Statistics
| Branch: | Revision:

root / pc-bios / ohw.diff @ ee4660f9

History | View | Annotate | Download (65 kB)

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