Author: blueswirl Date: 2009-01-05 21:30:39 +0100 (Mon, 05 Jan 2009) New Revision: 356
Added: openbios-devel/drivers/macio.c openbios-devel/drivers/macio.h Modified: openbios-devel/arch/ppc/qemu/qemu.c openbios-devel/config/examples/cross-ppc_config.xml openbios-devel/config/examples/ppc_config.xml openbios-devel/drivers/build.xml openbios-devel/drivers/cuda.c openbios-devel/drivers/cuda.h openbios-devel/drivers/pci.c openbios-devel/include/openbios/drivers.h Log: Mac-io cleanup (Laurent Vivier)
Modified: openbios-devel/arch/ppc/qemu/qemu.c =================================================================== --- openbios-devel/arch/ppc/qemu/qemu.c 2009-01-05 20:20:45 UTC (rev 355) +++ openbios-devel/arch/ppc/qemu/qemu.c 2009-01-05 20:30:39 UTC (rev 356) @@ -27,9 +27,6 @@ #include "qemu/qemu.h" #include <stdarg.h>
-// FIXME -unsigned long virt_offset = 0; - //#define DUMP_NVRAM
void @@ -52,11 +49,6 @@ exit(0); }
- -/************************************************************************/ -/* print using OSI interface */ -/************************************************************************/ - static int do_indent;
int @@ -82,94 +74,3 @@ } return i; } - - -/************************************************************************/ -/* TTY iface */ -/************************************************************************/ - -/************************************************************************/ -/* briQ specific stuff */ -/************************************************************************/ - -#define IO_NVRAM_SIZE 0x00020000 -#define IO_NVRAM_OFFSET 0x00060000 - -static char *nvram; - -void macio_nvram_init(const char *path, uint32_t addr) -{ - phandle_t chosen, aliases; - phandle_t dnode; - int props[2]; - char buf[64]; - - nvram = (char*)addr + IO_NVRAM_OFFSET; - snprintf(buf, sizeof(buf), "%s/nvram", path); - nvram_init(buf); - dnode = find_dev(buf); - set_int_property(dnode, "#bytes", IO_NVRAM_SIZE >> 4); - set_property(dnode, "compatible", "nvram,flash", 12); - props[0] = __cpu_to_be32(IO_NVRAM_OFFSET); - props[1] = __cpu_to_be32(IO_NVRAM_SIZE); - set_property(dnode, "reg", (char *)&props, sizeof(props)); - set_property(dnode, "device_type", "nvram", 6); - - chosen = find_dev("/chosen"); - set_int_property(chosen, "nvram", dnode); - - aliases = find_dev("/aliases"); - set_property(aliases, "nvram", buf, strlen(buf) + 1); -} - -#ifdef DUMP_NVRAM -static void -dump_nvram(void) -{ - int i, j; - for (i = 0; i < 10; i++) - { - for (j = 0; j < 16; j++) - printk ("%02x ", nvram[(i*16+j)<<4]); - printk (" "); - for (j = 0; j < 16; j++) - if (isprint(nvram[(i*16+j)<<4])) - printk("%c", nvram[(i*16+j)<<4]); - else - printk("."); - printk ("\n"); - } -} -#endif - - -int -arch_nvram_size( void ) -{ - return IO_NVRAM_SIZE>>4; -} - -void -arch_nvram_put( char *buf ) -{ - int i; - for (i=0; i<IO_NVRAM_SIZE>>4; i++) - nvram[i<<4]=buf[i]; -#ifdef DUMP_NVRAM - printk("new nvram:\n"); - dump_nvram(); -#endif -} - -void -arch_nvram_get( char *buf ) -{ - int i; - for (i=0; i<IO_NVRAM_SIZE>>4; i++) - buf[i]=nvram[i<<4]; - -#ifdef DUMP_NVRAM - printk("current nvram:\n"); - dump_nvram(); -#endif -}
Modified: openbios-devel/config/examples/cross-ppc_config.xml =================================================================== --- openbios-devel/config/examples/cross-ppc_config.xml 2009-01-05 20:20:45 UTC (rev 355) +++ openbios-devel/config/examples/cross-ppc_config.xml 2009-01-05 20:30:39 UTC (rev 356) @@ -73,5 +73,6 @@ <option name="CONFIG_DEBUG_IDE" type="boolean" value="false"/> <option name="CONFIG_DRIVER_ADB" type="boolean" value="true"/> <option name="CONFIG_DRIVER_VGA" type="boolean" value="true"/> + <option name="CONFIG_DRIVER_MACIO" type="boolean" value="true"/>
</config>
Modified: openbios-devel/config/examples/ppc_config.xml =================================================================== --- openbios-devel/config/examples/ppc_config.xml 2009-01-05 20:20:45 UTC (rev 355) +++ openbios-devel/config/examples/ppc_config.xml 2009-01-05 20:30:39 UTC (rev 356) @@ -73,5 +73,6 @@ <option name="CONFIG_DEBUG_IDE" type="boolean" value="false"/> <option name="CONFIG_DRIVER_ADB" type="boolean" value="true"/> <option name="CONFIG_DRIVER_VGA" type="boolean" value="true"/> + <option name="CONFIG_DRIVER_MACIO" type="boolean" value="true"/>
</config>
Modified: openbios-devel/drivers/build.xml =================================================================== --- openbios-devel/drivers/build.xml 2009-01-05 20:20:45 UTC (rev 355) +++ openbios-devel/drivers/build.xml 2009-01-05 20:30:39 UTC (rev 356) @@ -18,6 +18,7 @@ <object source="vga_load_regs.c" condition="DRIVER_VGA"/> <object source="vga_set_mode.c" condition="DRIVER_VGA"/> <object source="vga_vbe.c" condition="DRIVER_VGA"/> + <object source="macio.c" condition="DRIVER_MACIO"/> </library>
<dictionary name="openbios" target="forth">
Modified: openbios-devel/drivers/cuda.c =================================================================== --- openbios-devel/drivers/cuda.c 2009-01-05 20:20:45 UTC (rev 355) +++ openbios-devel/drivers/cuda.c 2009-01-05 20:30:39 UTC (rev 356) @@ -3,7 +3,9 @@ #include "libc/byteorder.h" #include "libc/vsprintf.h"
+#include "macio.h" #include "cuda.h" + //#define DEBUG_CUDA #ifdef DEBUG_CUDA #define CUDA_DPRINTF(fmt, args...) \
Modified: openbios-devel/drivers/cuda.h =================================================================== --- openbios-devel/drivers/cuda.h 2009-01-05 20:20:45 UTC (rev 355) +++ openbios-devel/drivers/cuda.h 2009-01-05 20:30:39 UTC (rev 356) @@ -14,6 +14,4 @@ CHARDEV_LAST, };
-extern phandle_t pic_handle; - cuda_t *cuda_init (const char *path, uint32_t base);
Added: openbios-devel/drivers/macio.c =================================================================== --- openbios-devel/drivers/macio.c (rev 0) +++ openbios-devel/drivers/macio.c 2009-01-05 20:30:39 UTC (rev 356) @@ -0,0 +1,162 @@ +/* + * derived from mol/mol.c, + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "openbios/config.h" +#include "openbios/nvram.h" +#include "openbios/bindings.h" +#include "libc/byteorder.h" +#include "libc/vsprintf.h" + +#include "macio.h" +#include "cuda.h" + +#define IO_NVRAM_SIZE 0x00020000 +#define IO_NVRAM_OFFSET 0x00060000 + +static char *nvram; + +int +arch_nvram_size( void ) +{ + return IO_NVRAM_SIZE>>4; +} + +void macio_nvram_init(const char *path, uint32_t addr) +{ + phandle_t chosen, aliases; + phandle_t dnode; + int props[2]; + char buf[64]; + + nvram = (char*)addr + IO_NVRAM_OFFSET; + snprintf(buf, sizeof(buf), "%s/nvram", path); + nvram_init(buf); + dnode = find_dev(buf); + set_int_property(dnode, "#bytes", arch_nvram_size() ); + props[0] = __cpu_to_be32(IO_NVRAM_OFFSET); + props[1] = __cpu_to_be32(IO_NVRAM_SIZE); + set_property(dnode, "reg", (char *)&props, sizeof(props)); + set_property(dnode, "device_type", "nvram", 6); + + chosen = find_dev("/chosen"); + push_str(buf); + fword("open-dev"); + set_int_property(chosen, "nvram", POP()); + + aliases = find_dev("/aliases"); + set_property(aliases, "nvram", buf, strlen(buf) + 1); +} + +#ifdef DUMP_NVRAM +static void +dump_nvram(void) +{ + int i, j; + for (i = 0; i < 10; i++) + { + for (j = 0; j < 16; j++) + printk ("%02x ", nvram[(i*16+j)<<4]); + printk (" "); + for (j = 0; j < 16; j++) + if (isprint(nvram[(i*16+j)<<4])) + printk("%c", nvram[(i*16+j)<<4]); + else + printk("."); + printk ("\n"); + } +} +#endif + + +void +arch_nvram_put( char *buf ) +{ + int i; + for (i=0; i< arch_nvram_size() ; i++) + nvram[i<<4]=buf[i]; +#ifdef DUMP_NVRAM + printk("new nvram:\n"); + dump_nvram(); +#endif +} + +void +arch_nvram_get( char *buf ) +{ + int i; + for (i=0; i< arch_nvram_size(); i++) + buf[i]=nvram[i<<4]; + +#ifdef DUMP_NVRAM + printk("current nvram:\n"); + dump_nvram(); +#endif +} + +DECLARE_UNNAMED_NODE( ob_intctrl_node, INSTALL_OPEN, 2*sizeof(int) ); + +static void +ob_intctrl_open(int *idx) +{ + int ret=1; + RET ( -ret ); +} + +static void +ob_intctrl_close(int *idx) +{ +} + +static void +ob_intctrl_initialize(int *idx) +{ +} + +NODE_METHODS(ob_intctrl_node) = { + { NULL, ob_intctrl_initialize }, + { "open", ob_intctrl_open }, + { "close", ob_intctrl_close }, +}; + +phandle_t pic_handle; + +void +ob_macio_init(const char *path, uint32_t addr) +{ + char buf[64]; + phandle_t ph, chosen, aliases; + cell props[2]; + + aliases = find_dev("/aliases"); + set_property(aliases, "mac-io", path, strlen(path) + 1); + + snprintf(buf, sizeof(buf), "%s/interrupt-controller", path); + REGISTER_NAMED_NODE(ob_intctrl_node, buf); + + ph = find_dev(buf); + set_property(ph, "device_type", "interrupt-controller", 21); + set_property(ph, "compatible", "heathrow\0mac-risc", 18); + set_int_property(ph, "#interrupt-cells", 1); + props[0]= 0x00000010; + props[1]= 0x00000020; + set_property(ph, "reg", (char *)&props, 2 * sizeof(props)); + set_property(ph, "interrupt-controller", NULL, 0); + + chosen = find_dev("/chosen"); + push_str(buf); + fword("open-dev"); + ph = POP(); + set_int_property(chosen, "interrupt-controller", ph); + + pic_handle = ph; + + cuda_init(path, addr); + macio_nvram_init(path, addr); +}
Added: openbios-devel/drivers/macio.h =================================================================== --- openbios-devel/drivers/macio.h (rev 0) +++ openbios-devel/drivers/macio.h 2009-01-05 20:30:39 UTC (rev 356) @@ -0,0 +1,4 @@ +extern phandle_t pic_handle; + +void ob_macio_init(const char *path, uint32_t addr); +void macio_nvram_init(const char *path, uint32_t addr);
Modified: openbios-devel/drivers/pci.c =================================================================== --- openbios-devel/drivers/pci.c 2009-01-05 20:20:45 UTC (rev 355) +++ openbios-devel/drivers/pci.c 2009-01-05 20:30:39 UTC (rev 356) @@ -27,7 +27,10 @@ #include "timer.h" #include "pci.h" #include "pci_database.h" +#ifdef CONFIG_DRIVER_MACIO #include "cuda.h" +#include "macio.h" +#endif
#define set_bool_property(ph, name) set_property(ph, name, NULL, 0);
@@ -93,28 +96,10 @@ return 0; }
-phandle_t pic_handle; int macio_config_cb (const pci_config_t *config) { -#ifdef CONFIG_PPC - char buf[64]; - phandle_t ph; - cell props[2]; - - snprintf(buf, sizeof(buf), "%s/interrupt-controller", config->path); - REGISTER_NAMED_NODE(ob_pci_node, buf); - - ph = find_dev(buf); - set_property(ph, "device_type", "interrupt-controller", 21); - set_property(ph, "compatible", "heathrow\0mac-risc", 18); - set_int_property(ph, "#interrupt-cells", 1); - props[0]= 0x10; - props[1]= 0x20; - set_property(ph, "reg", (char *)&props, sizeof(props)); - pic_handle = ph; - - cuda_init(config->path, config->regions[0]); - macio_nvram_init(config->path, config->regions[0]); +#ifdef CONFIG_DRIVER_MACIO + ob_macio_init(config->path, config->regions[0] & ~0x0000000F); #endif return 0; }
Modified: openbios-devel/include/openbios/drivers.h =================================================================== --- openbios-devel/include/openbios/drivers.h 2009-01-05 20:20:45 UTC (rev 355) +++ openbios-devel/include/openbios/drivers.h 2009-01-05 20:30:39 UTC (rev 356) @@ -16,9 +16,6 @@ #ifdef CONFIG_DRIVER_PCI /* drivers/pci.c */ int ob_pci_init(void); - -/* arch/ppc/qemu/qemu.c */ -void macio_nvram_init(const char *path, uint32_t addr); #endif #ifdef CONFIG_DRIVER_SBUS /* drivers/sbus.c */