summaryrefslogtreecommitdiffstats
path: root/drivers/nubus
diff options
context:
space:
mode:
authorFinn Thain <fthain@telegraphics.com.au>2017-04-08 19:51:15 -0400
committerGeert Uytterhoeven <geert@linux-m68k.org>2017-04-20 03:54:24 -0400
commitf42e5550967a3e1e39dc0b1c4e2e7d903e764d5d (patch)
tree03b4ebea7f8723bc398d2c3b037078a64cc97b5c /drivers/nubus
parent71ae40e4cf3323b89ea910b82947d5e5e08c94bf (diff)
nubus: Clean up whitespace
Signed-off-by: Finn Thain <fthain@telegraphics.com.au> [geert: rebased] Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Diffstat (limited to 'drivers/nubus')
-rw-r--r--drivers/nubus/nubus.c310
1 files changed, 148 insertions, 162 deletions
diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 56de633f19b9..77a48a5164ff 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -44,8 +44,8 @@ extern void oss_nubus_init(void);
44 44
45/* Globals */ 45/* Globals */
46 46
47struct nubus_dev* nubus_devices; 47struct nubus_dev *nubus_devices;
48struct nubus_board* nubus_boards; 48struct nubus_board *nubus_boards;
49 49
50/* Meaning of "bytelanes": 50/* Meaning of "bytelanes":
51 51
@@ -69,26 +69,26 @@ struct nubus_board* nubus_boards;
69 69
70 Etcetera, etcetera. Hopefully this clears up some confusion over 70 Etcetera, etcetera. Hopefully this clears up some confusion over
71 what the following code actually does. */ 71 what the following code actually does. */
72 72
73static inline int not_useful(void *p, int map) 73static inline int not_useful(void *p, int map)
74{ 74{
75 unsigned long pv=(unsigned long)p; 75 unsigned long pv = (unsigned long)p;
76
76 pv &= 3; 77 pv &= 3;
77 if(map & (1<<pv)) 78 if (map & (1 << pv))
78 return 0; 79 return 0;
79 return 1; 80 return 1;
80} 81}
81 82
82static unsigned long nubus_get_rom(unsigned char **ptr, int len, int map) 83static unsigned long nubus_get_rom(unsigned char **ptr, int len, int map)
83{ 84{
84 /* This will hold the result */ 85 /* This will hold the result */
85 unsigned long v = 0; 86 unsigned long v = 0;
86 unsigned char *p = *ptr; 87 unsigned char *p = *ptr;
87 88
88 while(len) 89 while (len) {
89 {
90 v <<= 8; 90 v <<= 8;
91 while(not_useful(p,map)) 91 while (not_useful(p, map))
92 p++; 92 p++;
93 v |= *p++; 93 v |= *p++;
94 len--; 94 len--;
@@ -99,31 +99,28 @@ static unsigned long nubus_get_rom(unsigned char **ptr, int len, int map)
99 99
100static void nubus_rewind(unsigned char **ptr, int len, int map) 100static void nubus_rewind(unsigned char **ptr, int len, int map)
101{ 101{
102 unsigned char *p=*ptr; 102 unsigned char *p = *ptr;
103 103
104 /* Sanity check */ 104 /* Sanity check */
105 if(len > 65536) 105 if (len > 65536)
106 pr_err("rewind of 0x%08x!\n", len); 106 pr_err("rewind of 0x%08x!\n", len);
107 while(len) 107 while (len) {
108 { 108 do {
109 do
110 {
111 p--; 109 p--;
112 } 110 } while (not_useful(p, map));
113 while(not_useful(p, map));
114 len--; 111 len--;
115 } 112 }
116 *ptr=p; 113 *ptr = p;
117} 114}
118 115
119static void nubus_advance(unsigned char **ptr, int len, int map) 116static void nubus_advance(unsigned char **ptr, int len, int map)
120{ 117{
121 unsigned char *p = *ptr; 118 unsigned char *p = *ptr;
122 if(len>65536) 119
120 if (len > 65536)
123 pr_err("advance of 0x%08x!\n", len); 121 pr_err("advance of 0x%08x!\n", len);
124 while(len) 122 while (len) {
125 { 123 while (not_useful(p, map))
126 while(not_useful(p,map))
127 p++; 124 p++;
128 p++; 125 p++;
129 len--; 126 len--;
@@ -133,9 +130,9 @@ static void nubus_advance(unsigned char **ptr, int len, int map)
133 130
134static void nubus_move(unsigned char **ptr, int len, int map) 131static void nubus_move(unsigned char **ptr, int len, int map)
135{ 132{
136 if(len > 0) 133 if (len > 0)
137 nubus_advance(ptr, len, map); 134 nubus_advance(ptr, len, map);
138 else if(len < 0) 135 else if (len < 0)
139 nubus_rewind(ptr, -len, map); 136 nubus_rewind(ptr, -len, map);
140} 137}
141 138
@@ -148,23 +145,24 @@ static void nubus_move(unsigned char **ptr, int len, int map)
148 145
149static inline long nubus_expand32(long foo) 146static inline long nubus_expand32(long foo)
150{ 147{
151 if(foo & 0x00800000) /* 24bit negative */ 148 if (foo & 0x00800000) /* 24bit negative */
152 foo |= 0xFF000000; 149 foo |= 0xFF000000;
153 return foo; 150 return foo;
154} 151}
155 152
156static inline void *nubus_rom_addr(int slot) 153static inline void *nubus_rom_addr(int slot)
157{ 154{
158 /* 155 /*
159 * Returns the first byte after the card. We then walk 156 * Returns the first byte after the card. We then walk
160 * backwards to get the lane register and the config 157 * backwards to get the lane register and the config
161 */ 158 */
162 return (void *)(0xF1000000+(slot<<24)); 159 return (void *)(0xF1000000 + (slot << 24));
163} 160}
164 161
165static unsigned char *nubus_dirptr(const struct nubus_dirent *nd) 162static unsigned char *nubus_dirptr(const struct nubus_dirent *nd)
166{ 163{
167 unsigned char *p = nd->base; 164 unsigned char *p = nd->base;
165
168 /* Essentially, just step over the bytelanes using whatever 166 /* Essentially, just step over the bytelanes using whatever
169 offset we might have found */ 167 offset we might have found */
170 nubus_move(&p, nubus_expand32(nd->data), nd->mask); 168 nubus_move(&p, nubus_expand32(nd->data), nd->mask);
@@ -175,36 +173,36 @@ static unsigned char *nubus_dirptr(const struct nubus_dirent *nd)
175/* These two are for pulling resource data blocks (i.e. stuff that's 173/* These two are for pulling resource data blocks (i.e. stuff that's
176 pointed to with offsets) out of the card ROM. */ 174 pointed to with offsets) out of the card ROM. */
177 175
178void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent* dirent, 176void nubus_get_rsrc_mem(void *dest, const struct nubus_dirent *dirent,
179 int len) 177 int len)
180{ 178{
181 unsigned char *t = (unsigned char *)dest; 179 unsigned char *t = (unsigned char *)dest;
182 unsigned char *p = nubus_dirptr(dirent); 180 unsigned char *p = nubus_dirptr(dirent);
183 while(len) 181
184 { 182 while (len) {
185 *t++ = nubus_get_rom(&p, 1, dirent->mask); 183 *t++ = nubus_get_rom(&p, 1, dirent->mask);
186 len--; 184 len--;
187 } 185 }
188} 186}
189EXPORT_SYMBOL(nubus_get_rsrc_mem); 187EXPORT_SYMBOL(nubus_get_rsrc_mem);
190 188
191void nubus_get_rsrc_str(void *dest, const struct nubus_dirent* dirent, 189void nubus_get_rsrc_str(void *dest, const struct nubus_dirent *dirent,
192 int len) 190 int len)
193{ 191{
194 unsigned char *t=(unsigned char *)dest; 192 unsigned char *t = (unsigned char *)dest;
195 unsigned char *p = nubus_dirptr(dirent); 193 unsigned char *p = nubus_dirptr(dirent);
196 while(len) 194
197 { 195 while (len) {
198 *t = nubus_get_rom(&p, 1, dirent->mask); 196 *t = nubus_get_rom(&p, 1, dirent->mask);
199 if(!*t++) 197 if (!*t++)
200 break; 198 break;
201 len--; 199 len--;
202 } 200 }
203} 201}
204EXPORT_SYMBOL(nubus_get_rsrc_str); 202EXPORT_SYMBOL(nubus_get_rsrc_str);
205 203
206int nubus_get_root_dir(const struct nubus_board* board, 204int nubus_get_root_dir(const struct nubus_board *board,
207 struct nubus_dir* dir) 205 struct nubus_dir *dir)
208{ 206{
209 dir->ptr = dir->base = board->directory; 207 dir->ptr = dir->base = board->directory;
210 dir->done = 0; 208 dir->done = 0;
@@ -214,8 +212,8 @@ int nubus_get_root_dir(const struct nubus_board* board,
214EXPORT_SYMBOL(nubus_get_root_dir); 212EXPORT_SYMBOL(nubus_get_root_dir);
215 213
216/* This is a slyly renamed version of the above */ 214/* This is a slyly renamed version of the above */
217int nubus_get_func_dir(const struct nubus_dev* dev, 215int nubus_get_func_dir(const struct nubus_dev *dev,
218 struct nubus_dir* dir) 216 struct nubus_dir *dir)
219{ 217{
220 dir->ptr = dir->base = dev->directory; 218 dir->ptr = dir->base = dev->directory;
221 dir->done = 0; 219 dir->done = 0;
@@ -224,11 +222,11 @@ int nubus_get_func_dir(const struct nubus_dev* dev,
224} 222}
225EXPORT_SYMBOL(nubus_get_func_dir); 223EXPORT_SYMBOL(nubus_get_func_dir);
226 224
227int nubus_get_board_dir(const struct nubus_board* board, 225int nubus_get_board_dir(const struct nubus_board *board,
228 struct nubus_dir* dir) 226 struct nubus_dir *dir)
229{ 227{
230 struct nubus_dirent ent; 228 struct nubus_dirent ent;
231 229
232 dir->ptr = dir->base = board->directory; 230 dir->ptr = dir->base = board->directory;
233 dir->done = 0; 231 dir->done = 0;
234 dir->mask = board->lanes; 232 dir->mask = board->lanes;
@@ -256,6 +254,7 @@ EXPORT_SYMBOL(nubus_get_subdir);
256int nubus_readdir(struct nubus_dir *nd, struct nubus_dirent *ent) 254int nubus_readdir(struct nubus_dir *nd, struct nubus_dirent *ent)
257{ 255{
258 u32 resid; 256 u32 resid;
257
259 if (nd->done) 258 if (nd->done)
260 return -1; 259 return -1;
261 260
@@ -266,27 +265,25 @@ int nubus_readdir(struct nubus_dir *nd, struct nubus_dirent *ent)
266 resid = nubus_get_rom(&nd->ptr, 4, nd->mask); 265 resid = nubus_get_rom(&nd->ptr, 4, nd->mask);
267 266
268 /* EOL marker, as per the Apple docs */ 267 /* EOL marker, as per the Apple docs */
269 if((resid&0xff000000) == 0xff000000) 268 if ((resid & 0xff000000) == 0xff000000) {
270 {
271 /* Mark it as done */ 269 /* Mark it as done */
272 nd->done = 1; 270 nd->done = 1;
273 return -1; 271 return -1;
274 } 272 }
275 273
276 /* First byte is the resource ID */ 274 /* First byte is the resource ID */
277 ent->type = resid >> 24; 275 ent->type = resid >> 24;
278 /* Low 3 bytes might contain data (or might not) */ 276 /* Low 3 bytes might contain data (or might not) */
279 ent->data = resid & 0xffffff; 277 ent->data = resid & 0xffffff;
280 ent->mask = nd->mask; 278 ent->mask = nd->mask;
281 return 0; 279 return 0;
282} 280}
283EXPORT_SYMBOL(nubus_readdir); 281EXPORT_SYMBOL(nubus_readdir);
284 282
285int nubus_rewinddir(struct nubus_dir* dir) 283int nubus_rewinddir(struct nubus_dir *dir)
286{ 284{
287 dir->ptr = dir->base; 285 dir->ptr = dir->base;
288 dir->done = 0; 286 dir->done = 0;
289
290 return 0; 287 return 0;
291} 288}
292EXPORT_SYMBOL(nubus_rewinddir); 289EXPORT_SYMBOL(nubus_rewinddir);
@@ -294,20 +291,15 @@ EXPORT_SYMBOL(nubus_rewinddir);
294/* Driver interface functions, more or less like in pci.c */ 291/* Driver interface functions, more or less like in pci.c */
295 292
296struct nubus_dev* 293struct nubus_dev*
297nubus_find_device(unsigned short category, 294nubus_find_device(unsigned short category, unsigned short type,
298 unsigned short type, 295 unsigned short dr_hw, unsigned short dr_sw,
299 unsigned short dr_hw, 296 const struct nubus_dev *from)
300 unsigned short dr_sw,
301 const struct nubus_dev* from)
302{ 297{
303 struct nubus_dev* itor = 298 struct nubus_dev *itor = from ? from->next : nubus_devices;
304 from ? from->next : nubus_devices;
305 299
306 while (itor) { 300 while (itor) {
307 if (itor->category == category 301 if (itor->category == category && itor->type == type &&
308 && itor->type == type 302 itor->dr_hw == dr_hw && itor->dr_sw == dr_sw)
309 && itor->dr_hw == dr_hw
310 && itor->dr_sw == dr_sw)
311 return itor; 303 return itor;
312 itor = itor->next; 304 itor = itor->next;
313 } 305 }
@@ -316,16 +308,13 @@ nubus_find_device(unsigned short category,
316EXPORT_SYMBOL(nubus_find_device); 308EXPORT_SYMBOL(nubus_find_device);
317 309
318struct nubus_dev* 310struct nubus_dev*
319nubus_find_type(unsigned short category, 311nubus_find_type(unsigned short category, unsigned short type,
320 unsigned short type, 312 const struct nubus_dev *from)
321 const struct nubus_dev* from)
322{ 313{
323 struct nubus_dev* itor = 314 struct nubus_dev *itor = from ? from->next : nubus_devices;
324 from ? from->next : nubus_devices;
325 315
326 while (itor) { 316 while (itor) {
327 if (itor->category == category 317 if (itor->category == category && itor->type == type)
328 && itor->type == type)
329 return itor; 318 return itor;
330 itor = itor->next; 319 itor = itor->next;
331 } 320 }
@@ -334,12 +323,10 @@ nubus_find_type(unsigned short category,
334EXPORT_SYMBOL(nubus_find_type); 323EXPORT_SYMBOL(nubus_find_type);
335 324
336struct nubus_dev* 325struct nubus_dev*
337nubus_find_slot(unsigned int slot, 326nubus_find_slot(unsigned int slot, const struct nubus_dev *from)
338 const struct nubus_dev* from)
339{ 327{
340 struct nubus_dev* itor = 328 struct nubus_dev *itor = from ? from->next : nubus_devices;
341 from ? from->next : nubus_devices; 329
342
343 while (itor) { 330 while (itor) {
344 if (itor->board->slot == slot) 331 if (itor->board->slot == slot)
345 return itor; 332 return itor;
@@ -350,13 +337,13 @@ nubus_find_slot(unsigned int slot,
350EXPORT_SYMBOL(nubus_find_slot); 337EXPORT_SYMBOL(nubus_find_slot);
351 338
352int 339int
353nubus_find_rsrc(struct nubus_dir* dir, unsigned char rsrc_type, 340nubus_find_rsrc(struct nubus_dir *dir, unsigned char rsrc_type,
354 struct nubus_dirent* ent) 341 struct nubus_dirent *ent)
355{ 342{
356 while (nubus_readdir(dir, ent) != -1) { 343 while (nubus_readdir(dir, ent) != -1) {
357 if (ent->type == rsrc_type) 344 if (ent->type == rsrc_type)
358 return 0; 345 return 0;
359 } 346 }
360 return -1; 347 return -1;
361} 348}
362EXPORT_SYMBOL(nubus_find_rsrc); 349EXPORT_SYMBOL(nubus_find_rsrc);
@@ -370,8 +357,8 @@ EXPORT_SYMBOL(nubus_find_rsrc);
370 among other things. The rest of it should go in the /proc code. 357 among other things. The rest of it should go in the /proc code.
371 For now, we just use it to give verbose boot logs. */ 358 For now, we just use it to give verbose boot logs. */
372 359
373static int __init nubus_show_display_resource(struct nubus_dev* dev, 360static int __init nubus_show_display_resource(struct nubus_dev *dev,
374 const struct nubus_dirent* ent) 361 const struct nubus_dirent *ent)
375{ 362{
376 switch (ent->type) { 363 switch (ent->type) {
377 case NUBUS_RESID_GAMMADIR: 364 case NUBUS_RESID_GAMMADIR:
@@ -388,14 +375,14 @@ static int __init nubus_show_display_resource(struct nubus_dev* dev,
388 return 0; 375 return 0;
389} 376}
390 377
391static int __init nubus_show_network_resource(struct nubus_dev* dev, 378static int __init nubus_show_network_resource(struct nubus_dev *dev,
392 const struct nubus_dirent* ent) 379 const struct nubus_dirent *ent)
393{ 380{
394 switch (ent->type) { 381 switch (ent->type) {
395 case NUBUS_RESID_MAC_ADDRESS: 382 case NUBUS_RESID_MAC_ADDRESS:
396 { 383 {
397 char addr[6]; 384 char addr[6];
398 385
399 nubus_get_rsrc_mem(addr, ent, 6); 386 nubus_get_rsrc_mem(addr, ent, 6);
400 pr_info(" MAC address: %pM\n", addr); 387 pr_info(" MAC address: %pM\n", addr);
401 break; 388 break;
@@ -407,13 +394,14 @@ static int __init nubus_show_network_resource(struct nubus_dev* dev,
407 return 0; 394 return 0;
408} 395}
409 396
410static int __init nubus_show_cpu_resource(struct nubus_dev* dev, 397static int __init nubus_show_cpu_resource(struct nubus_dev *dev,
411 const struct nubus_dirent* ent) 398 const struct nubus_dirent *ent)
412{ 399{
413 switch (ent->type) { 400 switch (ent->type) {
414 case NUBUS_RESID_MEMINFO: 401 case NUBUS_RESID_MEMINFO:
415 { 402 {
416 unsigned long meminfo[2]; 403 unsigned long meminfo[2];
404
417 nubus_get_rsrc_mem(&meminfo, ent, 8); 405 nubus_get_rsrc_mem(&meminfo, ent, 8);
418 pr_info(" memory: [ 0x%08lx 0x%08lx ]\n", 406 pr_info(" memory: [ 0x%08lx 0x%08lx ]\n",
419 meminfo[0], meminfo[1]); 407 meminfo[0], meminfo[1]);
@@ -422,6 +410,7 @@ static int __init nubus_show_cpu_resource(struct nubus_dev* dev,
422 case NUBUS_RESID_ROMINFO: 410 case NUBUS_RESID_ROMINFO:
423 { 411 {
424 unsigned long rominfo[2]; 412 unsigned long rominfo[2];
413
425 nubus_get_rsrc_mem(&rominfo, ent, 8); 414 nubus_get_rsrc_mem(&rominfo, ent, 8);
426 pr_info(" ROM: [ 0x%08lx 0x%08lx ]\n", 415 pr_info(" ROM: [ 0x%08lx 0x%08lx ]\n",
427 rominfo[0], rominfo[1]); 416 rominfo[0], rominfo[1]);
@@ -434,8 +423,8 @@ static int __init nubus_show_cpu_resource(struct nubus_dev* dev,
434 return 0; 423 return 0;
435} 424}
436 425
437static int __init nubus_show_private_resource(struct nubus_dev* dev, 426static int __init nubus_show_private_resource(struct nubus_dev *dev,
438 const struct nubus_dirent* ent) 427 const struct nubus_dirent *ent)
439{ 428{
440 switch (dev->category) { 429 switch (dev->category) {
441 case NUBUS_CAT_DISPLAY: 430 case NUBUS_CAT_DISPLAY:
@@ -454,39 +443,37 @@ static int __init nubus_show_private_resource(struct nubus_dev* dev,
454 return 0; 443 return 0;
455} 444}
456 445
457static struct nubus_dev* __init 446static struct nubus_dev * __init
458 nubus_get_functional_resource(struct nubus_board* board, 447nubus_get_functional_resource(struct nubus_board *board, int slot,
459 int slot, 448 const struct nubus_dirent *parent)
460 const struct nubus_dirent* parent)
461{ 449{
462 struct nubus_dir dir; 450 struct nubus_dir dir;
463 struct nubus_dirent ent; 451 struct nubus_dirent ent;
464 struct nubus_dev* dev; 452 struct nubus_dev *dev;
465 453
466 pr_info(" Function 0x%02x:\n", parent->type); 454 pr_info(" Function 0x%02x:\n", parent->type);
467 nubus_get_subdir(parent, &dir); 455 nubus_get_subdir(parent, &dir);
468 456
469 /* Apple seems to have botched the ROM on the IIx */ 457 /* Apple seems to have botched the ROM on the IIx */
470 if (slot == 0 && (unsigned long)dir.base % 2) 458 if (slot == 0 && (unsigned long)dir.base % 2)
471 dir.base += 1; 459 dir.base += 1;
472 460
473 pr_debug("%s: parent is 0x%p, dir is 0x%p\n", 461 pr_debug("%s: parent is 0x%p, dir is 0x%p\n",
474 __func__, parent->base, dir.base); 462 __func__, parent->base, dir.base);
475 463
476 /* Actually we should probably panic if this fails */ 464 /* Actually we should probably panic if this fails */
477 if ((dev = kzalloc(sizeof(*dev), GFP_ATOMIC)) == NULL) 465 if ((dev = kzalloc(sizeof(*dev), GFP_ATOMIC)) == NULL)
478 return NULL; 466 return NULL;
479 dev->resid = parent->type; 467 dev->resid = parent->type;
480 dev->directory = dir.base; 468 dev->directory = dir.base;
481 dev->board = board; 469 dev->board = board;
482 470
483 while (nubus_readdir(&dir, &ent) != -1) 471 while (nubus_readdir(&dir, &ent) != -1) {
484 { 472 switch (ent.type) {
485 switch(ent.type)
486 {
487 case NUBUS_RESID_TYPE: 473 case NUBUS_RESID_TYPE:
488 { 474 {
489 unsigned short nbtdata[4]; 475 unsigned short nbtdata[4];
476
490 nubus_get_rsrc_mem(nbtdata, &ent, 8); 477 nubus_get_rsrc_mem(nbtdata, &ent, 8);
491 dev->category = nbtdata[0]; 478 dev->category = nbtdata[0];
492 dev->type = nbtdata[1]; 479 dev->type = nbtdata[1];
@@ -508,6 +495,7 @@ static struct nubus_dev* __init
508 use this :-) */ 495 use this :-) */
509 struct nubus_dir drvr_dir; 496 struct nubus_dir drvr_dir;
510 struct nubus_dirent drvr_ent; 497 struct nubus_dirent drvr_ent;
498
511 nubus_get_subdir(&ent, &drvr_dir); 499 nubus_get_subdir(&ent, &drvr_dir);
512 nubus_readdir(&drvr_dir, &drvr_ent); 500 nubus_readdir(&drvr_dir, &drvr_ent);
513 dev->driver = nubus_dirptr(&drvr_ent); 501 dev->driver = nubus_dirptr(&drvr_ent);
@@ -525,7 +513,7 @@ static struct nubus_dev* __init
525 /* Ditto */ 513 /* Ditto */
526 nubus_get_rsrc_mem(&dev->iosize, &ent, 4); 514 nubus_get_rsrc_mem(&dev->iosize, &ent, 4);
527 pr_info(" memory length: 0x%08lx\n", dev->iosize); 515 pr_info(" memory length: 0x%08lx\n", dev->iosize);
528 break; 516 break;
529 case NUBUS_RESID_FLAGS: 517 case NUBUS_RESID_FLAGS:
530 dev->flags = ent.data; 518 dev->flags = ent.data;
531 pr_info(" flags: 0x%06x\n", dev->flags); 519 pr_info(" flags: 0x%06x\n", dev->flags);
@@ -540,16 +528,17 @@ static struct nubus_dev* __init
540 nubus_show_private_resource(dev, &ent); 528 nubus_show_private_resource(dev, &ent);
541 } 529 }
542 } 530 }
543 531
544 return dev; 532 return dev;
545} 533}
546 534
547/* This is cool. */ 535/* This is cool. */
548static int __init nubus_get_vidnames(struct nubus_board* board, 536static int __init nubus_get_vidnames(struct nubus_board *board,
549 const struct nubus_dirent* parent) 537 const struct nubus_dirent *parent)
550{ 538{
551 struct nubus_dir dir; 539 struct nubus_dir dir;
552 struct nubus_dirent ent; 540 struct nubus_dirent ent;
541
553 /* FIXME: obviously we want to put this in a header file soon */ 542 /* FIXME: obviously we want to put this in a header file soon */
554 struct vidmode { 543 struct vidmode {
555 u32 size; 544 u32 size;
@@ -564,14 +553,13 @@ static int __init nubus_get_vidnames(struct nubus_board* board,
564 pr_debug("%s: parent is 0x%p, dir is 0x%p\n", 553 pr_debug("%s: parent is 0x%p, dir is 0x%p\n",
565 __func__, parent->base, dir.base); 554 __func__, parent->base, dir.base);
566 555
567 while(nubus_readdir(&dir, &ent) != -1) 556 while (nubus_readdir(&dir, &ent) != -1) {
568 {
569 struct vidmode mode; 557 struct vidmode mode;
570 u32 size; 558 u32 size;
571 559
572 /* First get the length */ 560 /* First get the length */
573 nubus_get_rsrc_mem(&size, &ent, 4); 561 nubus_get_rsrc_mem(&size, &ent, 4);
574 562
575 /* Now clobber the whole thing */ 563 /* Now clobber the whole thing */
576 if (size > sizeof(mode) - 1) 564 if (size > sizeof(mode) - 1)
577 size = sizeof(mode) - 1; 565 size = sizeof(mode) - 1;
@@ -584,13 +572,13 @@ static int __init nubus_get_vidnames(struct nubus_board* board,
584} 572}
585 573
586/* This is *really* cool. */ 574/* This is *really* cool. */
587static int __init nubus_get_icon(struct nubus_board* board, 575static int __init nubus_get_icon(struct nubus_board *board,
588 const struct nubus_dirent* ent) 576 const struct nubus_dirent *ent)
589{ 577{
590 /* Should be 32x32 if my memory serves me correctly */ 578 /* Should be 32x32 if my memory serves me correctly */
591 unsigned char icon[128]; 579 unsigned char icon[128];
592 int x, y; 580 int x, y;
593 581
594 nubus_get_rsrc_mem(&icon, ent, 128); 582 nubus_get_rsrc_mem(&icon, ent, 128);
595 pr_info(" icon:\n"); 583 pr_info(" icon:\n");
596 584
@@ -600,8 +588,7 @@ static int __init nubus_get_icon(struct nubus_board* board,
600 for (y = 0; y < 32; y++) { 588 for (y = 0; y < 32; y++) {
601 pr_info(" "); 589 pr_info(" ");
602 for (x = 0; x < 32; x++) { 590 for (x = 0; x < 32; x++) {
603 if (icon[y*4 + x/8] 591 if (icon[y * 4 + x / 8] & (0x80 >> (x % 8)))
604 & (0x80 >> (x%8)))
605 pr_cont("*"); 592 pr_cont("*");
606 else 593 else
607 pr_cont(" "); 594 pr_cont(" ");
@@ -611,23 +598,22 @@ static int __init nubus_get_icon(struct nubus_board* board,
611 return 0; 598 return 0;
612} 599}
613 600
614static int __init nubus_get_vendorinfo(struct nubus_board* board, 601static int __init nubus_get_vendorinfo(struct nubus_board *board,
615 const struct nubus_dirent* parent) 602 const struct nubus_dirent *parent)
616{ 603{
617 struct nubus_dir dir; 604 struct nubus_dir dir;
618 struct nubus_dirent ent; 605 struct nubus_dirent ent;
619 static char* vendor_fields[6] = {"ID", "serial", "revision", 606 static char *vendor_fields[6] = { "ID", "serial", "revision",
620 "part", "date", "unknown field"}; 607 "part", "date", "unknown field" };
621 608
622 pr_info(" vendor info:\n"); 609 pr_info(" vendor info:\n");
623 nubus_get_subdir(parent, &dir); 610 nubus_get_subdir(parent, &dir);
624 pr_debug("%s: parent is 0x%p, dir is 0x%p\n", 611 pr_debug("%s: parent is 0x%p, dir is 0x%p\n",
625 __func__, parent->base, dir.base); 612 __func__, parent->base, dir.base);
626 613
627 while(nubus_readdir(&dir, &ent) != -1) 614 while (nubus_readdir(&dir, &ent) != -1) {
628 {
629 char name[64]; 615 char name[64];
630 616
631 /* These are all strings, we think */ 617 /* These are all strings, we think */
632 nubus_get_rsrc_str(name, &ent, 64); 618 nubus_get_rsrc_str(name, &ent, 64);
633 if (ent.type > 5) 619 if (ent.type > 5)
@@ -637,18 +623,17 @@ static int __init nubus_get_vendorinfo(struct nubus_board* board,
637 return 0; 623 return 0;
638} 624}
639 625
640static int __init nubus_get_board_resource(struct nubus_board* board, int slot, 626static int __init nubus_get_board_resource(struct nubus_board *board, int slot,
641 const struct nubus_dirent* parent) 627 const struct nubus_dirent *parent)
642{ 628{
643 struct nubus_dir dir; 629 struct nubus_dir dir;
644 struct nubus_dirent ent; 630 struct nubus_dirent ent;
645 631
646 nubus_get_subdir(parent, &dir); 632 nubus_get_subdir(parent, &dir);
647 pr_debug("%s: parent is 0x%p, dir is 0x%p\n", 633 pr_debug("%s: parent is 0x%p, dir is 0x%p\n",
648 __func__, parent->base, dir.base); 634 __func__, parent->base, dir.base);
649 635
650 while(nubus_readdir(&dir, &ent) != -1) 636 while (nubus_readdir(&dir, &ent) != -1) {
651 {
652 switch (ent.type) { 637 switch (ent.type) {
653 case NUBUS_RESID_TYPE: 638 case NUBUS_RESID_TYPE:
654 { 639 {
@@ -689,7 +674,7 @@ static int __init nubus_get_board_resource(struct nubus_board* board, int slot,
689 case NUBUS_RESID_SECONDINIT: 674 case NUBUS_RESID_SECONDINIT:
690 pr_info(" secondary init offset: 0x%06x\n", ent.data); 675 pr_info(" secondary init offset: 0x%06x\n", ent.data);
691 break; 676 break;
692 /* WTF isn't this in the functional resources? */ 677 /* WTF isn't this in the functional resources? */
693 case NUBUS_RESID_VIDNAMES: 678 case NUBUS_RESID_VIDNAMES:
694 nubus_get_vidnames(board, &ent); 679 nubus_get_vidnames(board, &ent);
695 break; 680 break;
@@ -697,7 +682,7 @@ static int __init nubus_get_board_resource(struct nubus_board* board, int slot,
697 case NUBUS_RESID_VIDMODES: 682 case NUBUS_RESID_VIDMODES:
698 pr_info(" video mode parameter directory offset: 0x%06x\n", 683 pr_info(" video mode parameter directory offset: 0x%06x\n",
699 ent.data); 684 ent.data);
700 break; 685 break;
701 default: 686 default:
702 pr_info(" unknown resource %02X, data 0x%06x\n", 687 pr_info(" unknown resource %02X, data 0x%06x\n",
703 ent.type, ent.data); 688 ent.type, ent.data);
@@ -710,8 +695,8 @@ static int __init nubus_get_board_resource(struct nubus_board* board, int slot,
710 sResources in the motherboard ROM */ 695 sResources in the motherboard ROM */
711static void __init nubus_find_rom_dir(struct nubus_board* board) 696static void __init nubus_find_rom_dir(struct nubus_board* board)
712{ 697{
713 unsigned char* rp; 698 unsigned char *rp;
714 unsigned char* romdir; 699 unsigned char *romdir;
715 struct nubus_dir dir; 700 struct nubus_dir dir;
716 struct nubus_dirent ent; 701 struct nubus_dirent ent;
717 702
@@ -744,14 +729,14 @@ static void __init nubus_find_rom_dir(struct nubus_board* board)
744 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 729 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
745 printk(KERN_INFO "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); 730 printk(KERN_INFO "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data);
746 /* This one takes us to where we want to go. */ 731 /* This one takes us to where we want to go. */
747 if (nubus_readdir(&dir, &ent) == -1) 732 if (nubus_readdir(&dir, &ent) == -1)
748 goto badrom; 733 goto badrom;
749 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 734 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
750 printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); 735 printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data);
751 nubus_get_subdir(&ent, &dir); 736 nubus_get_subdir(&ent, &dir);
752 737
753 /* Resource ID 01, also an "Unknown Macintosh" */ 738 /* Resource ID 01, also an "Unknown Macintosh" */
754 if (nubus_readdir(&dir, &ent) == -1) 739 if (nubus_readdir(&dir, &ent) == -1)
755 goto badrom; 740 goto badrom;
756 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 741 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
757 printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); 742 printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data);
@@ -770,12 +755,12 @@ static void __init nubus_find_rom_dir(struct nubus_board* board)
770 goto badrom; 755 goto badrom;
771 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 756 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
772 printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); 757 printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data);
773 758
774 /* Bwahahahaha... */ 759 /* Bwahahahaha... */
775 nubus_get_subdir(&ent, &dir); 760 nubus_get_subdir(&ent, &dir);
776 board->directory = dir.base; 761 board->directory = dir.base;
777 return; 762 return;
778 763
779 /* Even more evil laughter... */ 764 /* Even more evil laughter... */
780 badrom: 765 badrom:
781 board->directory = board->fblock; 766 board->directory = board->fblock;
@@ -784,23 +769,22 @@ static void __init nubus_find_rom_dir(struct nubus_board* board)
784} 769}
785 770
786/* Add a board (might be many devices) to the list */ 771/* Add a board (might be many devices) to the list */
787static struct nubus_board* __init nubus_add_board(int slot, int bytelanes) 772static struct nubus_board * __init nubus_add_board(int slot, int bytelanes)
788{ 773{
789 struct nubus_board* board; 774 struct nubus_board *board;
790 struct nubus_board** boardp; 775 struct nubus_board **boardp;
791
792 unsigned char *rp; 776 unsigned char *rp;
793 unsigned long dpat; 777 unsigned long dpat;
794 struct nubus_dir dir; 778 struct nubus_dir dir;
795 struct nubus_dirent ent; 779 struct nubus_dirent ent;
796 780
797 /* Move to the start of the format block */ 781 /* Move to the start of the format block */
798 rp = nubus_rom_addr(slot); 782 rp = nubus_rom_addr(slot);
799 nubus_rewind(&rp, FORMAT_BLOCK_SIZE, bytelanes); 783 nubus_rewind(&rp, FORMAT_BLOCK_SIZE, bytelanes);
800 784
801 /* Actually we should probably panic if this fails */ 785 /* Actually we should probably panic if this fails */
802 if ((board = kzalloc(sizeof(*board), GFP_ATOMIC)) == NULL) 786 if ((board = kzalloc(sizeof(*board), GFP_ATOMIC)) == NULL)
803 return NULL; 787 return NULL;
804 board->fblock = rp; 788 board->fblock = rp;
805 789
806 /* Dump the format block for debugging purposes */ 790 /* Dump the format block for debugging purposes */
@@ -816,7 +800,7 @@ static struct nubus_board* __init nubus_add_board(int slot, int bytelanes)
816 rp = board->fblock; 800 rp = board->fblock;
817 801
818 board->slot = slot; 802 board->slot = slot;
819 board->slot_addr = (unsigned long) nubus_slot_addr(slot); 803 board->slot_addr = (unsigned long)nubus_slot_addr(slot);
820 board->doffset = nubus_get_rom(&rp, 4, bytelanes); 804 board->doffset = nubus_get_rom(&rp, 4, bytelanes);
821 /* rom_length is *supposed* to be the total length of the 805 /* rom_length is *supposed* to be the total length of the
822 * ROM. In practice it is the "amount of ROM used to compute 806 * ROM. In practice it is the "amount of ROM used to compute
@@ -827,16 +811,16 @@ static struct nubus_board* __init nubus_add_board(int slot, int bytelanes)
827 board->rom_length = nubus_get_rom(&rp, 4, bytelanes); 811 board->rom_length = nubus_get_rom(&rp, 4, bytelanes);
828 board->crc = nubus_get_rom(&rp, 4, bytelanes); 812 board->crc = nubus_get_rom(&rp, 4, bytelanes);
829 board->rev = nubus_get_rom(&rp, 1, bytelanes); 813 board->rev = nubus_get_rom(&rp, 1, bytelanes);
830 board->format = nubus_get_rom(&rp,1, bytelanes); 814 board->format = nubus_get_rom(&rp, 1, bytelanes);
831 board->lanes = bytelanes; 815 board->lanes = bytelanes;
832 816
833 /* Directory offset should be small and negative... */ 817 /* Directory offset should be small and negative... */
834 if(!(board->doffset & 0x00FF0000)) 818 if (!(board->doffset & 0x00FF0000))
835 pr_warn("Dodgy doffset!\n"); 819 pr_warn("Dodgy doffset!\n");
836 dpat = nubus_get_rom(&rp, 4, bytelanes); 820 dpat = nubus_get_rom(&rp, 4, bytelanes);
837 if(dpat != NUBUS_TEST_PATTERN) 821 if (dpat != NUBUS_TEST_PATTERN)
838 pr_warn("Wrong test pattern %08lx!\n", dpat); 822 pr_warn("Wrong test pattern %08lx!\n", dpat);
839 823
840 /* 824 /*
841 * I wonder how the CRC is meant to work - 825 * I wonder how the CRC is meant to work -
842 * any takers ? 826 * any takers ?
@@ -846,7 +830,7 @@ static struct nubus_board* __init nubus_add_board(int slot, int bytelanes)
846 830
847 /* Attempt to work around slot zero weirdness */ 831 /* Attempt to work around slot zero weirdness */
848 nubus_find_rom_dir(board); 832 nubus_find_rom_dir(board);
849 nubus_get_root_dir(board, &dir); 833 nubus_get_root_dir(board, &dir);
850 834
851 /* We're ready to rock */ 835 /* We're ready to rock */
852 pr_info("Slot %X:\n", slot); 836 pr_info("Slot %X:\n", slot);
@@ -869,8 +853,9 @@ static struct nubus_board* __init nubus_add_board(int slot, int bytelanes)
869 resources. I have no idea WTF to do about this. */ 853 resources. I have no idea WTF to do about this. */
870 854
871 while (nubus_readdir(&dir, &ent) != -1) { 855 while (nubus_readdir(&dir, &ent) != -1) {
872 struct nubus_dev* dev; 856 struct nubus_dev *dev;
873 struct nubus_dev** devp; 857 struct nubus_dev **devp;
858
874 dev = nubus_get_functional_resource(board, slot, &ent); 859 dev = nubus_get_functional_resource(board, slot, &ent);
875 if (dev == NULL) 860 if (dev == NULL)
876 continue; 861 continue;
@@ -878,32 +863,33 @@ static struct nubus_board* __init nubus_add_board(int slot, int bytelanes)
878 /* We zeroed this out above */ 863 /* We zeroed this out above */
879 if (board->first_dev == NULL) 864 if (board->first_dev == NULL)
880 board->first_dev = dev; 865 board->first_dev = dev;
881 866
882 /* Put it on the global NuBus device chain. Keep entries in order. */ 867 /* Put it on the global NuBus device chain. Keep entries in order. */
883 for (devp=&nubus_devices; *devp!=NULL; devp=&((*devp)->next)) 868 for (devp = &nubus_devices; *devp != NULL;
869 devp = &((*devp)->next))
884 /* spin */; 870 /* spin */;
885 *devp = dev; 871 *devp = dev;
886 dev->next = NULL; 872 dev->next = NULL;
887 } 873 }
888 874
889 /* Put it on the global NuBus board chain. Keep entries in order. */ 875 /* Put it on the global NuBus board chain. Keep entries in order. */
890 for (boardp=&nubus_boards; *boardp!=NULL; boardp=&((*boardp)->next)) 876 for (boardp = &nubus_boards; *boardp != NULL;
877 boardp = &((*boardp)->next))
891 /* spin */; 878 /* spin */;
892 *boardp = board; 879 *boardp = board;
893 board->next = NULL; 880 board->next = NULL;
894 881
895 return board; 882 return board;
896} 883}
897 884
898void __init nubus_probe_slot(int slot) 885void __init nubus_probe_slot(int slot)
899{ 886{
900 unsigned char dp; 887 unsigned char dp;
901 unsigned char* rp; 888 unsigned char *rp;
902 int i; 889 int i;
903 890
904 rp = nubus_rom_addr(slot); 891 rp = nubus_rom_addr(slot);
905 for(i = 4; i; i--) 892 for (i = 4; i; i--) {
906 {
907 int card_present; 893 int card_present;
908 894
909 rp--; 895 rp--;
@@ -918,11 +904,11 @@ void __init nubus_probe_slot(int slot)
918 /* The last byte of the format block consists of two 904 /* The last byte of the format block consists of two
919 nybbles which are "mirror images" of each other. 905 nybbles which are "mirror images" of each other.
920 These show us the valid bytelanes */ 906 These show us the valid bytelanes */
921 if ((((dp>>4) ^ dp) & 0x0F) != 0x0F) 907 if ((((dp >> 4) ^ dp) & 0x0F) != 0x0F)
922 continue; 908 continue;
923 /* Check that this value is actually *on* one of the 909 /* Check that this value is actually *on* one of the
924 bytelanes it claims are valid! */ 910 bytelanes it claims are valid! */
925 if ((dp & 0x0F) >= (1<<i)) 911 if ((dp & 0x0F) >= (1 << i))
926 continue; 912 continue;
927 913
928 /* Looks promising. Let's put it on the list. */ 914 /* Looks promising. Let's put it on the list. */
@@ -935,19 +921,19 @@ void __init nubus_probe_slot(int slot)
935void __init nubus_scan_bus(void) 921void __init nubus_scan_bus(void)
936{ 922{
937 int slot; 923 int slot;
924
938 /* This might not work on your machine */ 925 /* This might not work on your machine */
939#ifdef I_WANT_TO_PROBE_SLOT_ZERO 926#ifdef I_WANT_TO_PROBE_SLOT_ZERO
940 nubus_probe_slot(0); 927 nubus_probe_slot(0);
941#endif 928#endif
942 for(slot = 9; slot < 15; slot++) 929 for (slot = 9; slot < 15; slot++) {
943 {
944 nubus_probe_slot(slot); 930 nubus_probe_slot(slot);
945 } 931 }
946} 932}
947 933
948static int __init nubus_init(void) 934static int __init nubus_init(void)
949{ 935{
950 if (!MACH_IS_MAC) 936 if (!MACH_IS_MAC)
951 return 0; 937 return 0;
952 938
953 /* Initialize the NuBus interrupts */ 939 /* Initialize the NuBus interrupts */
@@ -963,11 +949,11 @@ static int __init nubus_init(void)
963 gurus can fix the real cause of the problem. */ 949 gurus can fix the real cause of the problem. */
964 mdelay(1000); 950 mdelay(1000);
965#endif 951#endif
966 952
967 /* And probe */ 953 /* And probe */
968 pr_info("NuBus: Scanning NuBus slots.\n"); 954 pr_info("NuBus: Scanning NuBus slots.\n");
969 nubus_devices = NULL; 955 nubus_devices = NULL;
970 nubus_boards = NULL; 956 nubus_boards = NULL;
971 nubus_scan_bus(); 957 nubus_scan_bus();
972 nubus_proc_init(); 958 nubus_proc_init();
973 return 0; 959 return 0;