2 * derived from mol/mol.c,
3 * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
12 #include "arch/common/nvram.h"
13 #include "packages/nvram.h"
14 #include "libopenbios/bindings.h"
15 #include "libc/byteorder.h"
16 #include "libc/vsprintf.h"
18 #include "drivers/drivers.h"
22 #include "drivers/pci.h"
24 #define OW_IO_NVRAM_SIZE 0x00020000
25 #define OW_IO_NVRAM_OFFSET 0x00060000
26 #define OW_IO_NVRAM_SHIFT 4
28 #define NW_IO_NVRAM_SIZE 0x00004000
29 #define NW_IO_NVRAM_OFFSET 0xfff04000
30 #define NW_IO_NVRAM_SHIFT 1
32 #define IO_OPENPIC_SIZE 0x00040000
33 #define IO_OPENPIC_OFFSET 0x00040000
38 arch_nvram_size( void )
41 return OW_IO_NVRAM_SIZE
>> OW_IO_NVRAM_SHIFT
;
43 return NW_IO_NVRAM_SIZE
>> NW_IO_NVRAM_SHIFT
;
46 void macio_nvram_init(const char *path
, phys_addr_t addr
)
48 phandle_t chosen
, aliases
;
52 unsigned long nvram_size
, nvram_offset
;
55 nvram_offset
= OW_IO_NVRAM_OFFSET
;
56 nvram_size
= OW_IO_NVRAM_SIZE
;
58 nvram_offset
= NW_IO_NVRAM_OFFSET
;
59 nvram_size
= NW_IO_NVRAM_SIZE
;
65 fword("finish-device");
67 nvram
= (char*)addr
+ nvram_offset
;
68 snprintf(buf
, sizeof(buf
), "%s/nvram", path
);
70 dnode
= find_dev(buf
);
71 set_int_property(dnode
, "#bytes", arch_nvram_size() );
72 props
[0] = __cpu_to_be32(nvram_offset
);
73 props
[1] = __cpu_to_be32(nvram_size
);
74 set_property(dnode
, "reg", (char *)&props
, sizeof(props
));
75 set_property(dnode
, "device_type", "nvram", 6);
76 NEWWORLD(set_property(dnode
, "compatible", "nvram,flash", 12));
78 chosen
= find_dev("/chosen");
81 set_int_property(chosen
, "nvram", POP());
83 aliases
= find_dev("/aliases");
84 set_property(aliases
, "nvram", buf
, strlen(buf
) + 1);
92 for (i
= 0; i
< 10; i
++)
94 for (j
= 0; j
< 16; j
++)
95 printk ("%02x ", nvram
[(i
*16+j
)<<4]);
97 for (j
= 0; j
< 16; j
++)
98 if (isprint(nvram
[(i
*16+j
)<<4]))
99 printk("%c", nvram
[(i
*16+j
)<<4]);
109 arch_nvram_put( char *buf
)
112 unsigned int it_shift
;
115 it_shift
= OW_IO_NVRAM_SHIFT
;
117 it_shift
= NW_IO_NVRAM_SHIFT
;
119 for (i
=0; i
< arch_nvram_size() ; i
++)
120 nvram
[i
<< it_shift
] = buf
[i
];
122 printk("new nvram:\n");
128 arch_nvram_get( char *buf
)
131 unsigned int it_shift
;
134 it_shift
= OW_IO_NVRAM_SHIFT
;
136 it_shift
= NW_IO_NVRAM_SHIFT
;
138 for (i
=0; i
< arch_nvram_size(); i
++)
139 buf
[i
] = nvram
[i
<< it_shift
];
142 printk("current nvram:\n");
148 openpic_init(const char *path
, phys_addr_t addr
)
150 phandle_t target_node
;
156 fword("find-device");
158 push_str("interrupt-controller");
159 fword("device-name");
161 snprintf(buf
, sizeof(buf
), "%s/interrupt-controller", path
);
162 dnode
= find_dev(buf
);
163 set_property(dnode
, "device_type", "open-pic", 9);
164 set_property(dnode
, "compatible", "chrp,open-pic", 14);
165 set_property(dnode
, "built-in", "", 0);
166 props
[0] = __cpu_to_be32(IO_OPENPIC_OFFSET
);
167 props
[1] = __cpu_to_be32(IO_OPENPIC_SIZE
);
168 set_property(dnode
, "reg", (char *)&props
, sizeof(props
));
169 set_int_property(dnode
, "#interrupt-cells", 2);
170 set_int_property(dnode
, "#address-cells", 0);
171 set_property(dnode
, "interrupt-controller", "", 0);
172 set_int_property(dnode
, "clock-frequency", 4166666);
174 fword("finish-device");
180 /* patch in interrupt parent */
181 dnode
= find_dev(buf
);
183 target_node
= find_dev("/pci/mac-io");
184 set_int_property(target_node
, "interrupt-parent", dnode
);
186 target_node
= find_dev("/pci/mac-io/escc/ch-a");
187 set_int_property(target_node
, "interrupt-parent", dnode
);
189 target_node
= find_dev("/pci/mac-io/escc/ch-b");
190 set_int_property(target_node
, "interrupt-parent", dnode
);
192 target_node
= find_dev("/pci");
193 set_int_property(target_node
, "interrupt-parent", dnode
);
195 interrupt_map
= (u32
*)get_property(target_node
, "interrupt-map", &len
);
196 for (i
= 0; i
< 4; i
++) {
197 interrupt_map
[(i
* 7) + PCI_INT_MAP_PIC_HANDLE
] = (u32
)dnode
;
199 set_property(target_node
, "interrupt-map", (char *)interrupt_map
, len
);
203 DECLARE_NODE(ob_macio
, INSTALL_OPEN
, sizeof(int), "Tmac-io");
205 /* ( str len -- addr ) */
208 ob_macio_decode_unit(void *private)
212 const char *arg
= pop_fstr_copy();
214 addr
= strtol(arg
, NULL
, 16);
221 /* ( addr -- str len ) */
224 ob_macio_encode_unit(void *private)
230 snprintf(buf
, sizeof(buf
), "%x", addr
);
235 NODE_METHODS(ob_macio
) = {
236 { "decode-unit", ob_macio_decode_unit
},
237 { "encode-unit", ob_macio_encode_unit
},
241 ob_macio_heathrow_init(const char *path
, phys_addr_t addr
)
245 REGISTER_NODE(ob_macio
);
246 aliases
= find_dev("/aliases");
247 set_property(aliases
, "mac-io", path
, strlen(path
) + 1);
249 cuda_init(path
, addr
);
250 macio_nvram_init(path
, addr
);
251 escc_init(path
, addr
);
252 macio_ide_init(path
, addr
, 1);
256 ob_macio_keylargo_init(const char *path
, phys_addr_t addr
)
260 aliases
= find_dev("/aliases");
261 set_property(aliases
, "mac-io", path
, strlen(path
) + 1);
263 cuda_init(path
, addr
);
264 /* The NewWorld NVRAM is not located in the MacIO device */
265 macio_nvram_init("", 0);
266 escc_init(path
, addr
);
267 macio_ide_init(path
, addr
, 3);
268 openpic_init(path
, addr
);