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