blob: 55b9a4569a69c5317194aa22763c96f8de239202 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
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 Thain1ff27752018-01-13 17:37:13 -05008*/
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#ifndef LINUX_NUBUS_H
11#define LINUX_NUBUS_H
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/nubus.h>
David Howells607ca462012-10-13 10:46:48 +010014#include <uapi/linux/nubus.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Finn Thain1ff27752018-01-13 17:37:13 -050016struct nubus_dir {
17 unsigned char *base;
18 unsigned char *ptr;
19 int done;
20 int mask;
21};
22
23struct nubus_dirent {
24 unsigned char *base;
25 unsigned char type;
26 __u32 data; /* Actually 24 bits used */
27 int mask;
28};
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030struct nubus_board {
31 struct nubus_board* next;
32 struct nubus_dev* first_dev;
33
Finn Thainf8779582007-05-01 22:32:53 +020034 /* Only 9-E actually exist, though 0-8 are also theoretically
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 possible, and 0 is a special case which represents the
36 motherboard and onboard peripherals (Ethernet, video) */
37 int slot;
38 /* For slot 0, this is bogus. */
39 char name[64];
40
41 /* Format block */
42 unsigned char* fblock;
43 /* Root directory (does *not* always equal fblock + doffset!) */
44 unsigned char* directory;
45
46 unsigned long slot_addr;
47 /* Offset to root directory (sometimes) */
48 unsigned long doffset;
49 /* Length over which to compute the crc */
50 unsigned long rom_length;
51 /* Completely useless most of the time */
52 unsigned long crc;
53 unsigned char rev;
54 unsigned char format;
55 unsigned char lanes;
56};
57
58struct nubus_dev {
59 /* Next link in device list */
60 struct nubus_dev* next;
61 /* Directory entry in /proc/bus/nubus */
62 struct proc_dir_entry* procdir;
63
64 /* The functional resource ID of this device */
65 unsigned char resid;
66 /* These are mostly here for convenience; we could always read
67 them from the ROMs if we wanted to */
68 unsigned short category;
69 unsigned short type;
70 unsigned short dr_sw;
71 unsigned short dr_hw;
72 /* This is the device's name rather than the board's.
73 Sometimes they are different. Usually the board name is
74 more correct. */
75 char name[64];
76 /* MacOS driver (I kid you not) */
77 unsigned char* driver;
78 /* Actually this is an offset */
79 unsigned long iobase;
80 unsigned long iosize;
81 unsigned char flags, hwdevid;
82
83 /* Functional directory */
84 unsigned char* directory;
85 /* Much of our info comes from here */
86 struct nubus_board* board;
87};
88
89/* This is all NuBus devices (used to find devices later on) */
90extern struct nubus_dev* nubus_devices;
91/* This is all NuBus cards */
92extern struct nubus_board* nubus_boards;
93
94/* Generic NuBus interface functions, modelled after the PCI interface */
95void nubus_scan_bus(void);
David Howells11db6562013-04-10 15:05:38 +010096#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -070097extern void nubus_proc_init(void);
David Howells11db6562013-04-10 15:05:38 +010098#else
99static inline void nubus_proc_init(void) {}
100#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101int get_nubus_list(char *buf);
102int nubus_proc_attach_device(struct nubus_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/* If we need more precision we can add some more of these */
104struct nubus_dev* nubus_find_device(unsigned short category,
105 unsigned short type,
106 unsigned short dr_hw,
107 unsigned short dr_sw,
108 const struct nubus_dev* from);
109struct nubus_dev* nubus_find_type(unsigned short category,
110 unsigned short type,
111 const struct nubus_dev* from);
112/* Might have more than one device in a slot, you know... */
113struct nubus_dev* nubus_find_slot(unsigned int slot,
114 const struct nubus_dev* from);
115
116/* These are somewhat more NuBus-specific. They all return 0 for
117 success and -1 for failure, as you'd expect. */
118
119/* The root directory which contains the board and functional
120 directories */
121int nubus_get_root_dir(const struct nubus_board* board,
122 struct nubus_dir* dir);
123/* The board directory */
124int nubus_get_board_dir(const struct nubus_board* board,
125 struct nubus_dir* dir);
126/* The functional directory */
127int nubus_get_func_dir(const struct nubus_dev* dev,
128 struct nubus_dir* dir);
129
130/* These work on any directory gotten via the above */
131int nubus_readdir(struct nubus_dir* dir,
132 struct nubus_dirent* ent);
133int nubus_find_rsrc(struct nubus_dir* dir,
134 unsigned char rsrc_type,
135 struct nubus_dirent* ent);
136int nubus_rewinddir(struct nubus_dir* dir);
137
138/* Things to do with directory entries */
139int nubus_get_subdir(const struct nubus_dirent* ent,
140 struct nubus_dir* dir);
Finn Thain2f828fb2018-01-13 17:37:13 -0500141void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
142 unsigned int len);
143void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
144 unsigned int maxlen);
Finn Thain1ff27752018-01-13 17:37:13 -0500145
146/* Returns a pointer to the "standard" slot space. */
147static inline void *nubus_slot_addr(int slot)
148{
149 return (void *)(0xF0000000 | (slot << 24));
150}
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#endif /* LINUX_NUBUS_H */