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