nubus.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. nubus.h: various definitions and prototypes for NuBus drivers to use.
  4. Originally written by Alan Cox.
  5. Hacked to death by C. Scott Ananian and David Huggins-Daines.
  6. */
  7. #ifndef LINUX_NUBUS_H
  8. #define LINUX_NUBUS_H
  9. #include <linux/device.h>
  10. #include <asm/nubus.h>
  11. #include <uapi/linux/nubus.h>
  12. struct proc_dir_entry;
  13. struct seq_file;
  14. struct nubus_dir {
  15. unsigned char *base;
  16. unsigned char *ptr;
  17. int done;
  18. int mask;
  19. struct proc_dir_entry *procdir;
  20. };
  21. struct nubus_dirent {
  22. unsigned char *base;
  23. unsigned char type;
  24. __u32 data; /* Actually 24 bits used */
  25. int mask;
  26. };
  27. struct nubus_board {
  28. struct device dev;
  29. /* Only 9-E actually exist, though 0-8 are also theoretically
  30. possible, and 0 is a special case which represents the
  31. motherboard and onboard peripherals (Ethernet, video) */
  32. int slot;
  33. /* For slot 0, this is bogus. */
  34. char name[64];
  35. /* Format block */
  36. unsigned char *fblock;
  37. /* Root directory (does *not* always equal fblock + doffset!) */
  38. unsigned char *directory;
  39. unsigned long slot_addr;
  40. /* Offset to root directory (sometimes) */
  41. unsigned long doffset;
  42. /* Length over which to compute the crc */
  43. unsigned long rom_length;
  44. /* Completely useless most of the time */
  45. unsigned long crc;
  46. unsigned char rev;
  47. unsigned char format;
  48. unsigned char lanes;
  49. /* Directory entry in /proc/bus/nubus */
  50. struct proc_dir_entry *procdir;
  51. };
  52. struct nubus_rsrc {
  53. struct list_head list;
  54. /* The functional resource ID */
  55. unsigned char resid;
  56. /* These are mostly here for convenience; we could always read
  57. them from the ROMs if we wanted to */
  58. unsigned short category;
  59. unsigned short type;
  60. unsigned short dr_sw;
  61. unsigned short dr_hw;
  62. /* Functional directory */
  63. unsigned char *directory;
  64. /* Much of our info comes from here */
  65. struct nubus_board *board;
  66. };
  67. /* This is all NuBus functional resources (used to find devices later on) */
  68. extern struct list_head nubus_func_rsrcs;
  69. struct nubus_driver {
  70. struct device_driver driver;
  71. int (*probe)(struct nubus_board *board);
  72. int (*remove)(struct nubus_board *board);
  73. };
  74. extern struct bus_type nubus_bus_type;
  75. /* Generic NuBus interface functions, modelled after the PCI interface */
  76. #ifdef CONFIG_PROC_FS
  77. void nubus_proc_init(void);
  78. struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board);
  79. struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir,
  80. const struct nubus_dirent *ent,
  81. struct nubus_board *board);
  82. void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
  83. const struct nubus_dirent *ent,
  84. unsigned int size);
  85. void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
  86. const struct nubus_dirent *ent);
  87. #else
  88. static inline void nubus_proc_init(void) {}
  89. static inline
  90. struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board)
  91. { return NULL; }
  92. static inline
  93. struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir,
  94. const struct nubus_dirent *ent,
  95. struct nubus_board *board)
  96. { return NULL; }
  97. static inline void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
  98. const struct nubus_dirent *ent,
  99. unsigned int size) {}
  100. static inline void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
  101. const struct nubus_dirent *ent) {}
  102. #endif
  103. struct nubus_rsrc *nubus_first_rsrc_or_null(void);
  104. struct nubus_rsrc *nubus_next_rsrc_or_null(struct nubus_rsrc *from);
  105. #define for_each_func_rsrc(f) \
  106. for (f = nubus_first_rsrc_or_null(); f; f = nubus_next_rsrc_or_null(f))
  107. #define for_each_board_func_rsrc(b, f) \
  108. for_each_func_rsrc(f) if (f->board != b) {} else
  109. /* These are somewhat more NuBus-specific. They all return 0 for
  110. success and -1 for failure, as you'd expect. */
  111. /* The root directory which contains the board and functional
  112. directories */
  113. int nubus_get_root_dir(const struct nubus_board *board,
  114. struct nubus_dir *dir);
  115. /* The board directory */
  116. int nubus_get_board_dir(const struct nubus_board *board,
  117. struct nubus_dir *dir);
  118. /* The functional directory */
  119. int nubus_get_func_dir(const struct nubus_rsrc *fres, struct nubus_dir *dir);
  120. /* These work on any directory gotten via the above */
  121. int nubus_readdir(struct nubus_dir *dir,
  122. struct nubus_dirent *ent);
  123. int nubus_find_rsrc(struct nubus_dir *dir,
  124. unsigned char rsrc_type,
  125. struct nubus_dirent *ent);
  126. int nubus_rewinddir(struct nubus_dir *dir);
  127. /* Things to do with directory entries */
  128. int nubus_get_subdir(const struct nubus_dirent *ent,
  129. struct nubus_dir *dir);
  130. void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
  131. unsigned int len);
  132. unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
  133. unsigned int len);
  134. void nubus_seq_write_rsrc_mem(struct seq_file *m,
  135. const struct nubus_dirent *dirent,
  136. unsigned int len);
  137. unsigned char *nubus_dirptr(const struct nubus_dirent *nd);
  138. /* Declarations relating to driver model objects */
  139. int nubus_parent_device_register(void);
  140. int nubus_device_register(struct nubus_board *board);
  141. int nubus_driver_register(struct nubus_driver *ndrv);
  142. void nubus_driver_unregister(struct nubus_driver *ndrv);
  143. int nubus_proc_show(struct seq_file *m, void *data);
  144. static inline void nubus_set_drvdata(struct nubus_board *board, void *data)
  145. {
  146. dev_set_drvdata(&board->dev, data);
  147. }
  148. static inline void *nubus_get_drvdata(struct nubus_board *board)
  149. {
  150. return dev_get_drvdata(&board->dev);
  151. }
  152. /* Returns a pointer to the "standard" slot space. */
  153. static inline void *nubus_slot_addr(int slot)
  154. {
  155. return (void *)(0xF0000000 | (slot << 24));
  156. }
  157. #endif /* LINUX_NUBUS_H */