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