1 /* SPDX-License-Identifier: GPL-2.0 */
3 nubus.h: various definitions and prototypes for NuBus drivers to use.
5 Originally written by Alan Cox.
7 Hacked to death by C. Scott Ananian and David Huggins-Daines.
13 #include <linux/device.h>
14 #include <asm/nubus.h>
15 #include <uapi/linux/nubus.h>
17 struct proc_dir_entry
;
25 struct proc_dir_entry
*procdir
;
31 __u32 data
; /* Actually 24 bits used */
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) */
42 /* For slot 0, this is bogus. */
46 unsigned char *fblock
;
47 /* Root directory (does *not* always equal fblock + doffset!) */
48 unsigned char *directory
;
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 */
61 /* Directory entry in /proc/bus/nubus */
62 struct proc_dir_entry
*procdir
;
66 struct list_head list
;
68 /* The functional resource ID */
70 /* These are mostly here for convenience; we could always read
71 them from the ROMs if we wanted to */
72 unsigned short category
;
77 /* Functional directory */
78 unsigned char *directory
;
79 /* Much of our info comes from here */
80 struct nubus_board
*board
;
83 /* This is all NuBus functional resources (used to find devices later on) */
84 extern struct list_head nubus_func_rsrcs
;
87 struct device_driver driver
;
88 int (*probe
)(struct nubus_board
*board
);
89 void (*remove
)(struct nubus_board
*board
);
92 /* Generic NuBus interface functions, modelled after the PCI interface */
94 extern bool nubus_populate_procfs
;
95 void nubus_proc_init(void);
96 struct proc_dir_entry
*nubus_proc_add_board(struct nubus_board
*board
);
97 struct proc_dir_entry
*nubus_proc_add_rsrc_dir(struct proc_dir_entry
*procdir
,
98 const struct nubus_dirent
*ent
,
99 struct nubus_board
*board
);
100 void nubus_proc_add_rsrc_mem(struct proc_dir_entry
*procdir
,
101 const struct nubus_dirent
*ent
,
103 void nubus_proc_add_rsrc(struct proc_dir_entry
*procdir
,
104 const struct nubus_dirent
*ent
);
106 static inline void nubus_proc_init(void) {}
108 struct proc_dir_entry
*nubus_proc_add_board(struct nubus_board
*board
)
111 struct proc_dir_entry
*nubus_proc_add_rsrc_dir(struct proc_dir_entry
*procdir
,
112 const struct nubus_dirent
*ent
,
113 struct nubus_board
*board
)
115 static inline void nubus_proc_add_rsrc_mem(struct proc_dir_entry
*procdir
,
116 const struct nubus_dirent
*ent
,
117 unsigned int size
) {}
118 static inline void nubus_proc_add_rsrc(struct proc_dir_entry
*procdir
,
119 const struct nubus_dirent
*ent
) {}
122 struct nubus_rsrc
*nubus_first_rsrc_or_null(void);
123 struct nubus_rsrc
*nubus_next_rsrc_or_null(struct nubus_rsrc
*from
);
125 #define for_each_func_rsrc(f) \
126 for (f = nubus_first_rsrc_or_null(); f; f = nubus_next_rsrc_or_null(f))
128 #define for_each_board_func_rsrc(b, f) \
129 for_each_func_rsrc(f) if (f->board != b) {} else
131 /* These are somewhat more NuBus-specific. They all return 0 for
132 success and -1 for failure, as you'd expect. */
134 /* The root directory which contains the board and functional
136 int nubus_get_root_dir(const struct nubus_board
*board
,
137 struct nubus_dir
*dir
);
138 /* The board directory */
139 int nubus_get_board_dir(const struct nubus_board
*board
,
140 struct nubus_dir
*dir
);
141 /* The functional directory */
142 int nubus_get_func_dir(const struct nubus_rsrc
*fres
, struct nubus_dir
*dir
);
144 /* These work on any directory gotten via the above */
145 int nubus_readdir(struct nubus_dir
*dir
,
146 struct nubus_dirent
*ent
);
147 int nubus_find_rsrc(struct nubus_dir
*dir
,
148 unsigned char rsrc_type
,
149 struct nubus_dirent
*ent
);
150 int nubus_rewinddir(struct nubus_dir
*dir
);
152 /* Things to do with directory entries */
153 int nubus_get_subdir(const struct nubus_dirent
*ent
,
154 struct nubus_dir
*dir
);
155 void nubus_get_rsrc_mem(void *dest
, const struct nubus_dirent
*dirent
,
157 unsigned int nubus_get_rsrc_str(char *dest
, const struct nubus_dirent
*dirent
,
159 void nubus_seq_write_rsrc_mem(struct seq_file
*m
,
160 const struct nubus_dirent
*dirent
,
162 unsigned char *nubus_dirptr(const struct nubus_dirent
*nd
);
164 /* Declarations relating to driver model objects */
165 int nubus_parent_device_register(void);
166 int nubus_device_register(struct nubus_board
*board
);
167 int nubus_driver_register(struct nubus_driver
*ndrv
);
168 void nubus_driver_unregister(struct nubus_driver
*ndrv
);
169 int nubus_proc_show(struct seq_file
*m
, void *data
);
171 static inline void nubus_set_drvdata(struct nubus_board
*board
, void *data
)
173 dev_set_drvdata(&board
->dev
, data
);
176 static inline void *nubus_get_drvdata(struct nubus_board
*board
)
178 return dev_get_drvdata(&board
->dev
);
181 /* Returns a pointer to the "standard" slot space. */
182 static inline void *nubus_slot_addr(int slot
)
184 return (void *)(0xF0000000 | (slot
<< 24));
187 #endif /* LINUX_NUBUS_H */