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