Statistics
| Branch: | Revision:

root / pc-bios / ohw.diff @ 97067eb5

History | View | Annotate | Download (59.7 kB)

1
diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' --exclude mkdiff OpenHackWare-release-0.4.org/src/bios.h OpenHackWare-release-0.4/src/bios.h
2
--- OpenHackWare-release-0.4.org/src/bios.h        2005-04-06 23:20:22.000000000 +0200
3
+++ OpenHackWare-release-0.4/src/bios.h        2005-07-03 16:17:41.000000000 +0200
4
@@ -64,6 +64,7 @@
5
     ARCH_CHRP,
6
     ARCH_MAC99,
7
     ARCH_POP,
8
+    ARCH_HEATHROW,
9
 };
10
 
11
 /* Hardware definition(s) */
12
@@ -183,12 +184,12 @@
13
 part_t *bd_probe (int boot_device);
14
 bloc_device_t *bd_get (int device);
15
 void bd_put (bloc_device_t *bd);
16
-void bd_set_boot_part (bloc_device_t *bd, part_t *partition);
17
+void bd_set_boot_part (bloc_device_t *bd, part_t *partition, int partnum);
18
 part_t **_bd_parts (bloc_device_t *bd);
19
 
20
 void ide_pci_pc_register (uint32_t io_base0, uint32_t io_base1,
21
                           uint32_t io_base2, uint32_t io_base3,
22
-                          void *OF_private);
23
+                          void *OF_private0, void *OF_private1);
24
 void ide_pci_pmac_register (uint32_t io_base0, uint32_t io_base1,
25
                             void *OF_private);
26
 
27
@@ -399,17 +400,23 @@
28
                               uint16_t min_grant, uint16_t max_latency);
29
 void OF_finalize_pci_host (void *dev, int first_bus, int nb_busses);
30
 void OF_finalize_pci_device (void *dev, uint8_t bus, uint8_t devfn,
31
-                             uint32_t *regions, uint32_t *sizes);
32
+                             uint32_t *regions, uint32_t *sizes,
33
+                             int irq_line);
34
 void OF_finalize_pci_macio (void *dev, uint32_t base_address, uint32_t size,
35
                             void *private_data);
36
+void OF_finalize_pci_ide (void *dev, 
37
+                          uint32_t io_base0, uint32_t io_base1,
38
+                          uint32_t io_base2, uint32_t io_base3);
39
 int OF_register_bus (const unsigned char *name, uint32_t address,
40
                      const unsigned char *type);
41
 int OF_register_serial (const unsigned char *bus, const unsigned char *name,
42
                         uint32_t io_base, int irq);
43
 int OF_register_stdio (const unsigned char *dev_in,
44
                        const unsigned char *dev_out);
45
-void OF_vga_register (const unsigned char *name, uint32_t address,
46
-                      int width, int height, int depth);
47
+void OF_vga_register (const unsigned char *name, unused uint32_t address,
48
+                      int width, int height, int depth,
49
+                      unsigned long vga_bios_addr, 
50
+                      unsigned long vga_bios_size);
51
 void *OF_blockdev_register (void *parent, void *private,
52
                             const unsigned char *type,
53
                             const unsigned char *name, int devnum,
54
diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' --exclude mkdiff OpenHackWare-release-0.4.org/src/bloc.c OpenHackWare-release-0.4/src/bloc.c
55
--- OpenHackWare-release-0.4.org/src/bloc.c        2005-04-06 23:21:00.000000000 +0200
56
+++ OpenHackWare-release-0.4/src/bloc.c        2005-07-03 16:17:41.000000000 +0200
57
@@ -55,6 +55,7 @@
58
     /* Partitions */
59
     part_t *parts, *bparts;
60
     part_t *boot_part;
61
+    int bpartnum;
62
     /* Chain */
63
     bloc_device_t *next;
64
 };
65
@@ -223,10 +224,12 @@
66
 }
67
 
68
 /* XXX: to be suppressed */
69
-void bd_set_boot_part (bloc_device_t *bd, part_t *partition)
70
+void bd_set_boot_part (bloc_device_t *bd, part_t *partition, int partnum)
71
 {
72
+    dprintf("%s: part %p (%p) %d\n", __func__, partition, bd->boot_part, partnum);
73
     if (bd->boot_part == NULL) {
74
         bd->boot_part = partition;
75
+        bd->bpartnum = partnum;
76
     }
77
 }
78
 
79
@@ -240,6 +243,13 @@
80
     return &bd->bparts;
81
 }
82
 
83
+void bd_set_boot_device (bloc_device_t *bd)
84
+{
85
+#if defined (USE_OPENFIRMWARE)
86
+    OF_blockdev_set_boot_device(bd->OF_private, bd->bpartnum, "\\\\ofwboot");
87
+#endif
88
+}
89
+
90
 part_t *bd_probe (int boot_device)
91
 {
92
     char devices[] = { /*'a', 'b',*/ 'c', 'd', 'e', 'f', 'm', '\0', };
93
@@ -272,9 +282,7 @@
94
         tmp = part_probe(bd, force_raw);
95
         if (boot_device == bd->device) {
96
             boot_part = tmp;
97
-#if defined (USE_OPENFIRMWARE)
98
-            OF_blockdev_set_boot_device(bd->OF_private, 2, "\\\\ofwboot");
99
-#endif
100
+            bd_set_boot_device(bd);
101
         }
102
     }
103
 
104
@@ -717,34 +725,29 @@
105
 /* IDE PCI access for pc */
106
 static uint8_t ide_pci_port_read (bloc_device_t *bd, int port)
107
 {
108
-    eieio();
109
-
110
-    return *(uint8_t *)(bd->io_base + port);
111
+    uint8_t value;
112
+    value = inb(bd->io_base + port);
113
+    return value;
114
 }
115
 
116
 static void ide_pci_port_write (bloc_device_t *bd, int port, uint8_t value)
117
 {
118
-    *(uint8_t *)(bd->io_base + port) = value;
119
-    eieio();
120
+    outb(bd->io_base + port, value);
121
 }
122
 
123
 static uint32_t ide_pci_data_readl (bloc_device_t *bd)
124
 {
125
-    eieio();
126
-
127
-    return *((uint32_t *)bd->io_base);
128
+    return inl(bd->io_base);
129
 }
130
 
131
 static void ide_pci_data_writel (bloc_device_t *bd, uint32_t val)
132
 {
133
-    *(uint32_t *)(bd->io_base) = val;
134
-    eieio();
135
+    outl(bd->io_base, val);
136
 }
137
 
138
 static void ide_pci_control_write (bloc_device_t *bd, uint32_t val)
139
 {
140
-    *((uint8_t *)bd->tmp) = val;
141
-    eieio();
142
+    outb(bd->tmp + 2, val);
143
 }
144
 
145
 static ide_ops_t ide_pci_pc_ops = {
146
@@ -761,7 +764,7 @@
147
 
148
 void ide_pci_pc_register (uint32_t io_base0, uint32_t io_base1,
149
                           uint32_t io_base2, uint32_t io_base3,
150
-                          unused void *OF_private)
151
+                          void *OF_private0, void *OF_private1)
152
 {
153
     if (ide_pci_ops == NULL) {
154
         ide_pci_ops = malloc(sizeof(ide_ops_t));
155
@@ -770,19 +773,19 @@
156
         memcpy(ide_pci_ops, &ide_pci_pc_ops, sizeof(ide_ops_t));
157
     }
158
     if ((io_base0 != 0 || io_base1 != 0) &&
159
-        ide_pci_ops->base[0] == 0 && ide_pci_ops->base[1] == 0) {
160
+        ide_pci_ops->base[0] == 0 && ide_pci_ops->base[2] == 0) {
161
         ide_pci_ops->base[0] = io_base0;
162
-        ide_pci_ops->base[1] = io_base1;
163
+        ide_pci_ops->base[2] = io_base1;
164
 #ifdef USE_OPENFIRMWARE
165
-        ide_pci_ops->OF_private[0] = OF_private;
166
+        ide_pci_ops->OF_private[0] = OF_private0;
167
 #endif
168
     }
169
     if ((io_base2 != 0 || io_base3 != 0) &&
170
-        ide_pci_ops->base[2] == 0 && ide_pci_ops->base[3] == 0) {
171
-        ide_pci_ops->base[2] = io_base2;
172
+        ide_pci_ops->base[1] == 0 && ide_pci_ops->base[3] == 0) {
173
+        ide_pci_ops->base[1] = io_base2;
174
         ide_pci_ops->base[3] = io_base3;
175
 #ifdef USE_OPENFIRMWARE
176
-        ide_pci_ops->OF_private[1] = OF_private;
177
+        ide_pci_ops->OF_private[1] = OF_private1;
178
 #endif
179
     }
180
 }
181
diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' --exclude mkdiff OpenHackWare-release-0.4.org/src/libpart/apple.c OpenHackWare-release-0.4/src/libpart/apple.c
182
--- OpenHackWare-release-0.4.org/src/libpart/apple.c        2005-03-31 09:23:33.000000000 +0200
183
+++ OpenHackWare-release-0.4/src/libpart/apple.c        2005-07-03 16:17:41.000000000 +0200
184
@@ -199,14 +199,18 @@
185
         if (len == 0) {
186
             /* Place holder. Skip it */
187
             DPRINTF("%s placeholder part\t%d\n", __func__, i);
188
+            part->flags = PART_TYPE_APPLE | PART_FLAG_DUMMY;
189
+            part_register(bd, part, name, i);
190
         } else if (strncmp("Apple_Void", type, 32) == 0) {
191
             /* Void partition. Skip it */
192
             DPRINTF("%s Void part\t%d [%s]\n", __func__, i, type);
193
+            part->flags = PART_TYPE_APPLE | PART_FLAG_DUMMY;
194
+            part_register(bd, part, name, i);
195
         } else if (strncmp("Apple_Free", type, 32) == 0) {
196
             /* Free space. Skip it */
197
             DPRINTF("%s Free part (%d)\n", __func__, i);
198
             part->flags = PART_TYPE_APPLE | PART_FLAG_DUMMY;
199
-            part_register(bd, part, name);
200
+            part_register(bd, part, name, i);
201
         } else if (strncmp("Apple_partition_map", type, 32) == 0 ||
202
                    strncmp("Apple_Partition_Map", type, 32) == 0
203
 #if 0 // Is this really used or is it just a mistake ?
204
@@ -226,7 +230,7 @@
205
                  */
206
             }
207
             part->flags = PART_TYPE_APPLE | PART_FLAG_DUMMY;
208
-            part_register(bd, part, name);
209
+            part_register(bd, part, name, i);
210
         } else if (strncmp("Apple_Driver", type, 32) == 0 ||
211
                    strncmp("Apple_Driver43", type, 32) == 0 ||
212
                    strncmp("Apple_Driver43_CD", type, 32) == 0 ||
213
@@ -236,8 +240,12 @@
214
                    strncmp("Apple_Driver_IOKit", type, 32) == 0) {
215
             /* Drivers. don't care for now */
216
             DPRINTF("%s Drivers part\t%d [%s]\n", __func__, i, type);
217
+            part->flags = PART_TYPE_APPLE | PART_FLAG_DRIVER;
218
+            part_register(bd, part, name, i);
219
         } else if (strncmp("Apple_Patches", type, 32) == 0) {
220
             /* Patches: don't care for now */
221
+            part->flags = PART_TYPE_APPLE | PART_FLAG_PATCH;
222
+            part_register(bd, part, name, i);
223
             DPRINTF("%s Patches part\t%d [%s]\n", __func__, i, type);
224
         } else if (strncmp("Apple_HFS", type, 32) == 0 ||
225
                    strncmp("Apple_MFS", type, 32) == 0 ||
226
@@ -256,9 +264,8 @@
227
             count = partmap->bloc_cnt * HFS_BLOCSIZE;
228
             if (partmap->boot_size == 0 || partmap->boot_load == 0) {
229
                 printf("Not a bootable partition %d %d (%p %p)\n",
230
-                       partmap->boot_size, partmap->boot_load,boot_part, part);
231
-                if (boot_part == NULL)
232
-                    boot_part = part;
233
+                       partmap->boot_size, partmap->boot_load,
234
+                       boot_part, part);
235
                 part->flags = PART_TYPE_APPLE | PART_FLAG_FS;
236
             } else {
237
                 part->boot_start.bloc = partmap->boot_start;
238
@@ -278,8 +285,8 @@
239
                 boot_part = part;
240
                 part->flags = PART_TYPE_APPLE | PART_FLAG_FS | PART_FLAG_BOOT;
241
             }
242
-            printf("Partition: %d %s st %0x size %0x",
243
-                    i, name, partmap->start_bloc, partmap->bloc_cnt);
244
+            printf("Partition: %d '%s' '%s' st %0x size %0x",
245
+                    i, name, type, partmap->start_bloc, partmap->bloc_cnt);
246
 #ifndef DEBUG
247
             printf("\n");
248
 #endif
249
@@ -290,11 +297,13 @@
250
                     part->boot_load, part->boot_entry);
251
             DPRINTF("                           load %0x entry %0x %0x\n",
252
                     partmap->boot_load2, partmap->boot_entry2, HFS_BLOCSIZE);
253
-            part_register(bd, part, name);
254
+            part_register(bd, part, name, i);
255
         } else {
256
             memcpy(tmp, type, 32);
257
             tmp[32] = '\0';
258
             ERROR("Unknown partition type [%s]\n", tmp);
259
+            part->flags = PART_TYPE_APPLE | PART_FLAG_DUMMY;
260
+            part_register(bd, part, name, i);
261
         }
262
     }
263
  error:
264
diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' --exclude mkdiff OpenHackWare-release-0.4.org/src/libpart/core.c OpenHackWare-release-0.4/src/libpart/core.c
265
--- OpenHackWare-release-0.4.org/src/libpart/core.c        2005-03-31 09:23:33.000000000 +0200
266
+++ OpenHackWare-release-0.4/src/libpart/core.c        2005-07-03 16:17:41.000000000 +0200
267
@@ -126,7 +126,7 @@
268
 }
269
 
270
 int part_register (bloc_device_t *bd, part_t *partition,
271
-                   const unsigned char *name)
272
+                   const unsigned char *name, int partnum)
273
 {
274
     part_t **cur;
275
 
276
@@ -134,6 +134,7 @@
277
     partition->bd = bd;
278
     partition->next = NULL;
279
     partition->name = strdup(name);
280
+    partition->partnum = partnum;
281
     for (cur = _bd_parts(bd); *cur != NULL; cur = &(*cur)->next)
282
         continue;
283
     *cur = partition;
284
@@ -141,29 +142,15 @@
285
     return 0;
286
 }
287
 
288
-static inline int set_boot_part (bloc_device_t *bd, int partnum)
289
-{
290
-    part_t *cur;
291
-
292
-    cur = part_get(bd, partnum);
293
-    if (cur == NULL)
294
-        return -1;
295
-    bd_set_boot_part(bd, cur);
296
-
297
-    return 0;
298
-}
299
-
300
 part_t *part_get (bloc_device_t *bd, int partnum)
301
 {
302
     part_t **listp, *cur;
303
-    int i;
304
 
305
     listp = _bd_parts(bd);
306
-    cur = *listp;
307
-    for (i = 0; i != partnum; i++) {
308
-        if (cur == NULL)
309
+    
310
+    for (cur = *listp; cur != NULL; cur = cur->next) {
311
+        if (cur->partnum == partnum)
312
             break;
313
-        cur = cur->next;
314
     }
315
     
316
     return cur;
317
@@ -192,17 +179,20 @@
318
     part_set_blocsize(bd, part, 512);
319
     part->bd = bd;
320
     part->flags = PART_TYPE_RAW | PART_FLAG_BOOT;
321
-    part_register(bd, part, "Raw");
322
+    part_register(bd, part, "Raw", 0);
323
 
324
     return part;
325
 }
326
 
327
+bloc_device_t *part_get_bd (part_t *part)
328
+{
329
+    return part->bd;
330
+}
331
+
332
 part_t *part_probe (bloc_device_t *bd, int set_raw)
333
 {
334
-    part_t *part0, *boot_part, **cur;
335
+    part_t *part0 = NULL, *boot_part, **cur;
336
 
337
-    /* Register the 0 partition: raw partition containing the whole disk */
338
-    part0 = part_get_raw(bd);
339
     /* Try to find a valid boot partition */
340
     boot_part = Apple_probe_partitions(bd);
341
     if (boot_part == NULL) {
342
@@ -210,10 +200,13 @@
343
         if (boot_part == NULL && arch == ARCH_PREP)
344
             boot_part = PREP_find_partition(bd);
345
         if (boot_part == NULL && set_raw != 0) {
346
-            boot_part = part0;
347
-            set_boot_part(bd, 0);
348
+            dprintf("Use bloc device as raw partition\n");
349
         }
350
     }
351
+    if (_bd_parts(bd) == NULL) {
352
+        /* Register the 0 partition: raw partition containing the whole disk */
353
+        part0 = part_get_raw(bd);
354
+    }
355
     /* Probe filesystem on each found partition */
356
     for (cur = _bd_parts(bd); *cur != NULL; cur = &(*cur)->next) {
357
         const unsigned char *map, *type;
358
@@ -248,23 +241,28 @@
359
             type = "unknown";
360
             break;
361
         }
362
-        DPRINTF("Probe filesystem on %s %s partition '%s' %s\n",
363
+        dprintf("Probe filesystem on %s %s partition '%s' %s %p\n",
364
                 type, map, (*cur)->name,
365
-                ((*cur)->flags) & PART_FLAG_BOOT ? "(bootable)" : "");
366
+                ((*cur)->flags) & PART_FLAG_BOOT ? "(bootable)" : "", *cur);
367
         if (((*cur)->flags) & PART_FLAG_FS) {
368
             if (((*cur)->flags) & PART_FLAG_BOOT)
369
                 (*cur)->fs = fs_probe(*cur, 1);
370
             else
371
                 (*cur)->fs = fs_probe(*cur, 0);
372
+        } else if (((*cur)->flags) & PART_TYPE_RAW) {
373
+            (*cur)->fs = fs_probe(*cur, 2);
374
         } else {
375
             (*cur)->fs = fs_probe(*cur, 2);
376
         }
377
-        if (((*cur)->flags) & PART_FLAG_BOOT) {
378
-            bd_set_boot_part(bd, *cur);
379
             fs_get_bootfile((*cur)->fs);
380
+        if (((*cur)->flags) & PART_FLAG_BOOT) {
381
+            dprintf("Partition is bootable (%d)\n", (*cur)->partnum);
382
+            bd_set_boot_part(bd, *cur, (*cur)->partnum);
383
+            if (boot_part == NULL)
384
+                boot_part = *cur;
385
         }
386
     }
387
-    DPRINTF("Boot partition: %p %p %p %p\n", boot_part, boot_part->fs,
388
+    dprintf("Boot partition: %p %p %p %p\n", boot_part, boot_part->fs,
389
             part_fs(boot_part), part0);
390
 
391
     return boot_part;
392
@@ -279,6 +277,7 @@
393
     part->boot_size.offset = 0;
394
     part->boot_load = 0;
395
     part->boot_entry = 0;
396
+    part->flags |= PART_FLAG_BOOT;
397
 
398
     return 0;
399
 }
400
diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' --exclude mkdiff OpenHackWare-release-0.4.org/src/libpart/isofs.c OpenHackWare-release-0.4/src/libpart/isofs.c
401
--- OpenHackWare-release-0.4.org/src/libpart/isofs.c        2005-03-31 09:23:33.000000000 +0200
402
+++ OpenHackWare-release-0.4/src/libpart/isofs.c        2005-07-03 16:17:41.000000000 +0200
403
@@ -242,7 +242,7 @@
404
                    part->boot_start.bloc, part->boot_size.bloc,
405
                    part->boot_load, part->boot_entry);
406
             part->flags = PART_TYPE_ISO9660 | PART_FLAG_BOOT;
407
-            part_register(bd, part, name);
408
+            part_register(bd, part, name, i + 1);
409
             fs_raw_set_bootfile(part, part->boot_start.bloc,
410
                                 part->boot_start.offset,
411
                                 part->boot_size.bloc,
412
diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' --exclude mkdiff OpenHackWare-release-0.4.org/src/libpart/libpart.h OpenHackWare-release-0.4/src/libpart/libpart.h
413
--- OpenHackWare-release-0.4.org/src/libpart/libpart.h        2005-03-31 09:23:33.000000000 +0200
414
+++ OpenHackWare-release-0.4/src/libpart/libpart.h        2005-07-03 16:17:41.000000000 +0200
415
@@ -30,6 +30,7 @@
416
 
417
 struct part_t {
418
     bloc_device_t *bd;
419
+    int partnum;
420
     uint32_t start;      /* Partition first bloc             */
421
     uint32_t size;       /* Partition size, in blocs         */
422
     uint32_t spb;
423
@@ -54,7 +55,7 @@
424
 };
425
 
426
 int part_register (bloc_device_t *bd, part_t *partition,
427
-                   const unsigned char *name);
428
+                   const unsigned char *name, int partnum);
429
 void part_set_blocsize (bloc_device_t *bd, part_t *part, uint32_t blocsize);
430
 void part_private_set (part_t *part, void *private);
431
 void *part_private_get (part_t *part);
432
diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' --exclude mkdiff OpenHackWare-release-0.4.org/src/libpart/prep.c OpenHackWare-release-0.4/src/libpart/prep.c
433
--- OpenHackWare-release-0.4.org/src/libpart/prep.c        2005-03-31 09:23:33.000000000 +0200
434
+++ OpenHackWare-release-0.4/src/libpart/prep.c        2005-07-03 16:17:41.000000000 +0200
435
@@ -164,7 +164,7 @@
436
             part->boot_load = 0;
437
             part->boot_entry = boot_offset - part->bloc_size;
438
             part->flags = PART_TYPE_PREP | PART_FLAG_BOOT;
439
-            part_register(bd, part, "PREP boot");
440
+            part_register(bd, part, "PREP boot", i);
441
             fs_raw_set_bootfile(part, part->boot_start.bloc,
442
                                 part->boot_start.offset,
443
                                 part->boot_size.bloc,
444
diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' --exclude mkdiff OpenHackWare-release-0.4.org/src/main.c OpenHackWare-release-0.4/src/main.c
445
--- OpenHackWare-release-0.4.org/src/main.c        2005-03-31 09:23:33.000000000 +0200
446
+++ OpenHackWare-release-0.4/src/main.c        2005-06-07 23:48:39.000000000 +0200
447
@@ -364,20 +364,24 @@
448
     void *load_base, *load_entry, *last_alloc, *load_end;
449
     uint32_t memsize, boot_image_size, cmdline_size, ramdisk_size;
450
     uint32_t boot_base, boot_nb;
451
-    int boot_device;
452
+    int boot_device, i;
453
+    static const uint32_t isa_base_tab[3] = {
454
+        0x80000000, /* PREP */
455
+        0xFE000000, /* Grackle (Heathrow) */
456
+        0xF2000000, /* UniNorth (Mac99)  */
457
+    };
458
 
459
     /* Retrieve NVRAM configuration */
460
- nvram_retry:
461
+    for(i = 0; i < 3; i++) {
462
+        isa_io_base = isa_base_tab[i];
463
     nvram = NVRAM_get_config(&memsize, &boot_device,
464
                              &boot_image, &boot_image_size,
465
                              &cmdline, &cmdline_size,
466
                              &ramdisk, &ramdisk_size);
467
-    if (nvram == NULL) {
468
-        /* Retry with another isa_io_base */
469
-        if (isa_io_base == 0x80000000) {
470
-            isa_io_base = 0xF2000000;
471
-            goto nvram_retry;
472
+        if (nvram)
473
+            break;
474
         }
475
+    if (i == 3) {
476
         ERROR("Unable to load configuration from NVRAM. Aborting...\n");
477
         return -1;
478
     }
479
@@ -402,7 +406,7 @@
480
         cpu_name = CPU_get_name(pvr);
481
         OF_register_cpu(cpu_name, 0, pvr,
482
                         200 * 1000 * 1000, 200 * 1000 * 1000,
483
-                        100 * 1000 * 1000, 10 * 1000 * 1000,
484
+                        100 * 1000 * 1000, 100 * 1000 * 1000,
485
                         0x0092);
486
     }
487
     OF_register_memory(memsize, 512 * 1024 /* TOFIX */);
488
@@ -433,9 +437,12 @@
489
     vga_puts(copyright);
490
     vga_puts("\n");
491
 
492
+#if 0
493
     /* QEMU is quite incoherent: d is cdrom, not second drive */
494
+    /* XXX: should probe CD-ROM position */
495
     if (boot_device == 'd')
496
         boot_device = 'e';
497
+#endif
498
     /* Open boot device */
499
     boot_part = bd_probe(boot_device);
500
     if (boot_device == 'm') {
501
diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' --exclude mkdiff OpenHackWare-release-0.4.org/src/nvram.c OpenHackWare-release-0.4/src/nvram.c
502
--- OpenHackWare-release-0.4.org/src/nvram.c        2005-03-31 09:23:33.000000000 +0200
503
+++ OpenHackWare-release-0.4/src/nvram.c        2005-06-04 23:44:03.000000000 +0200
504
@@ -334,6 +334,7 @@
505
         ret = NVRAM_chrp_format(nvram);
506
         break;
507
     case ARCH_MAC99:
508
+    case ARCH_HEATHROW: /* XXX: may be incorrect */
509
         ret = NVRAM_mac99_format(nvram);
510
         break;
511
     case ARCH_POP:
512
@@ -409,13 +410,12 @@
513
         arch = ARCH_MAC99;
514
     } else if (strcmp(sign, "POP") == 0) {
515
         arch = ARCH_POP;
516
+    } else if (strcmp(sign, "HEATHROW") == 0) {
517
+        arch = ARCH_HEATHROW;
518
     } else {
519
         ERROR("Unknown PPC architecture: '%s'\n", sign);
520
         return NULL;
521
     }
522
-    /* HACK */
523
-    if (arch == ARCH_CHRP)
524
-        arch = ARCH_MAC99;
525
     lword = NVRAM_get_lword(nvram, 0x30);
526
     *RAM_size = lword;
527
     byte = NVRAM_get_byte(nvram, 0x34);
528
diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' --exclude mkdiff OpenHackWare-release-0.4.org/src/of.c OpenHackWare-release-0.4/src/of.c
529
--- OpenHackWare-release-0.4.org/src/of.c        2005-04-06 23:17:26.000000000 +0200
530
+++ OpenHackWare-release-0.4/src/of.c        2005-07-03 17:46:25.000000000 +0200
531
@@ -489,7 +489,7 @@
532
         ERROR("%s can't alloc new node '%s' name\n", __func__, name);
533
         return NULL;
534
     }
535
-    new->prop_address = OF_prop_int_new(env, new, "address", address);
536
+    new->prop_address = OF_prop_int_new(env, new, "unit-address", address);
537
     if (new->prop_address == NULL) {
538
         free(new->prop_name->value);
539
         free(new->prop_name);
540
@@ -1421,15 +1421,12 @@
541
 __attribute__ (( section (".OpenFirmware") ))
542
 int OF_init (void)
543
 {
544
-    const unsigned char compat_str[] =
545
 #if 0
546
         "PowerMac3,1\0MacRISC\0Power Macintosh\0";
547
         "PowerMac1,2\0MacRISC\0Power Macintosh\0";
548
         "AAPL,PowerMac G3\0PowerMac G3\0MacRISC\0Power Macintosh\0";
549
         "AAPL,PowerMac3,0\0MacRISC\0Power Macintosh\0";
550
         "AAPL,Gossamer\0MacRISC\0Power Macintosh\0";
551
-#else
552
-        "AAPL,PowerMac G3\0PowerMac G3\0MacRISC\0Power Macintosh\0";
553
 #endif
554
     OF_env_t *OF_env;
555
     OF_node_t *als, *opt, *chs, *pks;
556
@@ -1455,15 +1452,21 @@
557
         return -1;
558
     }
559
     OF_prop_string_new(OF_env, OF_node_root, "device_type", "bootrom");
560
-#if 0
561
-    OF_prop_string_new(OF_env, OF_node_root,
562
-                       "model", "PPC Open Hack'Ware " BIOS_VERSION);
563
-#else
564
+    if (arch == ARCH_HEATHROW) {
565
+        const unsigned char compat_str[] =
566
+            "PowerMac1,1\0MacRISC\0Power Macintosh";
567
+        OF_property_new(OF_env, OF_node_root, "compatible",
568
+                        compat_str, sizeof(compat_str));
569
     OF_prop_string_new(OF_env, OF_node_root,
570
-                       "model", compat_str);
571
-#endif
572
+                           "model", "Power Macintosh");
573
+    } else {
574
+        const unsigned char compat_str[] =
575
+            "PowerMac3,1\0MacRISC\0Power Macintosh";
576
     OF_property_new(OF_env, OF_node_root, "compatible",
577
                     compat_str, sizeof(compat_str));
578
+        OF_prop_string_new(OF_env, OF_node_root,
579
+                           "model", "PowerMac3,1");
580
+    }
581
 #if 0
582
     OF_prop_string_new(OF_env, OF_node_root, "copyright", copyright);
583
 #else
584
@@ -1561,14 +1564,15 @@
585
         range.size = 0x00800000;
586
         OF_property_new(OF_env, rom, "ranges", &range, sizeof(OF_range_t));
587
         OF_prop_int_new(OF_env, rom, "#address-cells", 1);
588
+
589
         /* "/rom/boot-rom@fff00000" node */
590
-        brom = OF_node_new(OF_env, OF_node_root, "boot-rom", 0xfff00000);
591
+        brom = OF_node_new(OF_env, rom, "boot-rom", 0xfff00000);
592
         if (brom == NULL) {
593
             ERROR("Cannot create 'boot-rom'\n");
594
             return -1;
595
         }
596
         regs.address = 0xFFF00000;
597
-        regs.size = 0x00010000;
598
+        regs.size = 0x00100000;
599
         OF_property_new(OF_env, brom, "reg", &regs, sizeof(OF_regprop_t));
600
         OF_prop_string_new(OF_env, brom, "write-characteristic", "flash");
601
         OF_prop_string_new(OF_env, brom, "BootROM-build-date",
602
@@ -1577,7 +1581,7 @@
603
         OF_prop_string_new(OF_env, brom, "copyright", copyright);
604
         OF_prop_string_new(OF_env, brom, "model", BIOS_str);
605
         OF_prop_int_new(OF_env, brom, "result", 0);
606
-#if 0
607
+#if 1
608
         {
609
             /* Hack taken 'as-is' from PearPC */
610
             unsigned char info[] = {
611
@@ -1596,7 +1600,9 @@
612
         OF_node_put(OF_env, brom);
613
         OF_node_put(OF_env, rom);
614
     }
615
+#if 0
616
     /* From here, hardcoded hacks to get a Mac-like machine */
617
+    /* XXX: Core99 does not seem to like this NVRAM tree */
618
     /* "/nvram@fff04000" node */
619
     {
620
         OF_regprop_t regs;
621
@@ -1617,6 +1623,7 @@
622
         OF_prop_int_new(OF_env, chs, "nvram", OF_pack_handle(OF_env, nvr));
623
         OF_node_put(OF_env, nvr);
624
     }
625
+#endif
626
     /* "/pseudo-hid" : hid emulation as Apple does */
627
     {
628
         OF_node_t *hid;
629
@@ -1663,7 +1670,27 @@
630
         }
631
         OF_node_put(OF_env, hid);
632
     }
633
+    if (arch == ARCH_MAC99) {
634
+        OF_node_t *unin;
635
+        OF_regprop_t regs;
636
 
637
+        unin = OF_node_new(OF_env, OF_node_root,
638
+                           "uni-n", 0xf8000000);
639
+        if (unin == NULL) {
640
+            ERROR("Cannot create 'uni-n'\n");
641
+            return -1;
642
+        }
643
+        OF_prop_string_new(OF_env, unin, "device-type", "memory-controller");
644
+        OF_prop_string_new(OF_env, unin, "model", "AAPL,UniNorth");
645
+        OF_prop_string_new(OF_env, unin, "compatible", "uni-north");
646
+        regs.address = 0xf8000000;
647
+        regs.size = 0x01000000;
648
+        OF_property_new(OF_env, unin, "reg", &regs, sizeof(regs));
649
+        OF_prop_int_new(OF_env, unin, "#address-cells", 1);
650
+        OF_prop_int_new(OF_env, unin, "#size-cells", 1);
651
+        OF_prop_int_new(OF_env, unin, "device-rev", 3);
652
+        OF_node_put(OF_env, unin);
653
+    }
654
     
655
 #if 1 /* This is mandatory for claim to work
656
        * but I don't know where it should really be (in cpu ?)
657
@@ -1693,7 +1720,9 @@
658
 
659
     /* "/options/boot-args" node */
660
     {
661
-        const unsigned char *args = "-v rootdev cdrom";
662
+        //        const unsigned char *args = "-v rootdev cdrom";
663
+        //const unsigned char *args = "-v io=0xffffffff";
664
+        const unsigned char *args = "-v";
665
         /* Ask MacOS X to print debug messages */
666
         //        OF_prop_string_new(OF_env, chs, "machargs", args);
667
         //        OF_prop_string_new(OF_env, opt, "boot-command", args);
668
@@ -2021,9 +2050,9 @@
669
     if (dev->acells != 0)
670
         OF_prop_int_new(OF_env, node, "#address-cells", dev->acells);
671
     if (dev->scells != 0)
672
-        OF_prop_int_new(OF_env, node, "#interrupt-cells", dev->acells);
673
+        OF_prop_int_new(OF_env, node, "#size-cells", dev->scells);
674
     if (dev->icells != 0)
675
-        OF_prop_int_new(OF_env, node, "#size-cells", dev->acells);
676
+        OF_prop_int_new(OF_env, node, "#interrupt-cells", dev->icells);
677
     dprintf("Done %p %p\n", parent, node);
678
     
679
     return node;
680
@@ -2040,8 +2069,9 @@
681
     OF_env_t *OF_env;
682
     pci_range_t ranges[3];
683
     OF_regprop_t regs[1];
684
-    OF_node_t *pci_host;
685
+    OF_node_t *pci_host, *als;
686
     int nranges;
687
+    unsigned char buffer[OF_NAMELEN_MAX];
688
 
689
     OF_env = OF_env_main;
690
     dprintf("register PCI host '%s' '%s' '%s' '%s'\n",
691
@@ -2052,6 +2082,17 @@
692
         ERROR("Cannot create pci host\n");
693
         return NULL;
694
     }
695
+    
696
+    als = OF_node_get(OF_env, "aliases");
697
+    if (als == NULL) {
698
+        ERROR("Cannot get 'aliases'\n");
699
+        return NULL;
700
+    }
701
+    sprintf(buffer, "/%s", dev->name);
702
+    OF_prop_string_set(OF_env, als, "pci", buffer);
703
+    OF_node_put(OF_env, als);
704
+    
705
+
706
     regs[0].address = cfg_base;
707
     regs[0].size = cfg_len;
708
     OF_property_new(OF_env, pci_host, "reg", regs, sizeof(OF_regprop_t));
709
@@ -2136,6 +2177,11 @@
710
     return pci_dev;
711
 }
712
 
713
+/* XXX: suppress that, used for interrupt map init */
714
+OF_node_t *pci_host_node;
715
+uint32_t pci_host_interrupt_map[7 * 32];
716
+int pci_host_interrupt_map_len = 0;
717
+
718
 void OF_finalize_pci_host (void *dev, int first_bus, int nb_busses)
719
 {
720
     OF_env_t *OF_env;
721
@@ -2145,10 +2191,12 @@
722
     regs[0].address = first_bus;
723
     regs[0].size = nb_busses;
724
     OF_property_new(OF_env, dev, "bus-range", regs, sizeof(OF_regprop_t));
725
+    pci_host_node = dev;
726
 }
727
 
728
 void OF_finalize_pci_device (void *dev, uint8_t bus, uint8_t devfn,
729
-                             uint32_t *regions, uint32_t *sizes)
730
+                             uint32_t *regions, uint32_t *sizes,
731
+                             int irq_line)
732
 {
733
     OF_env_t *OF_env;
734
     pci_reg_prop_t pregs[6], rregs[6];
735
@@ -2156,6 +2204,7 @@
736
     int i, j, k;
737
 
738
     OF_env = OF_env_main;
739
+    /* XXX: only useful for VGA card in fact */
740
     if (regions[0] != 0x00000000)
741
         OF_prop_int_set(OF_env, dev, "address", regions[0] & ~0x0000000F);
742
     for (i = 0, j = 0, k = 0; i < 6; i++) {
743
@@ -2222,7 +2271,22 @@
744
     } else {
745
         OF_property_new(OF_env, dev, "assigned-addresses", NULL, 0);
746
     }
747
-#if 0
748
+    if (irq_line >= 0) {
749
+        int i;
750
+        OF_prop_int_new(OF_env, dev, "interrupts", 1);
751
+        i = pci_host_interrupt_map_len;
752
+        pci_host_interrupt_map[i++] = (devfn << 8) & 0xf800;
753
+        pci_host_interrupt_map[i++] = 0;
754
+        pci_host_interrupt_map[i++] = 0;
755
+        pci_host_interrupt_map[i++] = 0;
756
+        pci_host_interrupt_map[i++] = 0; /* pic handle will be patched later */
757
+        pci_host_interrupt_map[i++] = irq_line;
758
+        if (arch != ARCH_HEATHROW) {
759
+            pci_host_interrupt_map[i++] = 1;
760
+        }
761
+        pci_host_interrupt_map_len = i;
762
+    }
763
+#if 1
764
     {
765
         OF_prop_t *prop_name = ((OF_node_t *)dev)->prop_name;
766
 
767
@@ -2390,6 +2454,54 @@
768
     return 0;
769
 }
770
 
771
+static void keylargo_ata(OF_node_t *mio, uint32_t base_address,
772
+                         uint32_t base, int irq1, int irq2, 
773
+                         uint16_t pic_phandle)
774
+{
775
+    OF_env_t *OF_env = OF_env_main;
776
+    OF_node_t *ata;
777
+    OF_regprop_t regs[2];
778
+
779
+    ata = OF_node_new(OF_env, mio, "ata-4", base);
780
+    if (ata == NULL) {
781
+        ERROR("Cannot create 'ata-4'\n");
782
+        return;
783
+    }
784
+    OF_prop_string_new(OF_env, ata, "device_type", "ata");
785
+#if 1
786
+    OF_prop_string_new(OF_env, ata, "compatible", "key2largo-ata");
787
+    OF_prop_string_new(OF_env, ata, "model", "ata-4");
788
+    OF_prop_string_new(OF_env, ata, "cable-type", "80-conductor");
789
+#else
790
+    OF_prop_string_new(OF_env, ata, "compatible", "cmd646-ata");
791
+    OF_prop_string_new(OF_env, ata, "model", "ata-4");
792
+#endif
793
+    OF_prop_int_new(OF_env, ata, "#address-cells", 1);
794
+    OF_prop_int_new(OF_env, ata, "#size-cells", 0);
795
+    regs[0].address = base;
796
+    regs[0].size = 0x00001000;
797
+#if 0 // HACK: Don't set up DMA registers
798
+    regs[1].address = 0x00008A00;
799
+    regs[1].size = 0x00001000;
800
+    OF_property_new(OF_env, ata, "reg",
801
+                    regs, 2 * sizeof(OF_regprop_t));
802
+#else
803
+    OF_property_new(OF_env, ata, "reg",
804
+                    regs, sizeof(OF_regprop_t));
805
+#endif
806
+    OF_prop_int_new(OF_env, ata, "interrupt-parent", pic_phandle);
807
+    regs[0].address = irq1;
808
+    regs[0].size = 0x00000001;
809
+    regs[1].address = irq2;
810
+    regs[1].size = 0x00000000;
811
+    OF_property_new(OF_env, ata, "interrupts",
812
+                    regs, 2 * sizeof(OF_regprop_t));
813
+    if (base == 0x1f000)
814
+        ide_pci_pmac_register(base_address + base, 0x00000000, ata);
815
+    else
816
+        ide_pci_pmac_register(0x00000000, base_address + base, ata);
817
+}
818
+
819
 void OF_finalize_pci_macio (void *dev, uint32_t base_address, uint32_t size,
820
                             void *private_data)
821
 {
822
@@ -2398,6 +2510,8 @@
823
     pci_reg_prop_t pregs[2];
824
     OF_node_t *mio, *chs, *als;
825
     uint16_t pic_phandle;
826
+    int rec_len;
827
+    OF_prop_t *mio_reg;
828
 
829
     OF_DPRINTF("mac-io: %p\n", dev);
830
     OF_env = OF_env_main;
831
@@ -2416,10 +2530,14 @@
832
     mio = dev;
833
     mio->private_data = private_data;
834
     pregs[0].addr.hi = 0x00000000;
835
-    pregs[0].addr.mid = 0x82013810;
836
+    pregs[0].addr.mid = 0x00000000;
837
     pregs[0].addr.lo = 0x00000000;
838
     pregs[0].size_hi = base_address;
839
     pregs[0].size_lo = size;
840
+    mio_reg = OF_property_get(OF_env, mio, "reg");
841
+    if (mio_reg && mio_reg->vlen >= 5 * 4) {
842
+        pregs[0].addr.mid = ((pci_reg_prop_t *)mio_reg->value)->addr.hi;
843
+    }
844
     OF_property_new(OF_env, mio, "ranges",
845
                     &pregs, sizeof(pci_reg_prop_t));
846
 #if 0
847
@@ -2431,8 +2549,49 @@
848
     OF_property_new(OF_env, mio, "assigned-addresses",
849
                     &pregs, sizeof(pci_reg_prop_t));
850
 #endif
851
-    /* OpenPIC */
852
+
853
+    switch(arch) {
854
+    default:
855
+    case ARCH_MAC99:
856
+        OF_prop_int_new(OF_env, mio, "#interrupt-cells", 2);
857
+        OF_prop_string_new(OF_env, mio, "model", "AAPL,Keylargo");
858
+        OF_prop_string_new(OF_env, mio, "compatible", "Keylargo");
859
+        break;
860
+    case ARCH_HEATHROW:
861
+        OF_prop_int_new(OF_env, mio, "#interrupt-cells", 1);
862
+        OF_prop_string_new(OF_env, mio, "model", "AAPL,343S1211");
863
     {
864
+            const char str[] = "paddington\0heathrow";
865
+            OF_property_new(OF_env, mio, "compatible", str, sizeof(str));
866
+        }
867
+        break;
868
+    }
869
+
870
+    if (arch == ARCH_HEATHROW) {
871
+        /* Heathrow PIC */
872
+        OF_regprop_t regs;
873
+        OF_node_t *mpic;
874
+        const char compat_str[] = "heathrow\0mac-risc";
875
+
876
+        mpic = OF_node_new(OF_env, mio, "interrupt-controller", 0x10);
877
+        if (mpic == NULL) {
878
+            ERROR("Cannot create 'mpic'\n");
879
+            goto out;
880
+        }
881
+        OF_prop_string_new(OF_env, mpic, "device_type", "interrupt-controller");
882
+        OF_property_new(OF_env, mpic, "compatible", compat_str, sizeof(compat_str));
883
+        OF_prop_int_new(OF_env, mpic, "#interrupt-cells", 1);
884
+        regs.address = 0x10;
885
+        regs.size = 0x20;
886
+        OF_property_new(OF_env, mpic, "reg",
887
+                        &regs, sizeof(regs));
888
+        OF_property_new(OF_env, mpic, "interrupt-controller", NULL, 0);
889
+        pic_phandle = OF_pack_handle(OF_env, mpic);
890
+        OF_prop_int_new(OF_env, chs, "interrupt-controller", pic_phandle);
891
+        OF_node_put(OF_env, mpic);
892
+        rec_len = 6;
893
+    } else {
894
+        /* OpenPIC */
895
         OF_regprop_t regs[4];
896
         OF_node_t *mpic;
897
         mpic = OF_node_new(OF_env, mio, "interrupt-controller", 0x40000);
898
@@ -2455,8 +2614,37 @@
899
         pic_phandle = OF_pack_handle(OF_env, mpic);
900
         OF_prop_int_new(OF_env, chs, "interrupt-controller", pic_phandle);
901
         OF_node_put(OF_env, mpic);
902
+        rec_len = 7;
903
     }
904
-#if 1
905
+
906
+    /* patch pci host table */
907
+    /* XXX: do it after the PCI init */
908
+    {
909
+        int i;
910
+        uint32_t tab[4];
911
+
912
+        for(i = 0; i < pci_host_interrupt_map_len; i += rec_len)
913
+            pci_host_interrupt_map[i + 4] = pic_phandle;
914
+#if 0
915
+        dprintf("interrupt-map:\n");
916
+        for(i = 0; i < pci_host_interrupt_map_len; i++) {
917
+            dprintf(" %08x", pci_host_interrupt_map[i]);
918
+            if ((i % rec_len) == (rec_len - 1))
919
+                dprintf("\n");
920
+        }
921
+        dprintf("\n");
922
+#endif
923
+        OF_property_new(OF_env, pci_host_node, "interrupt-map", 
924
+                        pci_host_interrupt_map, 
925
+                        pci_host_interrupt_map_len * sizeof(uint32_t));
926
+        tab[0] = 0xf800;
927
+        tab[1] = 0;
928
+        tab[2] = 0;
929
+        tab[3] = 0;
930
+        OF_property_new(OF_env, pci_host_node, "interrupt-map-mask", 
931
+                        tab, 4 * sizeof(uint32_t));
932
+    }
933
+#if 0
934
     /* escc is usefull to get MacOS X debug messages */
935
     {
936
         OF_regprop_t regs[8];
937
@@ -2645,85 +2833,12 @@
938
         OF_node_put(OF_env, scc);
939
     }
940
 #endif
941
-    /* IDE controller */
942
-    {
943
-        OF_node_t *ata;
944
-        OF_regprop_t regs[2];
945
-        ata = OF_node_new(OF_env, mio, "ata-4", 0x1f000);
946
-        if (ata == NULL) {
947
-            ERROR("Cannot create 'ata-4'\n");
948
-            goto out;
949
-        }
950
-        OF_prop_string_new(OF_env, ata, "device_type", "ata");
951
-#if 1
952
-        OF_prop_string_new(OF_env, ata, "compatible", "keylargo-ata");
953
-        OF_prop_string_new(OF_env, ata, "model", "ata-4");
954
-#else
955
-        OF_prop_string_new(OF_env, ata, "compatible", "cmd646-ata");
956
-        OF_prop_string_new(OF_env, ata, "model", "ata-4");
957
-#endif
958
-        OF_prop_int_new(OF_env, ata, "#address-cells", 1);
959
-        OF_prop_int_new(OF_env, ata, "#size-cells", 0);
960
-        regs[0].address = 0x0001F000;
961
-        regs[0].size = 0x00001000;
962
-#if 0 // HACK: Don't set up DMA registers
963
-        regs[1].address = 0x00008A00;
964
-        regs[1].size = 0x00001000;
965
-        OF_property_new(OF_env, ata, "reg",
966
-                        regs, 2 * sizeof(OF_regprop_t));
967
-#else
968
-        OF_property_new(OF_env, ata, "reg",
969
-                        regs, sizeof(OF_regprop_t));
970
-#endif
971
-        OF_prop_int_new(OF_env, ata, "interrupt-parent", pic_phandle);
972
-        regs[0].address = 0x00000013;
973
-        regs[0].size = 0x00000001;
974
-        regs[1].address = 0x0000000B;
975
-        regs[1].size = 0x00000000;
976
-        OF_property_new(OF_env, ata, "interrupts",
977
-                        regs, 2 * sizeof(OF_regprop_t));
978
-        ide_pci_pmac_register(base_address + 0x1f000, 0x00000000, ata);
979
-
980
-    }
981
-    {
982
-        OF_node_t *ata;
983
-        OF_regprop_t regs[2];
984
-        ata = OF_node_new(OF_env, mio, "ata-4", 0x20000);
985
-        if (ata == NULL) {
986
-            ERROR("Cannot create 'ata-4'\n");
987
-            goto out;
988
-        }
989
-        OF_prop_string_new(OF_env, ata, "device_type", "ata");
990
-#if 1
991
-        OF_prop_string_new(OF_env, ata, "compatible", "keylargo-ata");
992
-        OF_prop_string_new(OF_env, ata, "model", "ata-4");
993
-#else
994
-        OF_prop_string_new(OF_env, ata, "compatible", "cmd646-ata");
995
-        OF_prop_string_new(OF_env, ata, "model", "ata-4");
996
-#endif
997
-        OF_prop_int_new(OF_env, ata, "#address-cells", 1);
998
-        OF_prop_int_new(OF_env, ata, "#size-cells", 0);
999
-        regs[0].address = 0x00020000;
1000
-        regs[0].size = 0x00001000;
1001
-#if 0 // HACK: Don't set up DMA registers
1002
-        regs[1].address = 0x00008A00;
1003
-        regs[1].size = 0x00001000;
1004
-        OF_property_new(OF_env, ata, "reg",
1005
-                        regs, 2 * sizeof(OF_regprop_t));
1006
-#else
1007
-        OF_property_new(OF_env, ata, "reg",
1008
-                        regs, sizeof(OF_regprop_t));
1009
-#endif
1010
-        OF_prop_int_new(OF_env, ata, "interrupt-parent", pic_phandle);
1011
-        regs[0].address = 0x00000014;
1012
-        regs[0].size = 0x00000001;
1013
-        regs[1].address = 0x0000000B;
1014
-        regs[1].size = 0x00000000;
1015
-        OF_property_new(OF_env, ata, "interrupts",
1016
-                        regs, 2 * sizeof(OF_regprop_t));
1017
-        ide_pci_pmac_register(0x00000000, base_address + 0x20000, ata);
1018
-
1019
+    /* Keylargo IDE controller: need some work (DMA problem ?) */
1020
+    if (arch == ARCH_MAC99) {
1021
+        keylargo_ata(mio, base_address, 0x1f000, 0x13, 0xb, pic_phandle);
1022
+        keylargo_ata(mio, base_address, 0x20000, 0x14, 0xb, pic_phandle);
1023
     }
1024
+#if 0
1025
     /* Timer */
1026
     {
1027
         OF_node_t *tmr;
1028
@@ -2746,10 +2861,11 @@
1029
                         regs, sizeof(OF_regprop_t));
1030
         OF_node_put(OF_env, tmr);
1031
     }
1032
+#endif
1033
     /* VIA-PMU */
1034
     {
1035
         /* Controls adb, RTC and power-mgt (forget it !) */
1036
-        OF_node_t *via, *adb, *rtc;
1037
+        OF_node_t *via, *adb;
1038
         OF_regprop_t regs[1];
1039
 #if 0 // THIS IS A HACK AND IS COMPLETELY ABSURD !
1040
       // (but needed has Qemu doesn't emulate via-pmu).
1041
@@ -2773,14 +2889,21 @@
1042
         regs[0].size = 0x00002000;
1043
         OF_property_new(OF_env, via, "reg", regs, sizeof(OF_regprop_t));
1044
         OF_prop_int_new(OF_env, via, "interrupt-parent", pic_phandle);
1045
+        if (arch == ARCH_HEATHROW) {
1046
+            OF_prop_int_new(OF_env, via, "interrupts", 0x12);
1047
+        } else {
1048
         regs[0].address = 0x00000019;
1049
         regs[0].size = 0x00000001;
1050
         OF_property_new(OF_env, via, "interrupts",
1051
                         regs, sizeof(OF_regprop_t));
1052
+        }
1053
+        /* force usage of OF bus speeds */
1054
+        OF_prop_int_new(OF_env, via, "BusSpeedCorrect", 1);
1055
 #if 0
1056
         OF_prop_int_new(OF_env, via, "pmu-version", 0x00D0740C);
1057
 #endif
1058
-#if 1
1059
+        {
1060
+            OF_node_t *kbd, *mouse;
1061
         /* ADB pseudo-device */
1062
         adb = OF_node_new(OF_env, via, "adb", OF_ADDRESS_NONE);
1063
         if (adb == NULL) {
1064
@@ -2797,9 +2920,26 @@
1065
         OF_prop_int_new(OF_env, adb, "#size-cells", 0);
1066
         OF_pack_get_path(OF_env, tmp, 512, adb);
1067
         OF_prop_string_new(OF_env, als, "adb", tmp);
1068
-        /* XXX: add "keyboard@2" and "mouse@3" */
1069
-        OF_node_put(OF_env, adb);
1070
-#endif
1071
+
1072
+            kbd = OF_node_new(OF_env, adb, "keyboard", 2);
1073
+            if (kbd == NULL) {
1074
+                ERROR("Cannot create 'kbd'\n");
1075
+                goto out;
1076
+            }
1077
+            OF_prop_string_new(OF_env, kbd, "device_type", "keyboard");
1078
+            OF_prop_int_new(OF_env, kbd, "reg", 2);
1079
+
1080
+            mouse = OF_node_new(OF_env, adb, "mouse", 3);
1081
+            if (mouse == NULL) {
1082
+                ERROR("Cannot create 'mouse'\n");
1083
+                goto out;
1084
+            }
1085
+            OF_prop_string_new(OF_env, mouse, "device_type", "mouse");
1086
+            OF_prop_int_new(OF_env, mouse, "reg", 3);
1087
+            OF_prop_int_new(OF_env, mouse, "#buttons", 3);
1088
+        }
1089
+        {
1090
+            OF_node_t *rtc;
1091
         
1092
         rtc = OF_node_new(OF_env, via, "rtc", OF_ADDRESS_NONE);
1093
         if (rtc == NULL) {
1094
@@ -2813,14 +2953,55 @@
1095
         OF_prop_string_new(OF_env, rtc, "compatible", "rtc");
1096
 #endif
1097
         OF_node_put(OF_env, rtc);
1098
-        OF_node_put(OF_env, via);
1099
     }
1100
+        //        OF_node_put(OF_env, via);
1101
+    }
1102
+    {
1103
+        OF_node_t *pmgt;
1104
+        pmgt = OF_node_new(OF_env, mio, "power-mgt", OF_ADDRESS_NONE);
1105
+        OF_prop_string_new(OF_env, pmgt, "device_type", "power-mgt");
1106
+        OF_prop_string_new(OF_env, pmgt, "compatible", "cuda");
1107
+        OF_prop_string_new(OF_env, pmgt, "mgt-kind", "min-consumption-pwm-led");
1108
+        OF_node_put(OF_env, pmgt);
1109
+    }
1110
+
1111
  out:
1112
     //    OF_node_put(OF_env, mio);
1113
     OF_node_put(OF_env, chs);
1114
     OF_node_put(OF_env, als);
1115
 }
1116
 
1117
+void OF_finalize_pci_ide (void *dev, 
1118
+                          uint32_t io_base0, uint32_t io_base1,
1119
+                          uint32_t io_base2, uint32_t io_base3)
1120
+{
1121
+    OF_env_t *OF_env = OF_env_main;
1122
+    OF_node_t *pci_ata = dev;
1123
+    OF_node_t *ata, *atas[2];
1124
+    int i;
1125
+
1126
+    OF_prop_int_new(OF_env, pci_ata, "#address-cells", 1);
1127
+    OF_prop_int_new(OF_env, pci_ata, "#size-cells", 0);
1128
+
1129
+    /* XXX: Darwin handles only one device */
1130
+    for(i = 0; i < 1; i++) {
1131
+        ata = OF_node_new(OF_env, pci_ata, "ata-4", i);
1132
+        if (ata == NULL) {
1133
+            ERROR("Cannot create 'ata-4'\n");
1134
+            return;
1135
+        }
1136
+        OF_prop_string_new(OF_env, ata, "device_type", "ata");
1137
+        OF_prop_string_new(OF_env, ata, "compatible", "cmd646-ata");
1138
+        OF_prop_string_new(OF_env, ata, "model", "ata-4");
1139
+        OF_prop_int_new(OF_env, ata, "#address-cells", 1);
1140
+        OF_prop_int_new(OF_env, ata, "#size-cells", 0);
1141
+        OF_prop_int_new(OF_env, ata, "reg", i);
1142
+        atas[i] = ata;
1143
+    }
1144
+    ide_pci_pc_register(io_base0, io_base1, io_base2, io_base3,
1145
+                        atas[0], atas[1]);
1146
+}
1147
+
1148
 /*****************************************************************************/
1149
 /* Fake package */
1150
 static void OF_method_fake (OF_env_t *OF_env)
1151
@@ -2862,11 +3043,11 @@
1152
     /* As we get a 1:1 mapping, do nothing */
1153
     ihandle = popd(OF_env);
1154
     args = (void *)popd(OF_env);
1155
-    address = popd(OF_env);
1156
-    virt = popd(OF_env);
1157
-    size = popd(OF_env);
1158
     popd(OF_env);
1159
-    OF_DPRINTF("Translate address %0x %0x %0x %0x\n", ihandle, address,
1160
+    size = popd(OF_env);
1161
+    virt = popd(OF_env);
1162
+    address = popd(OF_env);
1163
+    dprintf("map %0x %0x %0x %0x\n", ihandle, address,
1164
                virt, size);
1165
     pushd(OF_env, 0);
1166
 }
1167
@@ -3270,7 +3451,7 @@
1168
     OF_prop_string_new(OF_env, dsk, "device_type", "block");
1169
     OF_prop_string_new(OF_env, dsk, "category", type);
1170
     OF_prop_int_new(OF_env, dsk, "device_id", devnum);
1171
-    OF_prop_int_new(OF_env, dsk, "reg", 0);
1172
+    OF_prop_int_new(OF_env, dsk, "reg", devnum);
1173
     OF_method_new(OF_env, dsk, "open", &OF_blockdev_open);
1174
     OF_method_new(OF_env, dsk, "seek", &OF_blockdev_seek);
1175
     OF_method_new(OF_env, dsk, "read", &OF_blockdev_read);
1176
@@ -3432,7 +3613,8 @@
1177
 }
1178
 
1179
 void OF_vga_register (const unsigned char *name, unused uint32_t address,
1180
-                      int width, int height, int depth)
1181
+                      int width, int height, int depth,
1182
+                      unsigned long vga_bios_addr, unsigned long vga_bios_size)
1183
 {
1184
     OF_env_t *OF_env;
1185
     unsigned char tmp[OF_NAMELEN_MAX];
1186
@@ -3504,6 +3686,18 @@
1187
     OF_prop_string_new(OF_env, als, "display", tmp);
1188
     OF_node_put(OF_env, als);
1189
     /* XXX: may also need read-rectangle */
1190
+
1191
+    if (vga_bios_size >= 8) {
1192
+        const uint8_t *p;
1193
+        int size;
1194
+        /* check the QEMU VGA BIOS header */
1195
+        p = (const uint8_t *)vga_bios_addr;
1196
+        if (p[0] == 'N' && p[1] == 'D' && p[2] == 'R' && p[3] == 'V') {
1197
+            size = *(uint32_t *)(p + 4);
1198
+            OF_property_new(OF_env, disp, "driver,AAPL,MacOS,PowerPC", 
1199
+                            p + 8, size);
1200
+        }
1201
+    }
1202
  out:
1203
     OF_node_put(OF_env, disp);
1204
 }
1205
@@ -4451,7 +4645,10 @@
1206
         break;
1207
     case 0x233441d3: /* MacOS X 10.2 and OpenDarwin 1.41 */
1208
         /* Create "memory-map" pseudo device */
1209
-        popd(OF_env);
1210
+        {
1211
+            OF_node_t *map;
1212
+            uint32_t phandle;
1213
+
1214
         /* Find "/packages" */
1215
         chs = OF_pack_find_by_name(OF_env, OF_node_root, "/chosen");
1216
         if (chs == NULL) {
1217
@@ -4459,10 +4656,6 @@
1218
             ERROR("Cannot get '/chosen'\n");
1219
             break;
1220
         }
1221
-        {
1222
-#if 1
1223
-            OF_node_t *map;
1224
-            uint32_t phandle;
1225
             map = OF_node_new(OF_env, chs, "memory-map", OF_ADDRESS_NONE);
1226
             if (map == NULL) {
1227
                 pushd(OF_env, -1);
1228
@@ -4473,11 +4666,8 @@
1229
             OF_node_put(OF_env, map);
1230
             OF_node_put(OF_env, chs);
1231
             pushd(OF_env, phandle);
1232
-        }
1233
-#else
1234
-        pushd(OF_env, 0);
1235
-#endif
1236
         pushd(OF_env, 0);
1237
+        }
1238
         break;
1239
     case 0x32a2d18e: /* MacOS X 10.2 and OpenDarwin 6.02 */
1240
         /* Return screen ihandle */
1241
@@ -4540,9 +4730,10 @@
1242
     case 0x4ad41f2d:
1243
         /* Yaboot: wait 10 ms: sure ! */
1244
         break;
1245
+
1246
     default:
1247
         /* ERROR */
1248
-        printf("Script:\n%s\n", FString);
1249
+        printf("Script: len=%d\n%s\n", (int)strlen(FString), FString);
1250
         printf("Call %0x NOT IMPLEMENTED !\n", crc);
1251
         bug();
1252
         break;
1253
diff -wruN --exclude '*~' --exclude '*.o' --exclude '*.bin' --exclude '*.out' --exclude mkdiff OpenHackWare-release-0.4.org/src/pci.c OpenHackWare-release-0.4/src/pci.c
1254
--- OpenHackWare-release-0.4.org/src/pci.c        2005-03-31 09:23:33.000000000 +0200
1255
+++ OpenHackWare-release-0.4/src/pci.c        2005-07-03 15:52:16.000000000 +0200
1256
@@ -99,8 +99,8 @@
1257
     uint16_t min_grant;
1258
     uint16_t max_latency;
1259
     uint8_t  irq_line;
1260
-    uint32_t regions[6];
1261
-    uint32_t sizes[6];
1262
+    uint32_t regions[7]; /* the region 6 is the PCI ROM */
1263
+    uint32_t sizes[7];
1264
     pci_device_t *next;
1265
 };
1266
 
1267
@@ -158,6 +158,7 @@
1268
 
1269
 /* IRQ numbers assigned to PCI IRQs */
1270
 static uint8_t prep_pci_irqs[4] = { 9, 11, 9, 11 };
1271
+static uint8_t heathrow_pci_irqs[4] = { 0x15, 0x16, 0x17, 0x18 };
1272
 static uint8_t pmac_pci_irqs[4] = { 8, 9, 10, 11 };
1273
 
1274
 /* PREP PCI host */
1275
@@ -399,6 +400,79 @@
1276
     &uninorth_config_readl, &uninorth_config_writel,
1277
 };
1278
 
1279
+/* Grackle PCI host */
1280
+
1281
+static uint32_t grackle_cfg_address (pci_bridge_t *bridge,
1282
+                                     uint8_t bus, uint8_t devfn,
1283
+                                     uint8_t offset)
1284
+{
1285
+    uint32_t addr;
1286
+    addr = 0x80000000 | (bus << 16) | (devfn << 8) | (offset & 0xfc);
1287
+    stswap32((uint32_t *)bridge->cfg_addr, addr);
1288
+    return bridge->cfg_data + (offset & 3);
1289
+}
1290
+
1291
+static uint8_t grackle_config_readb (pci_bridge_t *bridge,
1292
+                                      uint8_t bus, uint8_t devfn,
1293
+                                      uint8_t offset)
1294
+{
1295
+    uint32_t addr;
1296
+    addr = grackle_cfg_address(bridge, bus, devfn, offset);
1297
+    return *((uint8_t *)addr);
1298
+}
1299
+
1300
+static void grackle_config_writeb (pci_bridge_t *bridge,
1301
+                                    uint8_t bus, uint8_t devfn,
1302
+                                    uint8_t offset, uint8_t val)
1303
+{
1304
+    uint32_t addr;
1305
+    addr = grackle_cfg_address(bridge, bus, devfn, offset);
1306
+    *((uint8_t *)addr) = val;
1307
+}
1308
+
1309
+static uint16_t grackle_config_readw (pci_bridge_t *bridge,
1310
+                                       uint8_t bus, uint8_t devfn,
1311
+                                       uint8_t offset)
1312
+{
1313
+    uint32_t addr;
1314
+    addr = grackle_cfg_address(bridge, bus, devfn, offset);
1315
+    return ldswap16((uint16_t *)addr);
1316
+}
1317
+
1318
+static void grackle_config_writew (pci_bridge_t *bridge,
1319
+                                    uint8_t bus, uint8_t devfn,
1320
+                                    uint8_t offset, uint16_t val)
1321
+{
1322
+    uint32_t addr;
1323
+    addr = grackle_cfg_address(bridge, bus, devfn, offset);
1324
+    stswap16((uint16_t *)addr, val);
1325
+}
1326
+
1327
+static uint32_t grackle_config_readl (pci_bridge_t *bridge,
1328
+                                       uint8_t bus, uint8_t devfn,
1329
+                                       uint8_t offset)
1330
+{
1331
+    uint32_t addr;
1332
+    addr = grackle_cfg_address(bridge, bus, devfn, offset);
1333
+    return ldswap32((uint32_t *)addr);
1334
+}
1335
+
1336
+static void grackle_config_writel (pci_bridge_t *bridge,
1337
+                                    uint8_t bus, uint8_t devfn,
1338
+                                    uint8_t offset, uint32_t val)
1339
+{
1340
+    uint32_t addr;
1341
+
1342
+    addr = grackle_cfg_address(bridge, bus, devfn, offset);
1343
+    stswap32((uint32_t *)addr, val);
1344
+}
1345
+
1346
+static pci_ops_t grackle_pci_ops = {
1347
+    &grackle_config_readb, &grackle_config_writeb,
1348
+    &grackle_config_readw, &grackle_config_writew,
1349
+    &grackle_config_readl, &grackle_config_writel,
1350
+};
1351
+
1352
 static inline uint8_t pci_config_readb (pci_bridge_t *bridge,
1353
                                         uint8_t bus, uint8_t devfn,
1354
                                         uint8_t offset)
1355
@@ -466,12 +540,22 @@
1356
     },
1357
 };
1358
 
1359
+static int ide_config_cb2 (pci_device_t *device)
1360
+{
1361
+    OF_finalize_pci_ide(device->common.OF_private,
1362
+                        device->regions[0] & ~0x0000000F,
1363
+                        device->regions[1] & ~0x0000000F,
1364
+                        device->regions[2] & ~0x0000000F,
1365
+                        device->regions[3] & ~0x0000000F);
1366
+    return 0;
1367
+}
1368
+
1369
 static pci_dev_t ide_devices[] = {
1370
     {
1371
-        0x8086, 0x0100,
1372
-        NULL, "Qemu IDE", "Qemu IDE",    "ide",
1373
+        0x1095, 0x0646, /* CMD646 IDE controller */
1374
+        "pci-ide", "pci-ata", NULL, NULL,
1375
         0, 0, 0,
1376
-        NULL, NULL,
1377
+        ide_config_cb2, NULL,
1378
     },
1379
     {
1380
         0xFFFF, 0xFFFF,
1381
@@ -481,7 +565,9 @@
1382
     },
1383
 };
1384
 
1385
-static int ide_config_cb (pci_device_t *device)
1386
+#if 0
1387
+/* should base it on PCI ID, not on arch */
1388
+static int ide_config_cb (unused pci_device_t *device)
1389
 {
1390
     printf("Register IDE controller\n");
1391
     switch (arch) {
1392
@@ -491,14 +577,8 @@
1393
                               device->common.OF_private);
1394
         break;
1395
     default:
1396
-        ide_pci_pc_register(device->regions[0] & ~0x0000000F,
1397
-                            device->regions[1] & ~0x0000000F,
1398
-                            device->regions[2] & ~0x0000000F,
1399
-                            device->regions[3] & ~0x0000000F,
1400
-                            device->common.OF_private);
1401
         break;
1402
     }
1403
-
1404
     return 0;
1405
 }
1406
 
1407
@@ -512,16 +592,12 @@
1408
                               device->common.OF_private);
1409
         break;
1410
     default:
1411
-        ide_pci_pc_register(device->regions[0] & ~0x0000000F,
1412
-                            device->regions[1] & ~0x0000000F,
1413
-                            device->regions[2] & ~0x0000000F,
1414
-                            device->regions[3] & ~0x0000000F,
1415
-                            device->common.OF_private);
1416
         break;
1417
     }
1418
 
1419
     return 0;
1420
 }
1421
+#endif
1422
 
1423
 static pci_subclass_t mass_subclass[] = {
1424
     {
1425
@@ -530,7 +606,7 @@
1426
     },
1427
     {
1428
         0x01, "IDE controller",             "ide", ide_devices, NULL,
1429
-        &ide_config_cb, NULL,
1430
+        NULL, NULL,
1431
     },
1432
     {
1433
         0x02, "Floppy disk controller",     NULL,  NULL, NULL,
1434
@@ -546,7 +622,7 @@
1435
     },
1436
     {
1437
         0x05, "ATA controller",             "ata", NULL, NULL,
1438
-        &ata_config_cb, NULL,
1439
+        NULL, NULL,
1440
     },
1441
     {
1442
         0x80, "misc mass-storage controller", NULL, NULL, NULL,
1443
@@ -646,7 +722,9 @@
1444
         /* VGA 640x480x16 */
1445
         OF_vga_register(device->common.device->name,
1446
                         device->regions[0] & ~0x0000000F,
1447
-                        vga_width, vga_height, vga_depth);
1448
+                        vga_width, vga_height, vga_depth,
1449
+                        device->regions[6] & ~0x0000000F,
1450
+                        device->sizes[6]);
1451
     }
1452
     vga_console_register();
1453
 
1454
@@ -750,6 +828,13 @@
1455
     NULL, &PREP_pci_ops,
1456
 };
1457
 
1458
+pci_dev_t grackle_fake_bridge = {
1459
+    0xFFFF, 0xFFFF,
1460
+    "pci", "pci-bridge", "DEC,21154", "DEC,21154.pci-bridge",
1461
+    -1, -1, -1,
1462
+    NULL, &grackle_pci_ops,
1463
+};
1464
+
1465
 static pci_dev_t hbrg_devices[] = {
1466
     {
1467
         0x106B, 0x0020, NULL,
1468
@@ -758,8 +843,8 @@
1469
         NULL, &uninorth_agp_fake_bridge,
1470
     },
1471
     {
1472
-        0x106B, 0x001F,
1473
-        NULL, "pci", "AAPL,UniNorth", "uni-north",
1474
+        0x106B, 0x001F, NULL, 
1475
+        "pci", "AAPL,UniNorth", "uni-north",
1476
         3, 2, 1,
1477
         NULL, &uninorth_fake_bridge,
1478
     },
1479
@@ -770,10 +855,10 @@
1480
         NULL, &uninorth_fake_bridge,
1481
     },
1482
     {
1483
-        0x1011, 0x0026, NULL,
1484
-        "pci-bridge", NULL, NULL,
1485
+        0x1057, 0x0002, "pci",
1486
+        "pci", "MOT,MPC106", "grackle",
1487
         3, 2, 1,
1488
-        NULL, &PREP_pci_ops,
1489
+        NULL, &grackle_fake_bridge,
1490
     },
1491
     {
1492
         0x1057, 0x4801, NULL,
1493
@@ -1446,8 +1531,10 @@
1494
     /* Apple Mac-io controller */
1495
     { 
1496
         0x106B, 0x0022,
1497
-        "mac-io", "mac-io", "AAPL,Keylargo", "Keylargo",
1498
-        1, 1, 2,
1499
+        /* model, compatible and #interrupt-cells fields are filled in
1500
+           of.c */
1501
+        "mac-io", "mac-io", NULL, NULL,
1502
+        1, 1, 0,
1503
         &macio_config_cb, NULL,
1504
     },
1505
     {
1506
@@ -1599,7 +1686,7 @@
1507
                                       uint8_t min_grant, uint8_t max_latency,
1508
                                       int irq_line)
1509
 {
1510
-    uint32_t cmd;
1511
+    uint32_t cmd, addr;
1512
     int i;
1513
 
1514
     device->min_grant = min_grant;
1515
@@ -1611,22 +1698,28 @@
1516
         printf("MAP PCI device %d:%d to IRQ %d\n",
1517
                device->bus, device->devfn, irq_line);
1518
     }
1519
-    for (i = 0; i < 6; i++) {
1520
+    for (i = 0; i < 7; i++) {
1521
         if ((device->regions[i] & ~0xF) != 0x00000000 &&
1522
             (device->regions[i] & ~0xF) != 0xFFFFFFF0) {
1523
             printf("Map PCI device %d:%d %d to %0x %0x (%s)\n",
1524
                    device->bus, device->devfn, i,
1525
                    device->regions[i], device->sizes[i],
1526
-                   device->regions[i] & 0x00000001 ? "I/O" : "memory");
1527
+                   (device->regions[i] & 0x00000001) && i != 6 ? "I/O" : 
1528
+                    "memory");
1529
+            if (i != 6) {
1530
             cmd = pci_config_readl(bridge, device->bus, device->devfn, 0x04);
1531
             if (device->regions[i] & 0x00000001)
1532
                 cmd |= 0x00000001;
1533
             else
1534
                 cmd |= 0x00000002;
1535
             pci_config_writel(bridge, device->bus, device->devfn, 0x04, cmd);
1536
+            }
1537
+            if (i == 6)
1538
+                addr = 0x30; /* PCI ROM */
1539
+            else
1540
+                addr = 0x10 + (i * sizeof(uint32_t));
1541
             pci_config_writel(bridge, device->bus, device->devfn,
1542
-                              0x10 + (i * sizeof(uint32_t)),
1543
-                              device->regions[i]);
1544
+                              addr, device->regions[i]);
1545
         }
1546
     }
1547
 }
1548
@@ -1900,7 +1993,7 @@
1549
         goto out;
1550
     }
1551
     ret = (pci_u_t *)newd;
1552
-    max_areas = 6;
1553
+    max_areas = 7;
1554
     /* register PCI device in OF tree */
1555
     if (bridge->dev.common.type == PCI_FAKE_BRIDGE) {
1556
         newd->common.OF_private =
1557
@@ -1927,6 +2020,9 @@
1558
             /* Handle 64 bits memory mapping */
1559
             continue;
1560
         }
1561
+        if (i == 6)
1562
+            addr = 0x30; /* PCI ROM */
1563
+        else
1564
         addr = 0x10 + (i * sizeof(uint32_t));
1565
         /* Get region size
1566
          * Note: we assume it's always a power of 2
1567
@@ -1935,7 +2031,7 @@
1568
         smask = pci_config_readl(bridge, bus, devfn, addr);
1569
         if (smask == 0x00000000 || smask == 0xFFFFFFFF)
1570
             continue;
1571
-        if (smask & 0x00000001) {
1572
+        if ((smask & 0x00000001) != 0 && i != 6) {
1573
             /* I/O space */
1574
             base = io_base;
1575
             /* Align to a minimum of 256 bytes (arbitrary) */
1576
@@ -1947,6 +2043,8 @@
1577
             /* Align to a minimum of 64 kB (arbitrary) */
1578
             min_align = 1 << 16;
1579
             amask = 0x0000000F;
1580
+            if (i == 6)
1581
+                smask |= 1; /* PCI ROM enable */
1582
         }
1583
         omask = smask & amask;
1584
         smask &= ~amask;
1585
@@ -1980,7 +2078,10 @@
1586
     if (irq_pin > 0) {
1587
         /* assign the IRQ */
1588
         irq_pin = ((devfn >> 3) + irq_pin - 1) & 3;
1589
-        if (arch == ARCH_PREP) {
1590
+        /* XXX: should base it on the PCI bridge type, not the arch */
1591
+        switch(arch) {
1592
+        case ARCH_PREP:
1593
+            {
1594
             int elcr_port, val;
1595
             irq_line = prep_pci_irqs[irq_pin];
1596
             /* set the IRQ to level-sensitive */
1597
@@ -1988,14 +2089,22 @@
1598
             val = inb(elcr_port);
1599
             val |= 1 << (irq_line & 7);
1600
             outb(elcr_port, val);
1601
-        } else {
1602
+            }
1603
+            break;
1604
+        case ARCH_MAC99:
1605
             irq_line = pmac_pci_irqs[irq_pin];
1606
+            break;
1607
+        case ARCH_HEATHROW:
1608
+            irq_line = heathrow_pci_irqs[irq_pin];
1609
+            break;
1610
+        default:
1611
+            break;
1612
         }
1613
     }
1614
  update_device:
1615
     pci_update_device(bridge, newd, min_grant, max_latency, irq_line);
1616
     OF_finalize_pci_device(newd->common.OF_private, bus, devfn,
1617
-                           newd->regions, newd->sizes);
1618
+                           newd->regions, newd->sizes, irq_line);
1619
     /* Call special inits if needed */
1620
     if (dev->config_cb != NULL)
1621
         (*dev->config_cb)(newd);
1622
@@ -2049,6 +2158,32 @@
1623
     case ARCH_CHRP:
1624
         /* TODO */
1625
         break;
1626
+    case ARCH_HEATHROW:
1627
+        dev = pci_find_device(0x06, 0x00, 0xFF, checkv, checkp);
1628
+        if (dev == NULL)
1629
+            return -1;
1630
+        fake_host = pci_add_host(hostp, dev,
1631
+                                 (0x06 << 24) | (0x00 << 16) | (0xFF << 8));
1632
+        if (fake_host == NULL)
1633
+            return -1;
1634
+        fake_host->dev.common.type = PCI_FAKE_HOST;
1635
+        dev = &grackle_fake_bridge;
1636
+        if (dev == NULL)
1637
+            goto free_fake_host;
1638
+        fake_bridge = pci_add_bridge(fake_host, 0, 0, dev,
1639
+                                     (0x06 << 24) | (0x04 << 16) | (0xFF << 8),
1640
+                                     cfg_base, cfg_len,
1641
+                                     cfg_base + 0x7ec00000,
1642
+                                     cfg_base + 0x7ee00000,
1643
+                                     mem_base, mem_len,
1644
+                                     io_base, io_len,
1645
+                                     rbase, rlen,
1646
+                                     0,
1647
+                                     &grackle_pci_ops);
1648
+        if (fake_bridge == NULL)
1649
+            goto free_fake_host;
1650
+        fake_bridge->dev.common.type = PCI_FAKE_BRIDGE;
1651
+        break;
1652
     case ARCH_MAC99:
1653
         dev = pci_find_device(0x06, 0x00, 0xFF, checkv, checkp);
1654
         if (dev == NULL)
1655
@@ -2167,6 +2302,30 @@
1656
     case ARCH_CHRP:
1657
         /* TODO */
1658
         break;
1659
+    case ARCH_HEATHROW:
1660
+        cfg_base = 0x80000000;
1661
+        cfg_len  = 0x7f000000;
1662
+        mem_base = 0x80000000;
1663
+        mem_len  = 0x01000000;
1664
+        io_base  = 0xfe000000;
1665
+        io_len   = 0x00800000;
1666
+#if 1
1667
+        rbase    = 0xfd000000;
1668
+        rlen     = 0x01000000;
1669
+#else
1670
+        rbase    = 0x00000000;
1671
+        rlen     = 0x01000000;
1672
+#endif
1673
+        if (pci_check_host(&pci_main, cfg_base, cfg_len,
1674
+                           mem_base, mem_len, io_base, io_len, rbase, rlen,
1675
+                           0x1057, 0x0002) == 0) {
1676
+            isa_io_base = io_base;
1677
+            busnum++;
1678
+        }
1679
+        for (curh = pci_main; curh->next != NULL; curh = curh->next)
1680
+            continue;
1681
+        pci_check_devices(curh);
1682
+        break;
1683
     case ARCH_MAC99:
1684
         /* We are supposed to have 3 host bridges:
1685
          * - the uninorth AGP bridge at 0xF0000000