nubus: Generalize block resource handling
[linux-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
1da177e4 13#include <asm/nubus.h>
607ca46e 14#include <uapi/linux/nubus.h>
1da177e4 15
1ff2775a
FT
16struct 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
1da177e4 30struct nubus_board {
4bccc4b6
FT
31 struct nubus_board *next;
32 struct nubus_dev *first_dev;
33
f8779588 34 /* Only 9-E actually exist, though 0-8 are also theoretically
1da177e4
LT
35 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 */
4bccc4b6 42 unsigned char *fblock;
1da177e4 43 /* Root directory (does *not* always equal fblock + doffset!) */
4bccc4b6
FT
44 unsigned char *directory;
45
1da177e4
LT
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;
6c8b89ea
FT
56
57 /* Directory entry in /proc/bus/nubus */
58 struct proc_dir_entry *procdir;
1da177e4
LT
59};
60
61struct nubus_dev {
62 /* Next link in device list */
4bccc4b6 63 struct nubus_dev *next;
1da177e4
LT
64
65 /* The functional resource ID of this device */
66 unsigned char resid;
67 /* These are mostly here for convenience; we could always read
68 them from the ROMs if we wanted to */
69 unsigned short category;
70 unsigned short type;
71 unsigned short dr_sw;
72 unsigned short dr_hw;
4bccc4b6 73
1da177e4 74 /* Functional directory */
4bccc4b6 75 unsigned char *directory;
1da177e4 76 /* Much of our info comes from here */
4bccc4b6 77 struct nubus_board *board;
1da177e4
LT
78};
79
80/* This is all NuBus devices (used to find devices later on) */
4bccc4b6 81extern struct nubus_dev *nubus_devices;
1da177e4 82/* This is all NuBus cards */
4bccc4b6 83extern struct nubus_board *nubus_boards;
1da177e4
LT
84
85/* Generic NuBus interface functions, modelled after the PCI interface */
11db656a 86#ifdef CONFIG_PROC_FS
1da177e4 87extern void nubus_proc_init(void);
11db656a
DH
88#else
89static inline void nubus_proc_init(void) {}
90#endif
9f97977d 91
1da177e4 92int nubus_proc_attach_device(struct nubus_dev *dev);
1da177e4 93/* If we need more precision we can add some more of these */
4bccc4b6 94struct nubus_dev *nubus_find_type(unsigned short category,
1da177e4 95 unsigned short type,
4bccc4b6 96 const struct nubus_dev *from);
1da177e4 97/* Might have more than one device in a slot, you know... */
4bccc4b6
FT
98struct nubus_dev *nubus_find_slot(unsigned int slot,
99 const struct nubus_dev *from);
1da177e4
LT
100
101/* These are somewhat more NuBus-specific. They all return 0 for
102 success and -1 for failure, as you'd expect. */
103
104/* The root directory which contains the board and functional
105 directories */
4bccc4b6
FT
106int nubus_get_root_dir(const struct nubus_board *board,
107 struct nubus_dir *dir);
1da177e4 108/* The board directory */
4bccc4b6
FT
109int nubus_get_board_dir(const struct nubus_board *board,
110 struct nubus_dir *dir);
1da177e4 111/* The functional directory */
4bccc4b6
FT
112int nubus_get_func_dir(const struct nubus_dev *dev,
113 struct nubus_dir *dir);
1da177e4
LT
114
115/* These work on any directory gotten via the above */
4bccc4b6
FT
116int nubus_readdir(struct nubus_dir *dir,
117 struct nubus_dirent *ent);
118int nubus_find_rsrc(struct nubus_dir *dir,
1da177e4 119 unsigned char rsrc_type,
4bccc4b6
FT
120 struct nubus_dirent *ent);
121int nubus_rewinddir(struct nubus_dir *dir);
1da177e4
LT
122
123/* Things to do with directory entries */
4bccc4b6
FT
124int nubus_get_subdir(const struct nubus_dirent *ent,
125 struct nubus_dir *dir);
2f828fb2
FT
126void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
127 unsigned int len);
128void nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent,
129 unsigned int maxlen);
1ff2775a
FT
130
131/* Returns a pointer to the "standard" slot space. */
132static inline void *nubus_slot_addr(int slot)
133{
134 return (void *)(0xF0000000 | (slot << 24));
135}
136
1da177e4 137#endif /* LINUX_NUBUS_H */