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