Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Finn Thain | 1ff2775 | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #ifndef LINUX_NUBUS_H |
| 11 | #define LINUX_NUBUS_H |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/nubus.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 14 | #include <uapi/linux/nubus.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Finn Thain | 2f7dd07 | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 16 | struct proc_dir_entry; |
| 17 | struct seq_file; |
| 18 | |
Finn Thain | 1ff2775 | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 19 | struct nubus_dir { |
| 20 | unsigned char *base; |
| 21 | unsigned char *ptr; |
| 22 | int done; |
| 23 | int mask; |
Finn Thain | 2f7dd07 | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 24 | struct proc_dir_entry *procdir; |
Finn Thain | 1ff2775 | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | struct nubus_dirent { |
| 28 | unsigned char *base; |
| 29 | unsigned char type; |
| 30 | __u32 data; /* Actually 24 bits used */ |
| 31 | int mask; |
| 32 | }; |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | struct nubus_board { |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 35 | struct nubus_board *next; |
Finn Thain | 189e19e | 2018-01-13 17:37:13 -0500 | [diff] [blame^] | 36 | struct nubus_rsrc *first_func_rsrc; |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 37 | |
Finn Thain | f877958 | 2007-05-01 22:32:53 +0200 | [diff] [blame] | 38 | /* Only 9-E actually exist, though 0-8 are also theoretically |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 46 | unsigned char *fblock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | /* Root directory (does *not* always equal fblock + doffset!) */ |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 48 | unsigned char *directory; |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Finn Thain | 6c8b89e | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 60 | |
| 61 | /* Directory entry in /proc/bus/nubus */ |
| 62 | struct proc_dir_entry *procdir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
Finn Thain | 189e19e | 2018-01-13 17:37:13 -0500 | [diff] [blame^] | 65 | struct nubus_rsrc { |
| 66 | /* Next link in list */ |
| 67 | struct nubus_rsrc *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Finn Thain | 189e19e | 2018-01-13 17:37:13 -0500 | [diff] [blame^] | 69 | /* The functional resource ID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | unsigned char resid; |
| 71 | /* These are mostly here for convenience; we could always read |
| 72 | them from the ROMs if we wanted to */ |
| 73 | unsigned short category; |
| 74 | unsigned short type; |
| 75 | unsigned short dr_sw; |
| 76 | unsigned short dr_hw; |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | /* Functional directory */ |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 79 | unsigned char *directory; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* Much of our info comes from here */ |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 81 | struct nubus_board *board; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
Finn Thain | 189e19e | 2018-01-13 17:37:13 -0500 | [diff] [blame^] | 84 | /* This is all NuBus functional resources (used to find devices later on) */ |
| 85 | extern struct nubus_rsrc *nubus_func_rsrcs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* This is all NuBus cards */ |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 87 | extern struct nubus_board *nubus_boards; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | /* Generic NuBus interface functions, modelled after the PCI interface */ |
David Howells | 11db656 | 2013-04-10 15:05:38 +0100 | [diff] [blame] | 90 | #ifdef CONFIG_PROC_FS |
Finn Thain | 2f7dd07 | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 91 | void nubus_proc_init(void); |
| 92 | struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board); |
| 93 | struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir, |
| 94 | const struct nubus_dirent *ent, |
| 95 | struct nubus_board *board); |
| 96 | void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir, |
| 97 | const struct nubus_dirent *ent, |
| 98 | unsigned int size); |
| 99 | void nubus_proc_add_rsrc(struct proc_dir_entry *procdir, |
| 100 | const struct nubus_dirent *ent); |
David Howells | 11db656 | 2013-04-10 15:05:38 +0100 | [diff] [blame] | 101 | #else |
| 102 | static inline void nubus_proc_init(void) {} |
Finn Thain | 2f7dd07 | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 103 | static inline |
| 104 | struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board) |
| 105 | { return NULL; } |
| 106 | static inline |
| 107 | struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir, |
| 108 | const struct nubus_dirent *ent, |
| 109 | struct nubus_board *board) |
| 110 | { return NULL; } |
| 111 | static inline void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir, |
| 112 | const struct nubus_dirent *ent, |
| 113 | unsigned int size) {} |
| 114 | static inline void nubus_proc_add_rsrc(struct proc_dir_entry *procdir, |
| 115 | const struct nubus_dirent *ent) {} |
David Howells | 11db656 | 2013-04-10 15:05:38 +0100 | [diff] [blame] | 116 | #endif |
Finn Thain | 9f97977 | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 117 | |
Finn Thain | 189e19e | 2018-01-13 17:37:13 -0500 | [diff] [blame^] | 118 | struct nubus_rsrc *nubus_find_type(unsigned short category, |
| 119 | unsigned short type, |
| 120 | const struct nubus_rsrc *from); |
| 121 | |
| 122 | struct nubus_rsrc *nubus_find_slot(unsigned int slot, |
| 123 | const struct nubus_rsrc *from); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | /* These are somewhat more NuBus-specific. They all return 0 for |
| 126 | success and -1 for failure, as you'd expect. */ |
| 127 | |
| 128 | /* The root directory which contains the board and functional |
| 129 | directories */ |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 130 | int nubus_get_root_dir(const struct nubus_board *board, |
| 131 | struct nubus_dir *dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* The board directory */ |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 133 | int nubus_get_board_dir(const struct nubus_board *board, |
| 134 | struct nubus_dir *dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | /* The functional directory */ |
Finn Thain | 189e19e | 2018-01-13 17:37:13 -0500 | [diff] [blame^] | 136 | int nubus_get_func_dir(const struct nubus_rsrc *fres, struct nubus_dir *dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | /* These work on any directory gotten via the above */ |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 139 | int nubus_readdir(struct nubus_dir *dir, |
| 140 | struct nubus_dirent *ent); |
| 141 | int nubus_find_rsrc(struct nubus_dir *dir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | unsigned char rsrc_type, |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 143 | struct nubus_dirent *ent); |
| 144 | int nubus_rewinddir(struct nubus_dir *dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | /* Things to do with directory entries */ |
Finn Thain | 4bccc4b | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 147 | int nubus_get_subdir(const struct nubus_dirent *ent, |
| 148 | struct nubus_dir *dir); |
Finn Thain | 2f828fb | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 149 | void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent, |
| 150 | unsigned int len); |
Finn Thain | 2f7dd07 | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 151 | unsigned int nubus_get_rsrc_str(char *dest, const struct nubus_dirent *dirent, |
| 152 | unsigned int len); |
| 153 | void nubus_seq_write_rsrc_mem(struct seq_file *m, |
| 154 | const struct nubus_dirent *dirent, |
| 155 | unsigned int len); |
| 156 | unsigned char *nubus_dirptr(const struct nubus_dirent *nd); |
Finn Thain | 1ff2775 | 2018-01-13 17:37:13 -0500 | [diff] [blame] | 157 | |
| 158 | /* Returns a pointer to the "standard" slot space. */ |
| 159 | static inline void *nubus_slot_addr(int slot) |
| 160 | { |
| 161 | return (void *)(0xF0000000 | (slot << 24)); |
| 162 | } |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | #endif /* LINUX_NUBUS_H */ |