1 | /* SPDX-License-Identifier: GPL-2.0 */ |
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. |
8 | */ |
9 | |
10 | #ifndef LINUX_NUBUS_H |
11 | #define LINUX_NUBUS_H |
12 | |
13 | #include <linux/device.h> |
14 | #include <asm/nubus.h> |
15 | #include <uapi/linux/nubus.h> |
16 | |
17 | struct proc_dir_entry; |
18 | struct seq_file; |
19 | |
20 | struct nubus_dir { |
21 | unsigned char *base; |
22 | unsigned char *ptr; |
23 | int done; |
24 | int mask; |
25 | struct proc_dir_entry *procdir; |
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 | |
35 | struct nubus_board { |
36 | struct device dev; |
37 | |
38 | /* Only 9-E actually exist, though 0-8 are also theoretically |
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 */ |
46 | unsigned char *fblock; |
47 | /* Root directory (does *not* always equal fblock + doffset!) */ |
48 | unsigned char *directory; |
49 | |
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; |
60 | |
61 | /* Directory entry in /proc/bus/nubus */ |
62 | struct proc_dir_entry *procdir; |
63 | }; |
64 | |
65 | struct nubus_rsrc { |
66 | struct list_head list; |
67 | |
68 | /* The functional resource ID */ |
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; |
76 | |
77 | /* Functional directory */ |
78 | unsigned char *directory; |
79 | /* Much of our info comes from here */ |
80 | struct nubus_board *board; |
81 | }; |
82 | |
83 | /* This is all NuBus functional resources (used to find devices later on) */ |
84 | extern struct list_head nubus_func_rsrcs; |
85 | |
86 | struct nubus_driver { |
87 | struct device_driver driver; |
88 | int (*probe)(struct nubus_board *board); |
89 | void (*remove)(struct nubus_board *board); |
90 | }; |
91 | |
92 | extern struct bus_type nubus_bus_type; |
93 | |
94 | /* Generic NuBus interface functions, modelled after the PCI interface */ |
95 | #ifdef CONFIG_PROC_FS |
96 | extern bool nubus_populate_procfs; |
97 | void nubus_proc_init(void); |
98 | struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board); |
99 | struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir, |
100 | const struct nubus_dirent *ent, |
101 | struct nubus_board *board); |
102 | void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir, |
103 | const struct nubus_dirent *ent, |
104 | unsigned int size); |
105 | void nubus_proc_add_rsrc(struct proc_dir_entry *procdir, |
106 | const struct nubus_dirent *ent); |
107 | #else |
108 | static inline void nubus_proc_init(void) {} |
109 | static inline |
110 | struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board) |
111 | { return NULL; } |
112 | static inline |
113 | struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir, |
114 | const struct nubus_dirent *ent, |
115 | struct nubus_board *board) |
116 | { return NULL; } |
117 | static inline void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir, |
118 | const struct nubus_dirent *ent, |
119 | unsigned int size) {} |
120 | static inline void nubus_proc_add_rsrc(struct proc_dir_entry *procdir, |
121 | const struct nubus_dirent *ent) {} |
122 | #endif |
123 | |
124 | struct nubus_rsrc *nubus_first_rsrc_or_null(void); |
125 | struct nubus_rsrc *nubus_next_rsrc_or_null(struct nubus_rsrc *from); |
126 | |
127 | #define for_each_func_rsrc(f) \ |
128 | for (f = nubus_first_rsrc_or_null(); f; f = nubus_next_rsrc_or_null(f)) |
129 | |
130 | #define for_each_board_func_rsrc(b, f) \ |
131 | for_each_func_rsrc(f) if (f->board != b) {} else |
132 | |
133 | /* These are somewhat more NuBus-specific. They all return 0 for |
134 | success and -1 for failure, as you'd expect. */ |
135 | |
136 | /* The root directory which contains the board and functional |
137 | directories */ |
138 | int nubus_get_root_dir(const struct nubus_board *board, |
139 | struct nubus_dir *dir); |
140 | /* The board directory */ |
141 | int nubus_get_board_dir(const struct nubus_board *board, |
142 | struct nubus_dir *dir); |
143 | /* The functional directory */ |
144 | int nubus_get_func_dir(const struct nubus_rsrc *fres, struct nubus_dir *dir); |
145 | |
146 | /* These work on any directory gotten via the above */ |
147 | int nubus_readdir(struct nubus_dir *dir, |
148 | struct nubus_dirent *ent); |
149 | int nubus_find_rsrc(struct nubus_dir *dir, |
150 | unsigned char rsrc_type, |
151 | struct nubus_dirent *ent); |
152 | int nubus_rewinddir(struct nubus_dir *dir); |
153 | |
154 | /* Things to do with directory entries */ |
155 | int nubus_get_subdir(const struct nubus_dirent *ent, |
156 | struct nubus_dir *dir); |
157 | void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent, |
158 | unsigned int len); |
159 | unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent, |
160 | unsigned int len); |
161 | void nubus_seq_write_rsrc_mem(struct seq_file *m, |
162 | const struct nubus_dirent *dirent, |
163 | unsigned int len); |
164 | unsigned char *nubus_dirptr(const struct nubus_dirent *nd); |
165 | |
166 | /* Declarations relating to driver model objects */ |
167 | int nubus_parent_device_register(void); |
168 | int nubus_device_register(struct nubus_board *board); |
169 | int nubus_driver_register(struct nubus_driver *ndrv); |
170 | void nubus_driver_unregister(struct nubus_driver *ndrv); |
171 | int nubus_proc_show(struct seq_file *m, void *data); |
172 | |
173 | static inline void nubus_set_drvdata(struct nubus_board *board, void *data) |
174 | { |
175 | dev_set_drvdata(dev: &board->dev, data); |
176 | } |
177 | |
178 | static inline void *nubus_get_drvdata(struct nubus_board *board) |
179 | { |
180 | return dev_get_drvdata(dev: &board->dev); |
181 | } |
182 | |
183 | /* Returns a pointer to the "standard" slot space. */ |
184 | static inline void *nubus_slot_addr(int slot) |
185 | { |
186 | return (void *)(0xF0000000 | (slot << 24)); |
187 | } |
188 | |
189 | #endif /* LINUX_NUBUS_H */ |
190 | |