blob: e525669f1991a85066705a9d3ae62d7210c13976 [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 */
David Howells11db6562013-04-10 15:05:38 +010095#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -070096extern void nubus_proc_init(void);
David Howells11db6562013-04-10 15:05:38 +010097#else
98static inline void nubus_proc_init(void) {}
99#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100int get_nubus_list(char *buf);
101int nubus_proc_attach_device(struct nubus_dev *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/* If we need more precision we can add some more of these */
103struct nubus_dev* nubus_find_device(unsigned short category,
104 unsigned short type,
105 unsigned short dr_hw,
106 unsigned short dr_sw,
107 const struct nubus_dev* from);
108struct nubus_dev* nubus_find_type(unsigned short category,
109 unsigned short type,
110 const struct nubus_dev* from);
111/* Might have more than one device in a slot, you know... */
112struct nubus_dev* nubus_find_slot(unsigned int slot,
113 const struct nubus_dev* from);
114
115/* These are somewhat more NuBus-specific. They all return 0 for
116 success and -1 for failure, as you'd expect. */
117
118/* The root directory which contains the board and functional
119 directories */
120int nubus_get_root_dir(const struct nubus_board* board,
121 struct nubus_dir* dir);
122/* The board directory */
123int nubus_get_board_dir(const struct nubus_board* board,
124 struct nubus_dir* dir);
125/* The functional directory */
126int nubus_get_func_dir(const struct nubus_dev* dev,
127 struct nubus_dir* dir);
128
129/* These work on any directory gotten via the above */
130int nubus_readdir(struct nubus_dir* dir,
131 struct nubus_dirent* ent);
132int nubus_find_rsrc(struct nubus_dir* dir,
133 unsigned char rsrc_type,
134 struct nubus_dirent* ent);
135int nubus_rewinddir(struct nubus_dir* dir);
136
137/* Things to do with directory entries */
138int nubus_get_subdir(const struct nubus_dirent* ent,
139 struct nubus_dir* dir);
Finn Thain2f828fb2018-01-13 17:37:13 -0500140void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
141 unsigned int len);
142void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
143 unsigned int maxlen);
Finn Thain1ff27752018-01-13 17:37:13 -0500144
145/* Returns a pointer to the "standard" slot space. */
146static inline void *nubus_slot_addr(int slot)
147{
148 return (void *)(0xF0000000 | (slot << 24));
149}
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#endif /* LINUX_NUBUS_H */