Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Macintosh Nubus Interface Code |
| 3 | * |
| 4 | * Originally by Alan Cox |
| 5 | * |
| 6 | * Mostly rewritten by David Huggins-Daines, C. Scott Ananian, |
| 7 | * and others. |
| 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/types.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/nubus.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/delay.h> |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 17 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/setup.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/page.h> |
| 21 | #include <asm/hwtest.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/mac_via.h> |
| 23 | #include <asm/mac_oss.h> |
| 24 | |
| 25 | extern void via_nubus_init(void); |
| 26 | extern void oss_nubus_init(void); |
| 27 | |
| 28 | /* Constants */ |
| 29 | |
| 30 | /* This is, of course, the size in bytelanes, rather than the size in |
| 31 | actual bytes */ |
| 32 | #define FORMAT_BLOCK_SIZE 20 |
| 33 | #define ROM_DIR_OFFSET 0x24 |
| 34 | |
| 35 | #define NUBUS_TEST_PATTERN 0x5A932BC7 |
| 36 | |
| 37 | /* Define this if you like to live dangerously - it is known not to |
| 38 | work on pretty much every machine except the Quadra 630 and the LC |
| 39 | III. */ |
| 40 | #undef I_WANT_TO_PROBE_SLOT_ZERO |
| 41 | |
| 42 | /* This sometimes helps combat failure to boot */ |
| 43 | #undef TRY_TO_DODGE_WSOD |
| 44 | |
| 45 | /* Globals */ |
| 46 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 47 | struct nubus_dev *nubus_devices; |
| 48 | struct nubus_board *nubus_boards; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | /* Meaning of "bytelanes": |
| 51 | |
| 52 | The card ROM may appear on any or all bytes of each long word in |
| 53 | NuBus memory. The low 4 bits of the "map" value found in the |
| 54 | format block (at the top of the slot address space, as well as at |
| 55 | the top of the MacOS ROM) tells us which bytelanes, i.e. which byte |
| 56 | offsets within each longword, are valid. Thus: |
| 57 | |
| 58 | A map of 0x0f, as found in the MacOS ROM, means that all bytelanes |
| 59 | are valid. |
| 60 | |
| 61 | A map of 0xf0 means that no bytelanes are valid (We pray that we |
| 62 | will never encounter this, but stranger things have happened) |
| 63 | |
| 64 | A map of 0xe1 means that only the MSB of each long word is actually |
| 65 | part of the card ROM. (We hope to never encounter NuBus on a |
| 66 | little-endian machine. Again, stranger things have happened) |
| 67 | |
| 68 | A map of 0x78 means that only the LSB of each long word is valid. |
| 69 | |
| 70 | Etcetera, etcetera. Hopefully this clears up some confusion over |
| 71 | what the following code actually does. */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | static inline int not_useful(void *p, int map) |
| 74 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 75 | unsigned long pv = (unsigned long)p; |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | pv &= 3; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 78 | if (map & (1 << pv)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | return 0; |
| 80 | return 1; |
| 81 | } |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | static unsigned long nubus_get_rom(unsigned char **ptr, int len, int map) |
| 84 | { |
| 85 | /* This will hold the result */ |
| 86 | unsigned long v = 0; |
| 87 | unsigned char *p = *ptr; |
| 88 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 89 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | v <<= 8; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 91 | while (not_useful(p, map)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | p++; |
| 93 | v |= *p++; |
| 94 | len--; |
| 95 | } |
| 96 | *ptr = p; |
| 97 | return v; |
| 98 | } |
| 99 | |
| 100 | static void nubus_rewind(unsigned char **ptr, int len, int map) |
| 101 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 102 | unsigned char *p = *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | /* Sanity check */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 105 | if (len > 65536) |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 106 | pr_err("rewind of 0x%08x!\n", len); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 107 | while (len) { |
| 108 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | p--; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 110 | } while (not_useful(p, map)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | len--; |
| 112 | } |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 113 | *ptr = p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | static void nubus_advance(unsigned char **ptr, int len, int map) |
| 117 | { |
| 118 | unsigned char *p = *ptr; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 119 | |
| 120 | if (len > 65536) |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 121 | pr_err("advance of 0x%08x!\n", len); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 122 | while (len) { |
| 123 | while (not_useful(p, map)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | p++; |
Ilpo Järvinen | 2e0eb73 | 2008-10-15 22:01:31 -0700 | [diff] [blame] | 125 | p++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | len--; |
| 127 | } |
| 128 | *ptr = p; |
| 129 | } |
| 130 | |
| 131 | static void nubus_move(unsigned char **ptr, int len, int map) |
| 132 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 133 | if (len > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | nubus_advance(ptr, len, map); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 135 | else if (len < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | nubus_rewind(ptr, -len, map); |
| 137 | } |
| 138 | |
| 139 | /* Now, functions to read the sResource tree */ |
| 140 | |
| 141 | /* Each sResource entry consists of a 1-byte ID and a 3-byte data |
| 142 | field. If that data field contains an offset, then obviously we |
| 143 | have to expand it from a 24-bit signed number to a 32-bit signed |
| 144 | number. */ |
| 145 | |
| 146 | static inline long nubus_expand32(long foo) |
| 147 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 148 | if (foo & 0x00800000) /* 24bit negative */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | foo |= 0xFF000000; |
| 150 | return foo; |
| 151 | } |
| 152 | |
| 153 | static inline void *nubus_rom_addr(int slot) |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 154 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /* |
| 156 | * Returns the first byte after the card. We then walk |
| 157 | * backwards to get the lane register and the config |
| 158 | */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 159 | return (void *)(0xF1000000 + (slot << 24)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static unsigned char *nubus_dirptr(const struct nubus_dirent *nd) |
| 163 | { |
| 164 | unsigned char *p = nd->base; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | /* Essentially, just step over the bytelanes using whatever |
| 167 | offset we might have found */ |
| 168 | nubus_move(&p, nubus_expand32(nd->data), nd->mask); |
| 169 | /* And return the value */ |
| 170 | return p; |
| 171 | } |
| 172 | |
| 173 | /* These two are for pulling resource data blocks (i.e. stuff that's |
| 174 | pointed to with offsets) out of the card ROM. */ |
| 175 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 176 | void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | int len) |
| 178 | { |
| 179 | unsigned char *t = (unsigned char *)dest; |
| 180 | unsigned char *p = nubus_dirptr(dirent); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 181 | |
| 182 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | *t++ = nubus_get_rom(&p, 1, dirent->mask); |
| 184 | len--; |
| 185 | } |
| 186 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 187 | EXPORT_SYMBOL(nubus_get_rsrc_mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 189 | void nubus_get_rsrc_str(void *dest, const struct nubus_dirent *dirent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | int len) |
| 191 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 192 | unsigned char *t = (unsigned char *)dest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | unsigned char *p = nubus_dirptr(dirent); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 194 | |
| 195 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | *t = nubus_get_rom(&p, 1, dirent->mask); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 197 | if (!*t++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | break; |
| 199 | len--; |
| 200 | } |
| 201 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 202 | EXPORT_SYMBOL(nubus_get_rsrc_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 204 | int nubus_get_root_dir(const struct nubus_board *board, |
| 205 | struct nubus_dir *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | { |
| 207 | dir->ptr = dir->base = board->directory; |
| 208 | dir->done = 0; |
| 209 | dir->mask = board->lanes; |
| 210 | return 0; |
| 211 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 212 | EXPORT_SYMBOL(nubus_get_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | /* This is a slyly renamed version of the above */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 215 | int nubus_get_func_dir(const struct nubus_dev *dev, |
| 216 | struct nubus_dir *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
| 218 | dir->ptr = dir->base = dev->directory; |
| 219 | dir->done = 0; |
| 220 | dir->mask = dev->board->lanes; |
| 221 | return 0; |
| 222 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 223 | EXPORT_SYMBOL(nubus_get_func_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 225 | int nubus_get_board_dir(const struct nubus_board *board, |
| 226 | struct nubus_dir *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | struct nubus_dirent ent; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | dir->ptr = dir->base = board->directory; |
| 231 | dir->done = 0; |
| 232 | dir->mask = board->lanes; |
| 233 | |
| 234 | /* Now dereference it (the first directory is always the board |
| 235 | directory) */ |
| 236 | if (nubus_readdir(dir, &ent) == -1) |
| 237 | return -1; |
| 238 | if (nubus_get_subdir(&ent, dir) == -1) |
| 239 | return -1; |
| 240 | return 0; |
| 241 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 242 | EXPORT_SYMBOL(nubus_get_board_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | int nubus_get_subdir(const struct nubus_dirent *ent, |
| 245 | struct nubus_dir *dir) |
| 246 | { |
| 247 | dir->ptr = dir->base = nubus_dirptr(ent); |
| 248 | dir->done = 0; |
| 249 | dir->mask = ent->mask; |
| 250 | return 0; |
| 251 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 252 | EXPORT_SYMBOL(nubus_get_subdir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | int nubus_readdir(struct nubus_dir *nd, struct nubus_dirent *ent) |
| 255 | { |
| 256 | u32 resid; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (nd->done) |
| 259 | return -1; |
| 260 | |
| 261 | /* Do this first, otherwise nubus_rewind & co are off by 4 */ |
| 262 | ent->base = nd->ptr; |
| 263 | |
| 264 | /* This moves nd->ptr forward */ |
| 265 | resid = nubus_get_rom(&nd->ptr, 4, nd->mask); |
| 266 | |
| 267 | /* EOL marker, as per the Apple docs */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 268 | if ((resid & 0xff000000) == 0xff000000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | /* Mark it as done */ |
| 270 | nd->done = 1; |
| 271 | return -1; |
| 272 | } |
| 273 | |
| 274 | /* First byte is the resource ID */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 275 | ent->type = resid >> 24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* Low 3 bytes might contain data (or might not) */ |
| 277 | ent->data = resid & 0xffffff; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 278 | ent->mask = nd->mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | return 0; |
| 280 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 281 | EXPORT_SYMBOL(nubus_readdir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 283 | int nubus_rewinddir(struct nubus_dir *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
| 285 | dir->ptr = dir->base; |
David Huggins-Daines | e36b991 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 286 | dir->done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return 0; |
| 288 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 289 | EXPORT_SYMBOL(nubus_rewinddir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | /* Driver interface functions, more or less like in pci.c */ |
| 292 | |
| 293 | struct nubus_dev* |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 294 | nubus_find_device(unsigned short category, unsigned short type, |
| 295 | unsigned short dr_hw, unsigned short dr_sw, |
| 296 | const struct nubus_dev *from) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 298 | struct nubus_dev *itor = from ? from->next : nubus_devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | while (itor) { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 301 | if (itor->category == category && itor->type == type && |
| 302 | itor->dr_hw == dr_hw && itor->dr_sw == dr_sw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | return itor; |
| 304 | itor = itor->next; |
| 305 | } |
| 306 | return NULL; |
| 307 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 308 | EXPORT_SYMBOL(nubus_find_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | struct nubus_dev* |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 311 | nubus_find_type(unsigned short category, unsigned short type, |
| 312 | const struct nubus_dev *from) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 314 | struct nubus_dev *itor = from ? from->next : nubus_devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | while (itor) { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 317 | if (itor->category == category && itor->type == type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | return itor; |
| 319 | itor = itor->next; |
| 320 | } |
| 321 | return NULL; |
| 322 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 323 | EXPORT_SYMBOL(nubus_find_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | struct nubus_dev* |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 326 | nubus_find_slot(unsigned int slot, const struct nubus_dev *from) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 328 | struct nubus_dev *itor = from ? from->next : nubus_devices; |
| 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | while (itor) { |
| 331 | if (itor->board->slot == slot) |
| 332 | return itor; |
| 333 | itor = itor->next; |
| 334 | } |
| 335 | return NULL; |
| 336 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 337 | EXPORT_SYMBOL(nubus_find_slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | int |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 340 | nubus_find_rsrc(struct nubus_dir *dir, unsigned char rsrc_type, |
| 341 | struct nubus_dirent *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | { |
| 343 | while (nubus_readdir(dir, ent) != -1) { |
| 344 | if (ent->type == rsrc_type) |
| 345 | return 0; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 346 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | return -1; |
| 348 | } |
Adrian Bunk | 99ffab8 | 2008-02-04 22:30:23 -0800 | [diff] [blame] | 349 | EXPORT_SYMBOL(nubus_find_rsrc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
| 351 | /* Initialization functions - decide which slots contain stuff worth |
| 352 | looking at, and print out lots and lots of information from the |
| 353 | resource blocks. */ |
| 354 | |
| 355 | /* FIXME: A lot of this stuff will eventually be useful after |
Joe Perches | 081985a | 2008-02-03 17:23:36 +0200 | [diff] [blame] | 356 | initialization, for intelligently probing Ethernet and video chips, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | among other things. The rest of it should go in the /proc code. |
| 358 | For now, we just use it to give verbose boot logs. */ |
| 359 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 360 | static int __init nubus_show_display_resource(struct nubus_dev *dev, |
| 361 | const struct nubus_dirent *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
| 363 | switch (ent->type) { |
| 364 | case NUBUS_RESID_GAMMADIR: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 365 | pr_info(" gamma directory offset: 0x%06x\n", ent->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | break; |
| 367 | case 0x0080 ... 0x0085: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 368 | pr_info(" mode %02X info offset: 0x%06x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | ent->type, ent->data); |
| 370 | break; |
| 371 | default: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 372 | pr_info(" unknown resource %02X, data 0x%06x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | ent->type, ent->data); |
| 374 | } |
| 375 | return 0; |
| 376 | } |
| 377 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 378 | static int __init nubus_show_network_resource(struct nubus_dev *dev, |
| 379 | const struct nubus_dirent *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
| 381 | switch (ent->type) { |
| 382 | case NUBUS_RESID_MAC_ADDRESS: |
| 383 | { |
| 384 | char addr[6]; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | nubus_get_rsrc_mem(addr, ent, 6); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 387 | pr_info(" MAC address: %pM\n", addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | break; |
| 389 | } |
| 390 | default: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 391 | pr_info(" unknown resource %02X, data 0x%06x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | ent->type, ent->data); |
| 393 | } |
| 394 | return 0; |
| 395 | } |
| 396 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 397 | static int __init nubus_show_cpu_resource(struct nubus_dev *dev, |
| 398 | const struct nubus_dirent *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | { |
| 400 | switch (ent->type) { |
| 401 | case NUBUS_RESID_MEMINFO: |
| 402 | { |
| 403 | unsigned long meminfo[2]; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | nubus_get_rsrc_mem(&meminfo, ent, 8); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 406 | pr_info(" memory: [ 0x%08lx 0x%08lx ]\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | meminfo[0], meminfo[1]); |
| 408 | break; |
| 409 | } |
| 410 | case NUBUS_RESID_ROMINFO: |
| 411 | { |
| 412 | unsigned long rominfo[2]; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | nubus_get_rsrc_mem(&rominfo, ent, 8); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 415 | pr_info(" ROM: [ 0x%08lx 0x%08lx ]\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | rominfo[0], rominfo[1]); |
| 417 | break; |
| 418 | } |
| 419 | default: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 420 | pr_info(" unknown resource %02X, data 0x%06x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | ent->type, ent->data); |
| 422 | } |
| 423 | return 0; |
| 424 | } |
| 425 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 426 | static int __init nubus_show_private_resource(struct nubus_dev *dev, |
| 427 | const struct nubus_dirent *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
| 429 | switch (dev->category) { |
| 430 | case NUBUS_CAT_DISPLAY: |
| 431 | nubus_show_display_resource(dev, ent); |
| 432 | break; |
| 433 | case NUBUS_CAT_NETWORK: |
| 434 | nubus_show_network_resource(dev, ent); |
| 435 | break; |
| 436 | case NUBUS_CAT_CPU: |
| 437 | nubus_show_cpu_resource(dev, ent); |
| 438 | break; |
| 439 | default: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 440 | pr_info(" unknown resource %02X, data 0x%06x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | ent->type, ent->data); |
| 442 | } |
| 443 | return 0; |
| 444 | } |
| 445 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 446 | static struct nubus_dev * __init |
| 447 | nubus_get_functional_resource(struct nubus_board *board, int slot, |
| 448 | const struct nubus_dirent *parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 450 | struct nubus_dir dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | struct nubus_dirent ent; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 452 | struct nubus_dev *dev; |
| 453 | |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 454 | pr_info(" Function 0x%02x:\n", parent->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | nubus_get_subdir(parent, &dir); |
| 456 | |
| 457 | /* Apple seems to have botched the ROM on the IIx */ |
| 458 | if (slot == 0 && (unsigned long)dir.base % 2) |
| 459 | dir.base += 1; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 460 | |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 461 | pr_debug("%s: parent is 0x%p, dir is 0x%p\n", |
| 462 | __func__, parent->base, dir.base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
| 464 | /* Actually we should probably panic if this fails */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 465 | if ((dev = kzalloc(sizeof(*dev), GFP_ATOMIC)) == NULL) |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 466 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | dev->resid = parent->type; |
| 468 | dev->directory = dir.base; |
| 469 | dev->board = board; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 470 | |
| 471 | while (nubus_readdir(&dir, &ent) != -1) { |
| 472 | switch (ent.type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | case NUBUS_RESID_TYPE: |
| 474 | { |
| 475 | unsigned short nbtdata[4]; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | nubus_get_rsrc_mem(nbtdata, &ent, 8); |
| 478 | dev->category = nbtdata[0]; |
| 479 | dev->type = nbtdata[1]; |
| 480 | dev->dr_sw = nbtdata[2]; |
| 481 | dev->dr_hw = nbtdata[3]; |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 482 | pr_info(" type: [cat 0x%x type 0x%x sw 0x%x hw 0x%x]\n", |
| 483 | nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | break; |
| 485 | } |
| 486 | case NUBUS_RESID_NAME: |
| 487 | { |
| 488 | nubus_get_rsrc_str(dev->name, &ent, 64); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 489 | pr_info(" name: %s\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | break; |
| 491 | } |
| 492 | case NUBUS_RESID_DRVRDIR: |
| 493 | { |
| 494 | /* MacOS driver. If we were NetBSD we might |
| 495 | use this :-) */ |
| 496 | struct nubus_dir drvr_dir; |
| 497 | struct nubus_dirent drvr_ent; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | nubus_get_subdir(&ent, &drvr_dir); |
| 500 | nubus_readdir(&drvr_dir, &drvr_ent); |
| 501 | dev->driver = nubus_dirptr(&drvr_ent); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 502 | pr_info(" driver at: 0x%p\n", dev->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | break; |
| 504 | } |
| 505 | case NUBUS_RESID_MINOR_BASEOS: |
| 506 | /* We will need this in order to support |
| 507 | multiple framebuffers. It might be handy |
| 508 | for Ethernet as well */ |
| 509 | nubus_get_rsrc_mem(&dev->iobase, &ent, 4); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 510 | pr_info(" memory offset: 0x%08lx\n", dev->iobase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | break; |
| 512 | case NUBUS_RESID_MINOR_LENGTH: |
| 513 | /* Ditto */ |
| 514 | nubus_get_rsrc_mem(&dev->iosize, &ent, 4); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 515 | pr_info(" memory length: 0x%08lx\n", dev->iosize); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 516 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | case NUBUS_RESID_FLAGS: |
| 518 | dev->flags = ent.data; |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 519 | pr_info(" flags: 0x%06x\n", dev->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | break; |
| 521 | case NUBUS_RESID_HWDEVID: |
| 522 | dev->hwdevid = ent.data; |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 523 | pr_info(" hwdevid: 0x%06x\n", dev->hwdevid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | break; |
| 525 | default: |
| 526 | /* Local/Private resources have their own |
| 527 | function */ |
| 528 | nubus_show_private_resource(dev, &ent); |
| 529 | } |
| 530 | } |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | return dev; |
| 533 | } |
| 534 | |
| 535 | /* This is cool. */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 536 | static int __init nubus_get_vidnames(struct nubus_board *board, |
| 537 | const struct nubus_dirent *parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 539 | struct nubus_dir dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | struct nubus_dirent ent; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | /* FIXME: obviously we want to put this in a header file soon */ |
| 543 | struct vidmode { |
| 544 | u32 size; |
| 545 | /* Don't know what this is yet */ |
| 546 | u16 id; |
| 547 | /* Longest one I've seen so far is 26 characters */ |
| 548 | char name[32]; |
| 549 | }; |
| 550 | |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 551 | pr_info(" video modes supported:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | nubus_get_subdir(parent, &dir); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 553 | pr_debug("%s: parent is 0x%p, dir is 0x%p\n", |
| 554 | __func__, parent->base, dir.base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 556 | while (nubus_readdir(&dir, &ent) != -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | struct vidmode mode; |
| 558 | u32 size; |
| 559 | |
| 560 | /* First get the length */ |
| 561 | nubus_get_rsrc_mem(&size, &ent, 4); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | /* Now clobber the whole thing */ |
| 564 | if (size > sizeof(mode) - 1) |
| 565 | size = sizeof(mode) - 1; |
| 566 | memset(&mode, 0, sizeof(mode)); |
| 567 | nubus_get_rsrc_mem(&mode, &ent, size); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 568 | pr_info(" %02X: (%02X) %s\n", ent.type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | mode.id, mode.name); |
| 570 | } |
| 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | /* This is *really* cool. */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 575 | static int __init nubus_get_icon(struct nubus_board *board, |
| 576 | const struct nubus_dirent *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
| 578 | /* Should be 32x32 if my memory serves me correctly */ |
| 579 | unsigned char icon[128]; |
| 580 | int x, y; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | nubus_get_rsrc_mem(&icon, ent, 128); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 583 | pr_info(" icon:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
| 585 | /* We should actually plot these somewhere in the framebuffer |
| 586 | init. This is just to demonstrate that they do, in fact, |
| 587 | exist */ |
| 588 | for (y = 0; y < 32; y++) { |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 589 | pr_info(" "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | for (x = 0; x < 32; x++) { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 591 | if (icon[y * 4 + x / 8] & (0x80 >> (x % 8))) |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 592 | pr_cont("*"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | else |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 594 | pr_cont(" "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 596 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | return 0; |
| 599 | } |
| 600 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 601 | static int __init nubus_get_vendorinfo(struct nubus_board *board, |
| 602 | const struct nubus_dirent *parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 604 | struct nubus_dir dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | struct nubus_dirent ent; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 606 | static char *vendor_fields[6] = { "ID", "serial", "revision", |
| 607 | "part", "date", "unknown field" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 609 | pr_info(" vendor info:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | nubus_get_subdir(parent, &dir); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 611 | pr_debug("%s: parent is 0x%p, dir is 0x%p\n", |
| 612 | __func__, parent->base, dir.base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 614 | while (nubus_readdir(&dir, &ent) != -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | char name[64]; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | /* These are all strings, we think */ |
| 618 | nubus_get_rsrc_str(name, &ent, 64); |
| 619 | if (ent.type > 5) |
| 620 | ent.type = 5; |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 621 | pr_info(" %s: %s\n", vendor_fields[ent.type - 1], name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
| 623 | return 0; |
| 624 | } |
| 625 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 626 | static int __init nubus_get_board_resource(struct nubus_board *board, int slot, |
| 627 | const struct nubus_dirent *parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 629 | struct nubus_dir dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | struct nubus_dirent ent; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | nubus_get_subdir(parent, &dir); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 633 | pr_debug("%s: parent is 0x%p, dir is 0x%p\n", |
| 634 | __func__, parent->base, dir.base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 636 | while (nubus_readdir(&dir, &ent) != -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | switch (ent.type) { |
| 638 | case NUBUS_RESID_TYPE: |
| 639 | { |
| 640 | unsigned short nbtdata[4]; |
| 641 | /* This type is always the same, and is not |
| 642 | useful except insofar as it tells us that |
| 643 | we really are looking at a board resource. */ |
| 644 | nubus_get_rsrc_mem(nbtdata, &ent, 8); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 645 | pr_info(" type: [cat 0x%x type 0x%x sw 0x%x hw 0x%x]\n", |
| 646 | nbtdata[0], nbtdata[1], nbtdata[2], nbtdata[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | if (nbtdata[0] != 1 || nbtdata[1] != 0 || |
| 648 | nbtdata[2] != 0 || nbtdata[3] != 0) |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 649 | pr_err("this sResource is not a board resource!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | break; |
| 651 | } |
| 652 | case NUBUS_RESID_NAME: |
| 653 | nubus_get_rsrc_str(board->name, &ent, 64); |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 654 | pr_info(" name: %s\n", board->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | break; |
| 656 | case NUBUS_RESID_ICON: |
| 657 | nubus_get_icon(board, &ent); |
| 658 | break; |
| 659 | case NUBUS_RESID_BOARDID: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 660 | pr_info(" board id: 0x%x\n", ent.data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | break; |
| 662 | case NUBUS_RESID_PRIMARYINIT: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 663 | pr_info(" primary init offset: 0x%06x\n", ent.data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | break; |
| 665 | case NUBUS_RESID_VENDORINFO: |
| 666 | nubus_get_vendorinfo(board, &ent); |
| 667 | break; |
| 668 | case NUBUS_RESID_FLAGS: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 669 | pr_info(" flags: 0x%06x\n", ent.data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | break; |
| 671 | case NUBUS_RESID_HWDEVID: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 672 | pr_info(" hwdevid: 0x%06x\n", ent.data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | break; |
| 674 | case NUBUS_RESID_SECONDINIT: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 675 | pr_info(" secondary init offset: 0x%06x\n", ent.data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | break; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 677 | /* WTF isn't this in the functional resources? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | case NUBUS_RESID_VIDNAMES: |
| 679 | nubus_get_vidnames(board, &ent); |
| 680 | break; |
| 681 | /* Same goes for this */ |
| 682 | case NUBUS_RESID_VIDMODES: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 683 | pr_info(" video mode parameter directory offset: 0x%06x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | ent.data); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 685 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | default: |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 687 | pr_info(" unknown resource %02X, data 0x%06x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | ent.type, ent.data); |
| 689 | } |
| 690 | } |
| 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | /* Attempt to bypass the somewhat non-obvious arrangement of |
| 695 | sResources in the motherboard ROM */ |
| 696 | static void __init nubus_find_rom_dir(struct nubus_board* board) |
| 697 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 698 | unsigned char *rp; |
| 699 | unsigned char *romdir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | struct nubus_dir dir; |
| 701 | struct nubus_dirent ent; |
| 702 | |
| 703 | /* Check for the extra directory just under the format block */ |
| 704 | rp = board->fblock; |
| 705 | nubus_rewind(&rp, 4, board->lanes); |
| 706 | if (nubus_get_rom(&rp, 4, board->lanes) != NUBUS_TEST_PATTERN) { |
| 707 | /* OK, the ROM was telling the truth */ |
| 708 | board->directory = board->fblock; |
| 709 | nubus_move(&board->directory, |
| 710 | nubus_expand32(board->doffset), |
| 711 | board->lanes); |
| 712 | return; |
| 713 | } |
| 714 | |
| 715 | /* On "slot zero", you have to walk down a few more |
| 716 | directories to get to the equivalent of a real card's root |
| 717 | directory. We don't know what they were smoking when they |
| 718 | came up with this. */ |
| 719 | romdir = nubus_rom_addr(board->slot); |
| 720 | nubus_rewind(&romdir, ROM_DIR_OFFSET, board->lanes); |
| 721 | dir.base = dir.ptr = romdir; |
| 722 | dir.done = 0; |
| 723 | dir.mask = board->lanes; |
| 724 | |
| 725 | /* This one points to an "Unknown Macintosh" directory */ |
| 726 | if (nubus_readdir(&dir, &ent) == -1) |
| 727 | goto badrom; |
| 728 | |
Borislav Petkov | a8fe19e | 2014-06-04 16:11:46 -0700 | [diff] [blame] | 729 | if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | printk(KERN_INFO "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); |
| 731 | /* This one takes us to where we want to go. */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 732 | if (nubus_readdir(&dir, &ent) == -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | goto badrom; |
Borislav Petkov | a8fe19e | 2014-06-04 16:11:46 -0700 | [diff] [blame] | 734 | if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); |
| 736 | nubus_get_subdir(&ent, &dir); |
| 737 | |
| 738 | /* Resource ID 01, also an "Unknown Macintosh" */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 739 | if (nubus_readdir(&dir, &ent) == -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | goto badrom; |
Borislav Petkov | a8fe19e | 2014-06-04 16:11:46 -0700 | [diff] [blame] | 741 | if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); |
| 743 | |
| 744 | /* FIXME: the first one is *not* always the right one. We |
| 745 | suspect this has something to do with the ROM revision. |
| 746 | "The HORROR ROM" (LC-series) uses 0x7e, while "The HORROR |
| 747 | Continues" (Q630) uses 0x7b. The DAFB Macs evidently use |
| 748 | something else. Please run "Slots" on your Mac (see |
| 749 | include/linux/nubus.h for where to get this program) and |
| 750 | tell us where the 'SiDirPtr' for Slot 0 is. If you feel |
| 751 | brave, you should also use MacsBug to walk down the ROM |
| 752 | directories like this function does and try to find the |
| 753 | path to that address... */ |
| 754 | if (nubus_readdir(&dir, &ent) == -1) |
| 755 | goto badrom; |
Borislav Petkov | a8fe19e | 2014-06-04 16:11:46 -0700 | [diff] [blame] | 756 | if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 758 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | /* Bwahahahaha... */ |
| 760 | nubus_get_subdir(&ent, &dir); |
| 761 | board->directory = dir.base; |
| 762 | return; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | /* Even more evil laughter... */ |
| 765 | badrom: |
| 766 | board->directory = board->fblock; |
| 767 | nubus_move(&board->directory, nubus_expand32(board->doffset), board->lanes); |
| 768 | printk(KERN_ERR "nubus_get_rom_dir: ROM weirdness! Notify the developers...\n"); |
| 769 | } |
| 770 | |
| 771 | /* Add a board (might be many devices) to the list */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 772 | static struct nubus_board * __init nubus_add_board(int slot, int bytelanes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 774 | struct nubus_board *board; |
| 775 | struct nubus_board **boardp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | unsigned char *rp; |
| 777 | unsigned long dpat; |
| 778 | struct nubus_dir dir; |
| 779 | struct nubus_dirent ent; |
| 780 | |
| 781 | /* Move to the start of the format block */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 782 | rp = nubus_rom_addr(slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | nubus_rewind(&rp, FORMAT_BLOCK_SIZE, bytelanes); |
| 784 | |
| 785 | /* Actually we should probably panic if this fails */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 786 | if ((board = kzalloc(sizeof(*board), GFP_ATOMIC)) == NULL) |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 787 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | board->fblock = rp; |
| 789 | |
| 790 | /* Dump the format block for debugging purposes */ |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 791 | pr_debug("Slot %X, format block at 0x%p:\n", slot, rp); |
| 792 | pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); |
| 793 | pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); |
| 794 | pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); |
| 795 | pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); |
| 796 | pr_debug("%02lx\n", nubus_get_rom(&rp, 1, bytelanes)); |
| 797 | pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); |
| 798 | pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); |
| 799 | pr_debug("%08lx\n", nubus_get_rom(&rp, 4, bytelanes)); |
| 800 | rp = board->fblock; |
| 801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | board->slot = slot; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 803 | board->slot_addr = (unsigned long)nubus_slot_addr(slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | board->doffset = nubus_get_rom(&rp, 4, bytelanes); |
| 805 | /* rom_length is *supposed* to be the total length of the |
| 806 | * ROM. In practice it is the "amount of ROM used to compute |
| 807 | * the CRC." So some jokers decide to set it to zero and |
| 808 | * set the crc to zero so they don't have to do any math. |
| 809 | * See the Performa 460 ROM, for example. Those Apple "engineers". |
| 810 | */ |
| 811 | board->rom_length = nubus_get_rom(&rp, 4, bytelanes); |
| 812 | board->crc = nubus_get_rom(&rp, 4, bytelanes); |
| 813 | board->rev = nubus_get_rom(&rp, 1, bytelanes); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 814 | board->format = nubus_get_rom(&rp, 1, bytelanes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | board->lanes = bytelanes; |
| 816 | |
| 817 | /* Directory offset should be small and negative... */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 818 | if (!(board->doffset & 0x00FF0000)) |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 819 | pr_warn("Dodgy doffset!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | dpat = nubus_get_rom(&rp, 4, bytelanes); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 821 | if (dpat != NUBUS_TEST_PATTERN) |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 822 | pr_warn("Wrong test pattern %08lx!\n", dpat); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | /* |
| 825 | * I wonder how the CRC is meant to work - |
| 826 | * any takers ? |
| 827 | * CSA: According to MAC docs, not all cards pass the CRC anyway, |
| 828 | * since the initial Macintosh ROM releases skipped the check. |
| 829 | */ |
| 830 | |
| 831 | /* Attempt to work around slot zero weirdness */ |
| 832 | nubus_find_rom_dir(board); |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 833 | nubus_get_root_dir(board, &dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
| 835 | /* We're ready to rock */ |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 836 | pr_info("Slot %X:\n", slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
| 838 | /* Each slot should have one board resource and any number of |
| 839 | functional resources. So we'll fill in some fields in the |
| 840 | struct nubus_board from the board resource, then walk down |
| 841 | the list of functional resources, spinning out a nubus_dev |
| 842 | for each of them. */ |
| 843 | if (nubus_readdir(&dir, &ent) == -1) { |
| 844 | /* We can't have this! */ |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 845 | pr_err("Board resource not found!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | return NULL; |
| 847 | } else { |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 848 | pr_info(" Board resource:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | nubus_get_board_resource(board, slot, &ent); |
| 850 | } |
| 851 | |
| 852 | /* Aaaarrrrgghh! The LC III motherboard has *two* board |
| 853 | resources. I have no idea WTF to do about this. */ |
| 854 | |
| 855 | while (nubus_readdir(&dir, &ent) != -1) { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 856 | struct nubus_dev *dev; |
| 857 | struct nubus_dev **devp; |
| 858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | dev = nubus_get_functional_resource(board, slot, &ent); |
| 860 | if (dev == NULL) |
| 861 | continue; |
| 862 | |
| 863 | /* We zeroed this out above */ |
| 864 | if (board->first_dev == NULL) |
| 865 | board->first_dev = dev; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | /* Put it on the global NuBus device chain. Keep entries in order. */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 868 | for (devp = &nubus_devices; *devp != NULL; |
| 869 | devp = &((*devp)->next)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | /* spin */; |
| 871 | *devp = dev; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 872 | dev->next = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | /* Put it on the global NuBus board chain. Keep entries in order. */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 876 | for (boardp = &nubus_boards; *boardp != NULL; |
| 877 | boardp = &((*boardp)->next)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | /* spin */; |
| 879 | *boardp = board; |
| 880 | board->next = NULL; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | return board; |
| 883 | } |
| 884 | |
| 885 | void __init nubus_probe_slot(int slot) |
| 886 | { |
| 887 | unsigned char dp; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 888 | unsigned char *rp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | int i; |
| 890 | |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 891 | rp = nubus_rom_addr(slot); |
| 892 | for (i = 4; i; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | int card_present; |
| 894 | |
| 895 | rp--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | card_present = hwreg_present(rp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | if (!card_present) |
| 898 | continue; |
| 899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | dp = *rp; |
| 901 | if(dp == 0) |
| 902 | continue; |
| 903 | |
| 904 | /* The last byte of the format block consists of two |
| 905 | nybbles which are "mirror images" of each other. |
| 906 | These show us the valid bytelanes */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 907 | if ((((dp >> 4) ^ dp) & 0x0F) != 0x0F) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | continue; |
| 909 | /* Check that this value is actually *on* one of the |
| 910 | bytelanes it claims are valid! */ |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 911 | if ((dp & 0x0F) >= (1 << i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | continue; |
| 913 | |
| 914 | /* Looks promising. Let's put it on the list. */ |
| 915 | nubus_add_board(slot, dp); |
| 916 | |
| 917 | return; |
| 918 | } |
| 919 | } |
| 920 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | void __init nubus_scan_bus(void) |
| 922 | { |
| 923 | int slot; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | /* This might not work on your machine */ |
| 926 | #ifdef I_WANT_TO_PROBE_SLOT_ZERO |
| 927 | nubus_probe_slot(0); |
| 928 | #endif |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 929 | for (slot = 9; slot < 15; slot++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | nubus_probe_slot(slot); |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | static int __init nubus_init(void) |
| 935 | { |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 936 | if (!MACH_IS_MAC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | return 0; |
| 938 | |
| 939 | /* Initialize the NuBus interrupts */ |
| 940 | if (oss_present) { |
| 941 | oss_nubus_init(); |
| 942 | } else { |
| 943 | via_nubus_init(); |
| 944 | } |
| 945 | |
| 946 | #ifdef TRY_TO_DODGE_WSOD |
| 947 | /* Rogue Ethernet interrupts can kill the machine if we don't |
| 948 | do this. Obviously this is bogus. Hopefully the local VIA |
| 949 | gurus can fix the real cause of the problem. */ |
| 950 | mdelay(1000); |
| 951 | #endif |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | /* And probe */ |
David Huggins-Daines | 71ae40e | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 954 | pr_info("NuBus: Scanning NuBus slots.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | nubus_devices = NULL; |
Finn Thain | f42e555 | 2017-04-08 19:51:15 -0400 | [diff] [blame] | 956 | nubus_boards = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | nubus_scan_bus(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | nubus_proc_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | return 0; |
| 960 | } |
| 961 | |
| 962 | subsys_initcall(nubus_init); |