dev.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2019, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef DEV_H
  7. #define DEV_H
  8. #include <cdefs.h>
  9. #include <lib/debugfs.h>
  10. #include <stddef.h>
  11. /* FIXME: need configurability */
  12. #define NR_CHANS 10
  13. #define NR_CONSS 1
  14. #define NR_BINDS 4
  15. #define NR_FILES 18
  16. #define NODEV 255
  17. #define CHDIR (1 << 15)
  18. #define SYNCDEV 0
  19. #define SYNCALL 1
  20. typedef struct dev dev_t;
  21. typedef struct chan chan_t;
  22. typedef struct dirtab dirtab_t;
  23. typedef int devgen_t(chan_t *, const dirtab_t *, int, int, dir_t *);
  24. typedef struct attr attr_t;
  25. enum {
  26. DEV_ROOT_QROOT,
  27. DEV_ROOT_QDEV,
  28. DEV_ROOT_QFIP,
  29. DEV_ROOT_QBLOBS,
  30. DEV_ROOT_QBLOBCTL,
  31. DEV_ROOT_QPSCI
  32. };
  33. /*******************************************************************************
  34. * This structure contains the necessary information to represent a directory
  35. * of the filesystem.
  36. ******************************************************************************/
  37. struct dirtab {
  38. char name[NAMELEN];
  39. qid_t qid;
  40. long length;
  41. unsigned char perm;
  42. void *data;
  43. };
  44. /*******************************************************************************
  45. * This structure defines the interface of device drivers.
  46. * Each driver must implement a subset of those functions.
  47. * It is possible to redirect to default implementations defined in dev.c.
  48. ******************************************************************************/
  49. /* FIXME: comments for the callbacks */
  50. struct dev {
  51. char id;
  52. int (*stat)(chan_t *c, const char *file, dir_t *dir);
  53. int (*walk)(chan_t *c, const char *name);
  54. int (*read)(chan_t *c, void *buf, int n);
  55. int (*write)(chan_t *c, void *buf, int n);
  56. int (*seek)(chan_t *c, long off, int whence);
  57. chan_t *(*clone)(chan_t *c, chan_t *nc);
  58. chan_t *(*attach)(int id, int dev);
  59. chan_t *(*mount)(chan_t *c, const char *spec);
  60. };
  61. /*******************************************************************************
  62. * This structure defines the channel structure.
  63. * A channel is a handle on an element of the filesystem.
  64. ******************************************************************************/
  65. struct chan {
  66. long offset;
  67. qid_t qid;
  68. unsigned char index; /* device index in devtab */
  69. unsigned char dev;
  70. unsigned char mode;
  71. };
  72. /*******************************************************************************
  73. * This structure defines an abstract argument passed to physical drivers from
  74. * the configuration file.
  75. ******************************************************************************/
  76. struct attr {
  77. char *key;
  78. char *value;
  79. };
  80. chan_t *path_to_channel(const char *path, int mode);
  81. chan_t *clone(chan_t *c, chan_t *nc);
  82. chan_t *attach(int id, int dev);
  83. void channel_close(chan_t *c);
  84. int buf_to_channel(chan_t *c, void *dst, void *src, int nbytes, long len);
  85. int dirread(chan_t *c, dir_t *dir, const dirtab_t *tab,
  86. int ntab, devgen_t *gen);
  87. void make_dir_entry(chan_t *c, dir_t *dir, const char *name, long length,
  88. qid_t qid, unsigned int mode);
  89. void devlink(void);
  90. chan_t *devattach(int id, int dev);
  91. int devseek(chan_t *c, long off, int whence);
  92. chan_t *devclone(chan_t *c, chan_t *nc);
  93. int devgen(chan_t *c, const dirtab_t *tab, int ntab, int n, dir_t *dir);
  94. int devwalk(chan_t *c, const char *name, const dirtab_t *tab, int ntab,
  95. devgen_t *gen);
  96. int devstat(chan_t *dirc, const char *file, dir_t *dir,
  97. const dirtab_t *tab, int ntab, devgen_t *gen);
  98. chan_t *deverrmount(chan_t *c, const char *spec);
  99. int deverrwrite(chan_t *c, void *buf, int n);
  100. int deverrseek(chan_t *c, long off, int whence);
  101. extern dev_t *const devtab[];
  102. void __dead2 devpanic(const char *cause);
  103. #endif /* DEV_H */