This patchset started off with the aim of building the PCI-based machine device trees downwards from the root node to avoid switching either the active package and/or current instance at various points during the tree construction.
The basis for this was to try and remove all named nodes (those which are placed at a given path) and instead build the hierarchy in order by using new-device and finish-device as per the IEEE-1275 specification. This was realised by creating a new BIND_NODE_METHODS() macro which is similar to REGISTER_NAMED_NODE() except that it doesn't alter either the active package or the current instance, and then working through the device tree from the root converting all the devices for the PCI-based machines to use it.
Once this conversion has been completed for all devices beneath the PCI node, it becomes possible to remove both the REGISTER_NAMED_NODE() and REGISTER_NAMED_NODE_PHANDLE() macros to prevent future patches from accidentally changing the tree construction order.
Next the x86, PPC and SPARC64 device tree roots were altered to set the active package and current instance, allowing the remaining places where the PCI code alters either of them to be removed.
At this point instance variables were working correctly, and I noticed that there were several PCI devices which made use of C initialisation functions and/or properties for initial configuration. These can now be replaced with instance variables to keep everything simple and consistent.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
v3: - Rebase onto master - Fix up USB debug string for keyboard reported by Zoltan - Fix for creating devices that don't have an entry in the PCI database - Fix for MacOS 9 not initialising network reported by Howard
v2: - Fix up NVRAM initialisation so that -prom-env 'vga-ndrv?=false' works again
Mark Cave-Ayland (30): libopenbios: introduce BIND_NODE_METHODS() macro pc_kbd: convert to use BIND_NODE_METHODS() macro pc_serial: convert to use BIND_NODE_METHODS() macro floppy: convert to use BIND_NODE_METHODS() macro ide: convert to use BIND_NODE_METHODS() macro adb: convert to use BIND_NODE_METHODS() macro escc: convert to use BIND_NODE_METHODS() macro cuda: convert to use BIND_NODE_METHODS() macro macio: convert to use BIND_NODE_METHODS() macro pmu: convert to use BIND_NODE_METHODS() macro usbhid: convert to use BIND_NODE_METHODS() macro nvram: convert to use BIND_NODE_METHODS() macro lsi: don't change active package when setting device alias lsi: convert to use BIND_NODE_METHODS() macro virtio: convert to use BIND_NODE_METHODS() macro pci: convert to use BIND_NODE_METHODS() macro pci: remove ob_pci_initialize() and ob_pci_empty_node libopenbios: remove REGISTER_NAMED_NODE and REGISTER_NAMED_NODE_PHANDLE macros nvram: ensure that NVRAM configuration is separate from NVRAM node creation ppc: move New World uninorth and nvram device node creation to the root device ppc: set active package and current instance to root device node before probe SPARC64: set active package and current instance to root device node before probe x86: set active package and current instance to root device node before probe pci: remove explicit find-device from PCI devices pci: remove explicit setting of my-self from PCI devices pci: call set-args before configuring PCI device nodes pc_serial: remove separate init word pc_kbd: use instance value to initialise C instance parameter lsi: use instance value to hold sd_private_t pointer virtio: use instance value to initialise C instance parameter
arch/ppc/qemu/init.c | 18 +++- arch/sparc64/openbios.c | 6 ++ arch/x86/openbios.c | 9 +- drivers/adb_bus.c | 57 +++++++----- drivers/adb_kbd.c | 25 ++++-- drivers/adb_mouse.c | 31 ++++--- drivers/cuda.c | 158 ++++++++++++++++++++------------- drivers/escc.c | 113 ++++++++++++++--------- drivers/floppy.c | 68 +++++++------- drivers/ide.c | 123 +++++++++++++++---------- drivers/lsi.c | 65 +++++++------- drivers/macio.c | 118 ++++++++++++------------ drivers/macio.h | 1 - drivers/pc_kbd.c | 48 +++++----- drivers/pc_serial.c | 32 +++---- drivers/pci.c | 132 +++++++++++++-------------- drivers/pmu.c | 152 +++++++++++++++++++++---------- drivers/usbhid.c | 17 ++-- drivers/virtio.c | 56 +++--------- include/drivers/drivers.h | 2 + include/libopenbios/bindings.h | 19 ++-- include/packages/nvram.h | 4 +- libopenbios/bindings.c | 10 +++ packages/nvram.c | 35 ++++++-- 24 files changed, 755 insertions(+), 544 deletions(-)
This macro is designed to bind C functions into Forth words during creation of the device tree, but only into an existing node and without attempting to create any missing parent nodes.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- include/libopenbios/bindings.h | 8 ++++++++ libopenbios/bindings.c | 10 ++++++++++ 2 files changed, 18 insertions(+)
diff --git a/include/libopenbios/bindings.h b/include/libopenbios/bindings.h index 4ec9789..6360a4f 100644 --- a/include/libopenbios/bindings.h +++ b/include/libopenbios/bindings.h @@ -127,6 +127,11 @@ typedef struct { paths, 1, name##_m, sizeof(name##_m)/sizeof(method_t)); \ } while(0)
+#define BIND_NODE_METHODS(ph, name) do { \ + bind_node_methods(ph, name##_flags_, name##_size_, \ + name##_m, sizeof(name##_m)/sizeof(method_t)); \ +} while(0) + #define DECLARE_UNNAMED_NODE( name, flags, size ) \ static const int name##_flags_ = flags; \ static const int name##_size_ = size; @@ -144,6 +149,9 @@ static const method_t name##_m[] name##_m, sizeof(name##_m)/sizeof(method_t) ); \ } while(0)
+extern void +bind_node_methods(phandle_t ph, int flags, int size, const method_t *methods, int nmet); + extern void bind_node( int flags, int size, const char * const *paths, int npaths, const method_t *methods, int nmethods );
diff --git a/libopenbios/bindings.c b/libopenbios/bindings.c index 926944d..9b4308b 100644 --- a/libopenbios/bindings.c +++ b/libopenbios/bindings.c @@ -484,6 +484,16 @@ add_methods( int flags, int size, const method_t *methods, int nmet ) make_openable(0); }
+void +bind_node_methods(phandle_t ph, int flags, int size, const method_t *methods, int nmet) +{ + phandle_t save_ph = get_cur_dev(); + + activate_dev(ph); + add_methods(flags, size, methods, nmet); + activate_dev( save_ph ); +} + void bind_node( int flags, int size, const char * const *paths, int npaths, const method_t *methods, int nmet )
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/pc_kbd.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/drivers/pc_kbd.c b/drivers/pc_kbd.c index 3b74f8c..ed6b82c 100644 --- a/drivers/pc_kbd.c +++ b/drivers/pc_kbd.c @@ -194,7 +194,7 @@ pc_kbd_open(unsigned long *address) RET ( -1 ); }
-DECLARE_UNNAMED_NODE(pc_kbd, INSTALL_OPEN, sizeof(unsigned long)); +DECLARE_UNNAMED_NODE(pc_kbd, 0, sizeof(unsigned long));
NODE_METHODS(pc_kbd) = { { "open", pc_kbd_open }, @@ -219,7 +219,10 @@ ob_pc_kbd_init(const char *path, const char *kdev_name, const char *mdev_name,
push_str("8042"); fword("device-name"); - + + /* Make openable */ + fword("is-open"); + PUSH((base + offset) >> 32); fword("encode-int"); PUSH((base + offset) & 0xffffffff); @@ -259,15 +262,9 @@ ob_pc_kbd_init(const char *path, const char *kdev_name, const char *mdev_name,
push_str("interrupts"); fword("property"); - - fword("finish-device"); - - /* Keyboard */ - snprintf(nodebuff, sizeof(nodebuff), "%s/8042/%s", path, kdev_name); - REGISTER_NAMED_NODE(pc_kbd, nodebuff);
- push_str(nodebuff); - fword("find-device"); + /* Keyboard */ + fword("new-device");
push_str(kdev_name); fword("device-name"); @@ -289,7 +286,11 @@ ob_pc_kbd_init(const char *path, const char *kdev_name, const char *mdev_name, fword("encode-int"); push_str("address"); fword("property"); - + + BIND_NODE_METHODS(get_cur_dev(), pc_kbd); + fword("finish-device"); + + snprintf(nodebuff, sizeof(nodebuff), "%s/8042/%s", path, kdev_name); chosen = find_dev("/chosen"); push_str(nodebuff); fword("open-dev"); @@ -331,4 +332,6 @@ ob_pc_kbd_init(const char *path, const char *kdev_name, const char *mdev_name,
fword("finish-device"); } + + fword("finish-device"); }
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/pc_serial.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/pc_serial.c b/drivers/pc_serial.c index a638e1f..0d42689 100644 --- a/drivers/pc_serial.c +++ b/drivers/pc_serial.c @@ -151,7 +151,7 @@ pc_serial_init(unsigned long *address) *address = POP(); }
-DECLARE_UNNAMED_NODE(pc_serial, INSTALL_OPEN, sizeof(unsigned long)); +DECLARE_UNNAMED_NODE(pc_serial, 0, sizeof(unsigned long));
NODE_METHODS(pc_serial) = { { "init", pc_serial_init }, @@ -168,15 +168,13 @@ ob_pc_serial_init(const char *path, const char *dev_name, uint64_t base, phandle_t aliases; char nodebuff[128];
- snprintf(nodebuff, sizeof(nodebuff), "%s/%s", path, dev_name); - REGISTER_NAMED_NODE(pc_serial, nodebuff); - - push_str(nodebuff); + push_str(path); fword("find-device");
- PUSH(offset); - PUSH(find_package_method("init", get_cur_dev())); - fword("execute"); + fword("new-device"); + + push_str(dev_name); + fword("device-name");
push_str("serial"); fword("device-type"); @@ -203,6 +201,14 @@ ob_pc_serial_init(const char *path, const char *dev_name, uint64_t base, set_int_property(get_cur_dev(), "interrupts", 1); #endif
+ BIND_NODE_METHODS(get_cur_dev(), pc_serial); + + PUSH(offset); + feval("['] init execute"); + + fword("finish-device"); + aliases = find_dev("/aliases"); + snprintf(nodebuff, sizeof(nodebuff), "%s/%s", path, dev_name); set_property(aliases, "ttya", nodebuff, strlen(nodebuff) + 1); }
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/floppy.c | 71 +++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 31 deletions(-)
diff --git a/drivers/floppy.c b/drivers/floppy.c index 329987b..f34811a 100644 --- a/drivers/floppy.c +++ b/drivers/floppy.c @@ -9,7 +9,7 @@ #include "timer.h"
/* DECLARE data structures for the nodes. */ -DECLARE_UNNAMED_NODE( ob_floppy, INSTALL_OPEN, 2*sizeof(int) ); +DECLARE_UNNAMED_NODE( ob_floppy, 0, 2*sizeof(int) );
#ifdef CONFIG_DEBUG_FLOPPY #define printk_info printk @@ -1077,22 +1077,6 @@ static void floppy_reset(void) fdc_state.in_sync = 1; }
-static void -ob_floppy_initialize(const char *path) -{ - int props[3]; - phandle_t ph = find_dev(path); - - set_property(ph, "device_type", "block", sizeof("block")); - - // Set dummy reg properties - props[0] = __cpu_to_be32(0); props[1] = __cpu_to_be32(0); props[2] = __cpu_to_be32(0); - set_property(ph, "reg", (char *)&props, 3*sizeof(int)); - - fword("is-deblocker"); -} - - static void ob_floppy_open(int *idx) { @@ -1159,21 +1143,46 @@ NODE_METHODS(ob_floppy) = { int ob_floppy_init(const char *path, const char *dev_name, unsigned long io_base, unsigned long mmio_base) { - char nodebuff[128]; - phandle_t aliases; + char nodebuff[128]; + phandle_t aliases;
- snprintf(nodebuff, sizeof(nodebuff), "%s/%s", path, dev_name); - if (!mmio_base) { - REGISTER_NAMED_NODE(ob_floppy, nodebuff); - ob_floppy_initialize(nodebuff); - } else { - // Already in tree and mapped - REGISTER_NODE_METHODS(ob_floppy, nodebuff); - } - floppy_init(io_base, mmio_base); + push_str(path); + fword("find-device");
- aliases = find_dev("/aliases"); - set_property(aliases, "floppy", nodebuff, strlen(nodebuff) + 1); + fword("new-device");
- return 0; + push_str(dev_name); + fword("device-name"); + push_str("block"); + fword("device-type"); + + if (!mmio_base) { + BIND_NODE_METHODS(get_cur_dev(), ob_floppy); + + PUSH(0); + fword("encode-int"); + PUSH(0); + fword("encode-int"); + fword("encode+"); + PUSH(0); + fword("encode-int"); + fword("encode+"); + + push_str("reg"); + fword("property"); + + fword("is-deblocker"); + } else { + // Already in tree and mapped + BIND_NODE_METHODS(get_cur_dev(), ob_floppy); + } + floppy_init(io_base, mmio_base); + + fword("finish-device"); + + aliases = find_dev("/aliases"); + snprintf(nodebuff, sizeof(nodebuff), "%s/%s", path, dev_name); + set_property(aliases, "floppy", nodebuff, strlen(nodebuff) + 1); + + return 0; }
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/ide.c | 129 +++++++++++++++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 49 deletions(-)
diff --git a/drivers/ide.c b/drivers/ide.c index 519ad46..18a27c6 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -32,8 +32,8 @@ do { printk("IDE - %s: " fmt, __func__ , ##args); } while (0) #endif
/* DECLARE data structures for the nodes. */ -DECLARE_UNNAMED_NODE( ob_ide, INSTALL_OPEN, sizeof(struct ide_drive*) ); -DECLARE_UNNAMED_NODE( ob_ide_ctrl, INSTALL_OPEN, sizeof(int)); +DECLARE_UNNAMED_NODE( ob_ide, 0, sizeof(struct ide_drive*) ); +DECLARE_UNNAMED_NODE( ob_ide_ctrl, 0, sizeof(int));
/* * define to 2 for the standard 2 channels only @@ -1224,26 +1224,6 @@ ob_ide_block_size(int *idx) PUSH(drive->bs); }
-static void -ob_ide_initialize(int *idx) -{ - int props[3]; - phandle_t ph=get_cur_dev(); - - push_str("block"); - fword("device-type"); - - // Set dummy reg properties - - set_int_property(ph, "#address-cells", 1); - set_int_property(ph, "#size-cells", 0); - - props[0] = __cpu_to_be32(0); props[1] = __cpu_to_be32(0); props[2] = __cpu_to_be32(0); - set_property(ph, "reg", (char *)&props, 3*sizeof(int)); - - fword("is-deblocker"); -} - static void ob_ide_open(int *idx) { @@ -1318,7 +1298,6 @@ ob_ide_dma_sync(int *idx) }
NODE_METHODS(ob_ide) = { - { NULL, ob_ide_initialize }, { "open", ob_ide_open }, { "close", ob_ide_close }, { "read-blocks", ob_ide_read_blocks }, @@ -1332,26 +1311,25 @@ NODE_METHODS(ob_ide) = { };
static void -ob_ide_ctrl_initialize(int *idx) +ob_ide_ctrl_decodeunit(int *idx) { - phandle_t ph=get_cur_dev(); - - /* set device type */ - push_str(DEV_TYPE); - fword("device-type"); + fword("parse-hex"); +}
- set_int_property(ph, "#address-cells", 1); - set_int_property(ph, "#size-cells", 0); +static void +ob_ide_ctrl_open(int *idx) +{ + RET(-1); }
static void -ob_ide_ctrl_decodeunit(int *idx) +ob_ide_ctrl_close(int *idx) { - fword("parse-hex"); }
NODE_METHODS(ob_ide_ctrl) = { - { NULL, ob_ide_ctrl_initialize }, + { "open", ob_ide_ctrl_open }, + { "close", ob_ide_ctrl_close }, { "decode-unit", ob_ide_ctrl_decodeunit }, { "dma-alloc", ob_ide_dma_alloc }, { "dma-free", ob_ide_dma_free }, @@ -1414,6 +1392,9 @@ int ob_ide_init(const char *path, uint32_t io_port0, uint32_t ctl_port0, io_ports[1] = io_port1; ctl_ports[1] = ctl_port1;
+ push_str(path); + fword("find-device"); + for (i = 0; i < IDE_NUM_CHANNELS; i++, current_channel++) {
chan = malloc(sizeof(struct ide_channel)); @@ -1457,11 +1438,12 @@ int ob_ide_init(const char *path, uint32_t io_port0, uint32_t ctl_port0,
ob_ide_identify_drives(chan);
- snprintf(nodebuff, sizeof(nodebuff), "%s/" DEV_NAME, path); - REGISTER_NAMED_NODE_PHANDLE(ob_ide_ctrl, nodebuff, dnode); - + fword("new-device"); + dnode = get_cur_dev(); chan->ph = dnode;
+ BIND_NODE_METHODS(get_cur_dev(), ob_ide_ctrl); + #if !defined(CONFIG_PPC) && !defined(CONFIG_SPARC64) props[0]=14; props[1]=0; set_property(dnode, "interrupts", @@ -1473,6 +1455,15 @@ int ob_ide_init(const char *path, uint32_t io_port0, uint32_t ctl_port0, props[2] = 0; set_property(dnode, "reg", (char *)&props, 3*sizeof(props[0]));
+ set_int_property(dnode, "#address-cells", 1); + set_int_property(dnode, "#size-cells", 0); + + push_str(DEV_NAME); + fword("device-name"); + + push_str(DEV_TYPE); + fword("device-type"); + IDE_DPRINTF(DEV_NAME": [io ports 0x%x-0x%x,0x%x]\n", current_channel, chan->io_regs[0], chan->io_regs[0] + 7, chan->io_regs[8]); @@ -1500,20 +1491,34 @@ int ob_ide_init(const char *path, uint32_t io_port0, uint32_t ctl_port0, media = "disk"; break; } + IDE_DPRINTF("%s]: %s\n", media, drive->model); - snprintf(nodebuff, sizeof(nodebuff), "%s/%s", - get_path_from_ph(dnode), media); - REGISTER_NAMED_NODE_PHANDLE(ob_ide, nodebuff, dnode); + + fword("new-device"); + dnode = get_cur_dev(); set_int_property(dnode, "reg", j); + push_str(media); + fword("device-name");
- /* create aliases */ + push_str("block"); + fword("device-type"); + + BIND_NODE_METHODS(dnode, ob_ide); + fword("is-deblocker");
+ fword("finish-device"); + + /* create aliases */ + snprintf(nodebuff, sizeof(nodebuff), "%s", + get_path_from_ph(dnode)); set_ide_alias(nodebuff); if (drive->media == ide_media_cdrom) set_cd_alias(nodebuff); if (drive->media == ide_media_disk) set_hd_alias(nodebuff); } + + fword("finish-device"); }
return 0; @@ -1583,6 +1588,9 @@ int macio_ide_init(const char *path, uint32_t addr, int nb_channels) * Also see comments in pci.c:ob_pci_host_set_interrupt_map() */ current_channel = 3;
+ push_str(path); + fword("find-device"); + for (i = 0; i < nb_channels; i++) {
chan = malloc(sizeof(struct ide_channel)); @@ -1622,12 +1630,20 @@ int macio_ide_init(const char *path, uint32_t addr, int nb_channels)
ob_ide_identify_drives(chan);
- snprintf(nodebuff, sizeof(nodebuff), "%s/" DEV_NAME "-%d", path, - current_channel); - REGISTER_NAMED_NODE_PHANDLE(ob_ide_ctrl, nodebuff, dnode); - + fword("new-device"); + dnode = get_cur_dev(); chan->ph = dnode;
+ snprintf(nodebuff, sizeof(nodebuff), DEV_NAME "-%d", current_channel); + push_str(nodebuff); + fword("device-name"); + + push_str(DEV_TYPE); + fword("device-type"); + + set_int_property(dnode, "#address-cells", 1); + set_int_property(dnode, "#size-cells", 0); + set_property(dnode, "compatible", (is_oldworld() ? "heathrow-ata" : "keylargo-ata"), 13);
@@ -1695,6 +1711,8 @@ int macio_ide_init(const char *path, uint32_t addr, int nb_channels) IDE_DPRINTF(DEV_NAME": [io ports 0x%lx]\n", current_channel, chan->mmio);
+ BIND_NODE_METHODS(dnode, ob_ide_ctrl); + for (j = 0; j < 2; j++) { struct ide_drive *drive = &chan->drives[j]; const char *media = "UNKNOWN"; @@ -1719,19 +1737,32 @@ int macio_ide_init(const char *path, uint32_t addr, int nb_channels) break; } IDE_DPRINTF("%s]: %s\n", media, drive->model); - snprintf(nodebuff, sizeof(nodebuff), "%s/%s", - get_path_from_ph(dnode), media); - REGISTER_NAMED_NODE_PHANDLE(ob_ide, nodebuff, dnode); + + fword("new-device"); + dnode = get_cur_dev(); set_int_property(dnode, "reg", j); + push_str(media); + fword("device-name");
- /* create aliases */ + push_str("block"); + fword("device-type"); + + BIND_NODE_METHODS(dnode, ob_ide); + fword("is-deblocker"); + + fword("finish-device");
+ /* create aliases */ + snprintf(nodebuff, sizeof(nodebuff), "%s", + get_path_from_ph(dnode)); set_ide_alias(nodebuff); if (drive->media == ide_media_cdrom) set_cd_alias(nodebuff); if (drive->media == ide_media_disk) set_hd_alias(nodebuff); } + + fword("finish-device"); }
return 0;
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/adb_bus.c | 60 +++++++++++++++++++++++++++++---------------- drivers/adb_kbd.c | 28 ++++++++++++++------- drivers/adb_mouse.c | 34 +++++++++++++++++-------- 3 files changed, 82 insertions(+), 40 deletions(-)
diff --git a/drivers/adb_bus.c b/drivers/adb_bus.c index 88a3a2d..c505322 100644 --- a/drivers/adb_bus.c +++ b/drivers/adb_bus.c @@ -28,25 +28,7 @@ #include "adb_kbd.h" #include "adb_mouse.h"
-DECLARE_UNNAMED_NODE( adb, INSTALL_OPEN, sizeof(int)); - -static void -adb_initialize (int *idx) -{ - phandle_t ph=get_cur_dev(); - - push_str("adb"); - fword("device-type"); - - if (has_pmu()) { - set_property(ph, "compatible", "pmu-99", 7); - } else { - set_property(ph, "compatible", "adb", 4); - } - - set_int_property(ph, "#address-cells", 1); - set_int_property(ph, "#size-cells", 0); -} +DECLARE_UNNAMED_NODE( adb, 0, sizeof(int));
static void adb_open(int *idx) @@ -60,7 +42,6 @@ adb_close(int *idx) }
NODE_METHODS( adb ) = { - { NULL, adb_initialize }, { "open", adb_open }, { "close", adb_close }, }; @@ -95,8 +76,43 @@ int adb_bus_init (char *path, adb_bus_t *bus) int reloc = 0, next_free = 7; int keep;
+ push_str(path); + fword("find-device"); + + fword("new-device"); + + push_str("adb"); + fword("device-name"); + + push_str("adb"); + fword("device-type"); + + if (has_pmu()) { + push_str("pmu-99"); + fword("encode-string"); + push_str("compatible"); + fword("property"); + } else { + push_str("adb"); + fword("encode-string"); + push_str("compatible"); + fword("property"); + } + + PUSH(1); + fword("encode-int"); + push_str("#address-cells"); + fword("property"); + + PUSH(0); + fword("encode-int"); + push_str("#size-cells"); + fword("property"); + + BIND_NODE_METHODS(get_cur_dev(), adb); + snprintf(buf, sizeof(buf), "%s/adb", path); - REGISTER_NAMED_NODE( adb, buf); + /* Reset the bus */ // ADB_DPRINTF("\n"); adb_reset(bus); @@ -195,6 +211,8 @@ int adb_bus_init (char *path, adb_bus_t *bus) } }
+ fword("finish-device"); + return 0; }
diff --git a/drivers/adb_kbd.c b/drivers/adb_kbd.c index be6099a..df53fe0 100644 --- a/drivers/adb_kbd.c +++ b/drivers/adb_kbd.c @@ -28,7 +28,7 @@ #include "adb_bus.h" #include "adb_kbd.h"
-DECLARE_UNNAMED_NODE( keyboard, INSTALL_OPEN, sizeof(int)); +DECLARE_UNNAMED_NODE( keyboard, 0, sizeof(int));
static void keyboard_open(int *idx) @@ -523,8 +523,7 @@ static int adb_kbd_read (void *private) void *adb_kbd_new (char *path, void *private) { char buf[64]; - int props[1]; - phandle_t ph, aliases; + phandle_t aliases; adb_kbd_t *kbd; adb_dev_t *dev = private; kbd = (adb_kbd_t*)malloc(sizeof(adb_kbd_t)); @@ -553,16 +552,27 @@ void *adb_kbd_new (char *path, void *private) my_adb_dev = dev; }
- snprintf(buf, sizeof(buf), "%s/keyboard", path); - REGISTER_NAMED_NODE( keyboard, buf); + push_str(path); + fword("find-device");
- ph = find_dev(buf); + fword("new-device");
- set_property(ph, "device_type", "keyboard", 9); - props[0] = __cpu_to_be32(dev->addr); - set_property(ph, "reg", (char *)&props, sizeof(props)); + push_str("keyboard"); + fword("device-name"); + + push_str("keyboard"); + fword("device-type"); + + PUSH(dev->addr); + fword("encode-int"); + push_str("reg"); + fword("property"); + + BIND_NODE_METHODS(get_cur_dev(), keyboard); + fword("finish-device");
aliases = find_dev("/aliases"); + snprintf(buf, sizeof(buf), "%s/keyboard", path); set_property(aliases, "adb-keyboard", buf, strlen(buf) + 1);
return kbd; diff --git a/drivers/adb_mouse.c b/drivers/adb_mouse.c index b94a344..6ee512f 100644 --- a/drivers/adb_mouse.c +++ b/drivers/adb_mouse.c @@ -27,7 +27,7 @@ #include "adb_bus.h" #include "adb_mouse.h"
-DECLARE_UNNAMED_NODE( mouse, INSTALL_OPEN, sizeof(int)); +DECLARE_UNNAMED_NODE( mouse, 0, sizeof(int));
static void mouse_open(int *idx) @@ -48,20 +48,34 @@ NODE_METHODS( mouse ) = { void adb_mouse_new (char *path, void *private) { char buf[64]; - int props[1]; - phandle_t ph, aliases; + phandle_t aliases; adb_dev_t *dev = private;
- snprintf(buf, sizeof(buf), "%s/mouse", path); - REGISTER_NAMED_NODE( mouse, buf); + push_str(path); + fword("find-device");
- ph = find_dev(buf); + fword("new-device");
- set_property(ph, "device_type", "mouse", 6); - props[0] = __cpu_to_be32(dev->addr); - set_property(ph, "reg", (char *)&props, sizeof(props)); - set_int_property(ph, "#buttons", 3); + push_str("mouse"); + fword("device-name"); + + push_str("mouse"); + fword("device-type"); + + PUSH(dev->addr); + fword("encode-int"); + push_str("reg"); + fword("property"); + + PUSH(3); + fword("encode-int"); + push_str("#buttons"); + fword("property"); + + BIND_NODE_METHODS(get_cur_dev(), mouse); + fword("finish-device");
aliases = find_dev("/aliases"); + snprintf(buf, sizeof(buf), "%s/mouse", path); set_property(aliases, "adb-mouse", buf, strlen(buf) + 1); }
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/escc.c | 114 +++++++++++++++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 42 deletions(-)
diff --git a/drivers/escc.c b/drivers/escc.c index 4ea8308..199d571 100644 --- a/drivers/escc.c +++ b/drivers/escc.c @@ -131,7 +131,7 @@ void serial_cls(void)
/* ( addr len -- actual ) */ static void -escc_read(ucell *address) +escc_port_read(ucell *address) { char *addr; int len; @@ -152,7 +152,7 @@ escc_read(ucell *address)
/* ( addr len -- actual ) */ static void -escc_write(ucell *address) +escc_port_write(ucell *address) { unsigned char *addr; int i, len; @@ -167,14 +167,15 @@ escc_write(ucell *address) }
static void -escc_close(void) +escc_port_close(void) { }
+#ifdef CONFIG_DRIVER_ESCC_SUN static void -escc_open(ucell *address) +escc_port_open(ucell *address) { -#ifdef CONFIG_DRIVER_ESCC_SUN + int len; phandle_t ph; unsigned long *prop; @@ -193,19 +194,46 @@ escc_open(ucell *address) //printk("escc_open: address %lx, args %s\n", *address, args); free(args); } + + RET ( -1 ); +} + #else + +static void +escc_port_open(ucell *address) +{ *address = (unsigned long)escc_serial_dev; // XXX -#endif - RET ( -1 ); + RET(-1); }
-DECLARE_UNNAMED_NODE(escc, INSTALL_OPEN, sizeof(ucell)); +static void +escc_open(int *idx) +{ + RET(-1); +} + +static void +escc_close(int *idx) +{ +} + +DECLARE_UNNAMED_NODE(escc, 0, sizeof(int *));
NODE_METHODS(escc) = { - { "open", escc_open }, - { "close", escc_close }, - { "read", escc_read }, - { "write", escc_write }, + { "open", escc_open }, + { "close", escc_close }, +}; + +#endif + +DECLARE_UNNAMED_NODE(escc_port, 0, sizeof(ucell)); + +NODE_METHODS(escc_port) = { + { "open", escc_port_open }, + { "close", escc_port_close }, + { "read", escc_port_read }, + { "write", escc_port_write }, };
#ifdef CONFIG_DRIVER_ESCC_SUN @@ -305,11 +333,11 @@ escc_read_keyboard(void) } }
-DECLARE_UNNAMED_NODE(escc_keyboard, INSTALL_OPEN, sizeof(ucell)); +DECLARE_UNNAMED_NODE(escc_keyboard, 0, sizeof(ucell));
NODE_METHODS(escc_keyboard) = { - { "open", escc_open }, - { "close", escc_close }, + { "open", escc_port_open }, + { "close", escc_port_close }, { "read", escc_read_keyboard }, };
@@ -352,19 +380,20 @@ ob_zs_init(phys_addr_t base, uint64_t offset, int intr, int slave, int keyboard) push_str("port-b-ignore-cd"); fword("property");
+ if (keyboard) { + BIND_NODE_METHODS(get_cur_dev(), escc_keyboard); + } else { + BIND_NODE_METHODS(get_cur_dev(), escc_port); + } + fword("finish-device");
- snprintf(nodebuff, sizeof(nodebuff), "/obio/zs@0,%x", - (int)offset & 0xffffffff); + aliases = find_dev("/aliases"); if (keyboard) { - REGISTER_NODE_METHODS(escc_keyboard, nodebuff); - - aliases = find_dev("/aliases"); + snprintf(nodebuff, sizeof(nodebuff), "/obio/zs@0,%x", + (int)offset & 0xffffffff); set_property(aliases, "keyboard", nodebuff, strlen(nodebuff) + 1); } else { - REGISTER_NODE_METHODS(escc, nodebuff); - - aliases = find_dev("/aliases"); snprintf(nodebuff, sizeof(nodebuff), "/obio/zs@0,%x:a", (int)offset & 0xffffffff); set_property(aliases, "ttya", nodebuff, strlen(nodebuff) + 1); @@ -421,11 +450,16 @@ escc_add_channel(const char *path, const char *node, phys_addr_t addr,
/* add device */
- snprintf(buf, sizeof(buf), "%s/ch-%s", path, node); + push_str(path); + fword("find-device"); + + fword("new-device");
- REGISTER_NAMED_NODE(escc, buf); + snprintf(buf, sizeof(buf), "ch-%s", node); + push_str(buf); + fword("device-name");
- activate_device(buf); + BIND_NODE_METHODS(get_cur_dev(), escc_port);
/* add aliases */
@@ -440,7 +474,7 @@ escc_add_channel(const char *path, const char *node, phys_addr_t addr, } /* add properties */
- dnode = find_dev(buf); + dnode = get_cur_dev(); set_property(dnode, "device_type", "serial", strlen("serial") + 1);
@@ -484,7 +518,7 @@ escc_add_channel(const char *path, const char *node, phys_addr_t addr,
set_int_property(dnode, "slot-names", 0);
- device_end(); + fword("finish-device");
uart_init_line((unsigned char*)addr + offset + reg_offsets[legacy][index][0], CONFIG_SERIAL_SPEED); @@ -504,10 +538,7 @@ escc_init(const char *path, phys_addr_t addr) push_str("escc"); fword("device-name");
- snprintf(buf, sizeof(buf), "%s/escc", path); - - dnode = find_dev(buf); - + dnode = get_cur_dev(); set_int_property(dnode, "#address-cells", 1); props[0] = __cpu_to_be32(IO_ESCC_OFFSET); props[1] = __cpu_to_be32(IO_ESCC_SIZE); @@ -517,25 +548,22 @@ escc_init(const char *path, phys_addr_t addr) set_property(dnode, "compatible", "escc\0CHRP,es0", 14); set_property(dnode, "ranges", "", 0);
- fword("finish-device"); - + snprintf(buf, sizeof(buf), "%s/escc", path); escc_add_channel(buf, "a", addr, 2); escc_add_channel(buf, "b", addr, 3);
+ BIND_NODE_METHODS(dnode, escc); + fword("finish-device"); + escc_serial_dev = (unsigned char *)addr + IO_ESCC_OFFSET + (CONFIG_SERIAL_PORT ? 0 : 0x20);
- push_str(path); - fword("find-device"); fword("new-device");
push_str("escc-legacy"); fword("device-name");
- snprintf(buf, sizeof(buf), "%s/escc-legacy", path); - - dnode = find_dev(buf); - + dnode = get_cur_dev(); set_int_property(dnode, "#address-cells", 1); props[0] = __cpu_to_be32(IO_ESCC_LEGACY_OFFSET); props[1] = __cpu_to_be32(IO_ESCC_LEGACY_SIZE); @@ -545,9 +573,11 @@ escc_init(const char *path, phys_addr_t addr) set_property(dnode, "compatible", "chrp,es1", 9); set_property(dnode, "ranges", "", 0);
- fword("finish-device"); - + snprintf(buf, sizeof(buf), "%s/escc-legacy", path); escc_add_channel(buf, "a", addr, 4); escc_add_channel(buf, "b", addr, 5); + + BIND_NODE_METHODS(dnode, escc); + fword("finish-device"); } #endif
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/cuda.c | 161 ++++++++++++++++++++++++++++++------------------- 1 file changed, 100 insertions(+), 61 deletions(-)
diff --git a/drivers/cuda.c b/drivers/cuda.c index d079d1e..d88edf8 100644 --- a/drivers/cuda.c +++ b/drivers/cuda.c @@ -170,7 +170,7 @@ static int cuda_adb_req (void *host, const uint8_t *snd_buf, int len, }
-DECLARE_UNNAMED_NODE(ob_cuda, INSTALL_OPEN, sizeof(int)); +DECLARE_UNNAMED_NODE(ob_cuda, 0, sizeof(int));
static cuda_t *main_cuda;
@@ -192,43 +192,6 @@ ppc32_poweroff(void) cuda_request(main_cuda, CUDA_PACKET, cmdbuf, sizeof(cmdbuf), obuf); }
-static void -ob_cuda_initialize (int *idx) -{ - phandle_t ph=get_cur_dev(); - int props[2]; - - push_str("via-cuda"); - fword("device-type"); - - set_int_property(ph, "#address-cells", 1); - set_int_property(ph, "#size-cells", 0); - - set_property(ph, "compatible", "cuda", 5); - - props[0] = __cpu_to_be32(IO_CUDA_OFFSET); - props[1] = __cpu_to_be32(IO_CUDA_SIZE); - - set_property(ph, "reg", (char *)&props, sizeof(props)); - - /* on newworld machines the cuda is on interrupt 0x19 */ - - props[0] = 0x19; - props[1] = 0; - NEWWORLD(set_property(ph, "interrupts", (char *)props, sizeof(props))); - NEWWORLD(set_int_property(ph, "#interrupt-cells", 2)); - - /* we emulate an oldworld hardware, so we must use - * non-standard oldworld property (needed by linux 2.6.18) - */ - - OLDWORLD(set_int_property(ph, "AAPL,interrupts", 0x12)); - - bind_func("ppc32-reset-all", ppc32_reset_all); - push_str("' ppc32-reset-all to reset-all"); - fword("eval"); -} - static void ob_cuda_open(int *idx) { @@ -241,12 +204,11 @@ ob_cuda_close(int *idx) }
NODE_METHODS(ob_cuda) = { - { NULL, ob_cuda_initialize }, { "open", ob_cuda_open }, { "close", ob_cuda_close }, };
-DECLARE_UNNAMED_NODE(rtc, INSTALL_OPEN, sizeof(int)); +DECLARE_UNNAMED_NODE(rtc, 0, sizeof(int));
static void rtc_open(int *idx) @@ -368,41 +330,67 @@ NODE_METHODS(rtc) = { static void rtc_init(char *path) { - phandle_t ph, aliases; + phandle_t aliases; char buf[128];
- snprintf(buf, sizeof(buf), "%s/rtc", path); - REGISTER_NAMED_NODE(rtc, buf); + push_str(path); + fword("find-device"); + + fword("new-device"); + + push_str("rtc"); + fword("device-name"); + + push_str("rtc"); + fword("device-type"); + + push_str("rtc"); + fword("encode-string"); + push_str("compatible"); + fword("property");
- ph = find_dev(buf); - set_property(ph, "device_type", "rtc", 4); - set_property(ph, "compatible", "rtc", 4); + BIND_NODE_METHODS(get_cur_dev(), rtc); + fword("finish-device");
aliases = find_dev("/aliases"); + snprintf(buf, sizeof(buf), "%s/rtc", path); set_property(aliases, "rtc", buf, strlen(buf) + 1); - }
static void powermgt_init(char *path) { - phandle_t ph; - char buf[128]; + push_str(path); + fword("find-device");
- snprintf(buf, sizeof(buf), "%s/power-mgt", path); - REGISTER_NAMED_NODE(rtc, buf); + fword("new-device");
- ph = find_dev(buf); - set_property(ph, "device_type", "power-mgt", 10); - set_property(ph, "mgt-kind", "min-consumption-pwm-led", strlen("min-consumption-pwm-led") + 1); - set_property(ph, "compatible", "cuda", strlen("cuda") + 1); + push_str("power-mgt"); + fword("device-name"); + + push_str("power-mgt"); + fword("device-type"); + + push_str("min-consumption-pwm-led"); + fword("encode-string"); + push_str("mgt-kind"); + fword("property"); + + push_str("cuda"); + fword("encode-string"); + push_str("compatible"); + fword("property"); + + BIND_NODE_METHODS(get_cur_dev(), rtc); + fword("finish-device"); }
cuda_t *cuda_init (const char *path, phys_addr_t base) { cuda_t *cuda; char buf[64]; - phandle_t aliases; + phandle_t ph, aliases; + int props[2];
base += IO_CUDA_OFFSET; CUDA_DPRINTF(" base=" FMT_plx "\n", base); @@ -410,10 +398,57 @@ cuda_t *cuda_init (const char *path, phys_addr_t base) if (cuda == NULL) return NULL;
- snprintf(buf, sizeof(buf), "%s/via-cuda", path); - REGISTER_NAMED_NODE(ob_cuda, buf); + push_str(path); + fword("find-device"); + + fword("new-device"); + + push_str("via-cuda"); + fword("device-name"); + + push_str("via-cuda"); + fword("device-type"); + + push_str("cuda"); + fword("encode-string"); + push_str("compatible"); + fword("property"); + + PUSH(1); + fword("encode-int"); + push_str("#address-cells"); + fword("property"); + + PUSH(0); + fword("encode-int"); + push_str("#size-cells"); + fword("property"); + + PUSH(IO_CUDA_OFFSET); + fword("encode-int"); + PUSH(IO_CUDA_SIZE); + fword("encode-int"); + fword("encode+"); + push_str("reg"); + fword("property"); + + ph = get_cur_dev(); + + /* on newworld machines the cuda is on interrupt 0x19 */ + props[0] = 0x19; + props[1] = 0; + NEWWORLD(set_property(ph, "interrupts", (char *)props, sizeof(props))); + NEWWORLD(set_int_property(ph, "#interrupt-cells", 2)); + + /* we emulate an oldworld hardware, so we must use + * non-standard oldworld property (needed by linux 2.6.18) + */ + OLDWORLD(set_int_property(ph, "AAPL,interrupts", 0x12)); + + BIND_NODE_METHODS(get_cur_dev(), ob_cuda);
aliases = find_dev("/aliases"); + snprintf(buf, sizeof(buf), "%s/via-cuda", path); set_property(aliases, "via-cuda", buf, strlen(buf) + 1);
cuda->base = base; @@ -430,10 +465,14 @@ cuda_t *cuda_init (const char *path, phys_addr_t base) rtc_init(buf); powermgt_init(buf);
- main_cuda = cuda; + main_cuda = cuda; + + fword("finish-device");
- device_end(); - bind_func("poweroff", ppc32_poweroff); + bind_func("ppc32-power-off", ppc32_poweroff); + feval("['] ppc32-power-off to power-off"); + bind_func("ppc32-reset-all", ppc32_reset_all); + feval("['] ppc32-reset-all to reset-all");
return cuda; }
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/macio.c | 111 ++++++++++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 50 deletions(-)
diff --git a/drivers/macio.c b/drivers/macio.c index be6f9e4..eb2af04 100644 --- a/drivers/macio.c +++ b/drivers/macio.c @@ -189,7 +189,7 @@ openpic_init(const char *path, phys_addr_t addr) fword("finish-device"); }
-DECLARE_NODE(ob_macio, INSTALL_OPEN, sizeof(int), "Tmac-io"); +DECLARE_UNNAMED_NODE(ob_macio, 0, sizeof(int));
/* ( str len -- addr ) */
@@ -284,20 +284,41 @@ ob_unin_init(void) fword("finish-device"); }
-static void ob_macio_gpio_initialize (int *idx) +static void macio_gpio_init(const char *path) { - phandle_t ph=get_cur_dev(); - int props[2]; + push_str(path); + fword("find-device"); + + fword("new-device"); + + push_str("gpio"); + fword("device-name");
push_str("gpio"); fword("device-type");
- set_int_property(ph, "#address-cells", 1); - set_int_property(ph, "#size-cells", 0); - set_property(ph, "compatible", "mac-io-gpio", 12); - props[0] = __cpu_to_be32(0x50); - props[1] = __cpu_to_be32(0x30); - set_property(ph, "reg", (char *)&props, sizeof(props)); + PUSH(1); + fword("encode-int"); + push_str("#address-cells"); + fword("property"); + + PUSH(0); + fword("encode-int"); + push_str("#size-cells"); + fword("property"); + + push_str("mac-io-gpio"); + fword("encode-string"); + push_str("compatible"); + fword("property"); + + PUSH(0x50); + fword("encode-int"); + PUSH(0x30); + fword("encode-int"); + fword("encode+"); + push_str("reg"); + fword("property");
/* Build the extint-gpio1 for the PMU */ fword("new-device"); @@ -339,57 +360,47 @@ static void ob_macio_gpio_initialize (int *idx) push_str("interrupts"); fword("property"); fword("finish-device"); -}
-DECLARE_UNNAMED_NODE(ob_macio_gpio, 0, 0); - -NODE_METHODS(ob_macio_gpio) = { - { NULL, ob_macio_gpio_initialize } -}; - -static void macio_gpio_init(const char *path) -{ - char buf[64]; - - snprintf(buf, sizeof(buf), "%s/gpio", path); - REGISTER_NAMED_NODE(ob_macio_gpio, buf); + fword("finish-device"); }
void ob_macio_heathrow_init(const char *path, phys_addr_t addr) { - phandle_t aliases; + phandle_t aliases;
- REGISTER_NODE(ob_macio); - aliases = find_dev("/aliases"); - set_property(aliases, "mac-io", path, strlen(path) + 1); + BIND_NODE_METHODS(get_cur_dev(), ob_macio); + + cuda_init(path, addr); + macio_nvram_init(path, addr); + escc_init(path, addr); + macio_ide_init(path, addr, 2);
- cuda_init(path, addr); - macio_nvram_init(path, addr); - escc_init(path, addr); - macio_ide_init(path, addr, 2); + aliases = find_dev("/aliases"); + set_property(aliases, "mac-io", path, strlen(path) + 1); }
void ob_macio_keylargo_init(const char *path, phys_addr_t addr) { - phandle_t aliases; - - REGISTER_NODE(ob_macio); - aliases = find_dev("/aliases"); - set_property(aliases, "mac-io", path, strlen(path) + 1); - - if (has_pmu()) { - macio_gpio_init(path); - pmu_init(path, addr); - } else { - cuda_init(path, addr); - } - - /* The NewWorld NVRAM is not located in the MacIO device */ - macio_nvram_init("", 0); - escc_init(path, addr); - macio_ide_init(path, addr, 2); - openpic_init(path, addr); - ob_unin_init(); + phandle_t aliases; + + BIND_NODE_METHODS(get_cur_dev(), ob_macio); + + if (has_pmu()) { + macio_gpio_init(path); + pmu_init(path, addr); + } else { + cuda_init(path, addr); + } + + /* The NewWorld NVRAM is not located in the MacIO device */ + macio_nvram_init("", 0); + escc_init(path, addr); + macio_ide_init(path, addr, 2); + openpic_init(path, addr); + ob_unin_init(); + + aliases = find_dev("/aliases"); + set_property(aliases, "mac-io", path, strlen(path) + 1); }
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/pmu.c | 155 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 107 insertions(+), 48 deletions(-)
diff --git a/drivers/pmu.c b/drivers/pmu.c index 9198846..38fa1e8 100644 --- a/drivers/pmu.c +++ b/drivers/pmu.c @@ -348,7 +348,7 @@ static int pmu_adb_req(void *host, const uint8_t *snd_buf, int len, } #endif
-DECLARE_UNNAMED_NODE(ob_pmu, INSTALL_OPEN, sizeof(int)); +DECLARE_UNNAMED_NODE(ob_pmu, 0, sizeof(int));
static pmu_t *main_pmu;
@@ -364,32 +364,6 @@ static void pmu_poweroff(void) pmu_request(main_pmu, PMU_SHUTDOWN, 4, params, NULL, NULL); }
-static void ob_pmu_initialize (int *idx) -{ - phandle_t ph=get_cur_dev(); - int props[2]; - - push_str("via-pmu"); - fword("device-type"); - - set_int_property(ph, "#address-cells", 1); - set_int_property(ph, "#size-cells", 0); - set_property(ph, "compatible", "pmu", 4); - - props[0] = __cpu_to_be32(IO_PMU_OFFSET); - props[1] = __cpu_to_be32(IO_PMU_SIZE); - set_property(ph, "reg", (char *)&props, sizeof(props)); - - /* On newworld machines the PMU is on interrupt 0x19 */ - props[0] = 0x19; - props[1] = 1; - set_property(ph, "interrupts", (char *)props, sizeof(props)); - set_int_property(ph, "pmu-version", 0xd0330c); - - bind_func("pmu-reset-all", pmu_reset_all); - feval("['] pmu-reset-all to reset-all"); -} - static void ob_pmu_open(int *idx) { RET(-1); @@ -400,18 +374,21 @@ static void ob_pmu_close(int *idx) }
NODE_METHODS(ob_pmu) = { - { NULL, ob_pmu_initialize }, { "open", ob_pmu_open }, { "close", ob_pmu_close }, };
-DECLARE_UNNAMED_NODE(rtc, INSTALL_OPEN, sizeof(int)); +DECLARE_UNNAMED_NODE(rtc, 0, sizeof(int));
static void rtc_open(int *idx) { RET(-1); }
+static void rtc_close(int *idx) +{ +} + /* * get-time ( -- second minute hour day month year ) * @@ -516,31 +493,64 @@ static void rtc_set_time(int *idx)
NODE_METHODS(rtc) = { { "open", rtc_open }, + { "close", rtc_close }, { "get-time", rtc_get_time }, { "set-time", rtc_set_time }, };
static void rtc_init(char *path) { - phandle_t ph, aliases; + phandle_t aliases; char buf[128];
- snprintf(buf, sizeof(buf), "%s/rtc", path); - REGISTER_NAMED_NODE(rtc, buf); + push_str(path); + fword("find-device"); + + fword("new-device");
- ph = find_dev(buf); - set_property(ph, "device_type", "rtc", 4); - set_property(ph, "compatible", "rtc,via-pmu", 12); + push_str("rtc"); + fword("device-name"); + + push_str("rtc"); + fword("device-type"); + + push_str("rtc,via-pmu"); + fword("encode-string"); + push_str("compatible"); + fword("property"); + + BIND_NODE_METHODS(get_cur_dev(), rtc); + fword("finish-device");
aliases = find_dev("/aliases"); + snprintf(buf, sizeof(buf), "%s/rtc", path); set_property(aliases, "rtc", buf, strlen(buf) + 1); - device_end(); }
static void powermgt_init(char *path) { phandle_t ph; - char buf[128]; + + push_str(path); + fword("find-device"); + + fword("new-device"); + + push_str("power-mgt"); + fword("device-name"); + + push_str("power-mgt"); + fword("device-type"); + + push_str("via-pmu-99"); + fword("encode-string"); + push_str("compatible"); + fword("property"); + + push_str("extint-gpio1"); + fword("encode-string"); + push_str("registry-name"); + fword("property");
/* This is a bunch of magic "Feature" bits for which we only have * partial definitions from Darwin. These are taken from a @@ -574,15 +584,12 @@ static void powermgt_init(char *path) 0x46, 0x00, 0x02, 0x78, 0x78, 0x3c, 0x00 };
- snprintf(buf, sizeof(buf), "%s/power-mgt", path); - REGISTER_NAMED_NODE(rtc, buf); // XXX ? + ph = get_cur_dev(); + BIND_NODE_METHODS(ph, rtc);
- ph = find_dev(buf); - set_property(ph, "device_type", "power-mgt", 10); - set_property(ph, "compatible", "via-pmu-99", 11); - set_property(ph, "registry-name", "extint-gpio1", 13); set_property(ph, "prim-info", prim, sizeof(prim)); - device_end(); + + fword("finish-device"); }
pmu_t *pmu_init(const char *path, phys_addr_t base) @@ -599,10 +606,58 @@ pmu_t *pmu_init(const char *path, phys_addr_t base) return NULL; }
- snprintf(buf, sizeof(buf), "%s/via-pmu", path); - REGISTER_NAMED_NODE(ob_pmu, buf); + push_str(path); + fword("find-device"); + + fword("new-device"); + + push_str("via-pmu"); + fword("device-name"); + + push_str("via-pmu"); + fword("device-type"); + + push_str("pmu"); + fword("encode-string"); + push_str("compatible"); + fword("property"); + + PUSH(1); + fword("encode-int"); + push_str("#address-cells"); + fword("property"); + + PUSH(0); + fword("encode-int"); + push_str("#size-cells"); + fword("property"); + + PUSH(IO_PMU_OFFSET); + fword("encode-int"); + PUSH(IO_PMU_SIZE); + fword("encode-int"); + fword("encode+"); + push_str("reg"); + fword("property"); + + /* On newworld machines the PMU is on interrupt 0x19 */ + PUSH(0x19); + fword("encode-int"); + PUSH(1); + fword("encode-int"); + fword("encode+"); + push_str("interrupts"); + fword("property"); + + PUSH(0xd0330c); + fword("encode-int"); + push_str("pmu-version"); + fword("property"); + + BIND_NODE_METHODS(get_cur_dev(), ob_pmu);
aliases = find_dev("/aliases"); + snprintf(buf, sizeof(buf), "%s/via-pmu", path); set_property(aliases, "via-pmu", buf, strlen(buf) + 1); pmu->base = base;
@@ -618,8 +673,12 @@ pmu_t *pmu_init(const char *path, phys_addr_t base)
main_pmu = pmu;
- device_end(); - bind_func("poweroff", pmu_poweroff); + fword("finish-device"); + + bind_func("pmu-power-off", pmu_poweroff); + feval("['] pmu-power-off to power-off"); + bind_func("pmu-reset-all", pmu_reset_all); + feval("['] pmu-reset-all to reset-all");
return pmu; }
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/usbhid.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/usbhid.c b/drivers/usbhid.c index 1c13113..a847b6e 100644 --- a/drivers/usbhid.c +++ b/drivers/usbhid.c @@ -39,7 +39,7 @@ #include "drivers/usb.h" #include "usb.h"
-DECLARE_UNNAMED_NODE(usb_kbd, INSTALL_OPEN, sizeof(int)); +DECLARE_UNNAMED_NODE(usb_kbd, 0, sizeof(int));
static void keyboard_open(int *idx) @@ -564,16 +564,24 @@ void ob_usb_hid_add_keyboard(const char *path) char name[128]; phandle_t aliases;
- snprintf(name, sizeof(name), "%s/keyboard", path); - usb_debug("Found keyboard at %s\n", name); - REGISTER_NAMED_NODE(usb_kbd, name); - - push_str(name); + push_str(path); fword("find-device");
+ fword("new-device"); + + push_str("keyboard"); + fword("device-name"); + push_str("keyboard"); fword("device-type");
+ snprintf(name, sizeof(name), "%s/keyboard", path); + usb_debug("Found keyboard at %s\n", name); + + BIND_NODE_METHODS(get_cur_dev(), usb_kbd); + + fword("finish-device"); + aliases = find_dev("/aliases"); set_property(aliases, "keyboard", name, strlen(name) + 1); }
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/macio.c | 8 ++++---- include/packages/nvram.h | 4 +++- packages/nvram.c | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/drivers/macio.c b/drivers/macio.c index eb2af04..5a94252 100644 --- a/drivers/macio.c +++ b/drivers/macio.c @@ -91,9 +91,8 @@ void macio_nvram_init(const char *path, phys_addr_t addr) nvram_size = macio_nvram_size();
nvram = (char*)addr + nvram_offset; - snprintf(buf, sizeof(buf), "%s/nvram", path); - nvram_init(buf); - dnode = find_dev(buf); + snprintf(buf, sizeof(buf), "%s", path); + dnode = nvram_init(buf); set_int_property(dnode, "#bytes", arch_nvram_size() ); props[0] = __cpu_to_be32(nvram_offset); props[1] = __cpu_to_be32(nvram_size); @@ -102,6 +101,7 @@ void macio_nvram_init(const char *path, phys_addr_t addr) NEWWORLD(set_property(dnode, "compatible", "nvram,flash", 12));
chosen = find_dev("/chosen"); + snprintf(buf, sizeof(buf), "%s", get_path_from_ph(dnode)); push_str(buf); fword("open-dev"); set_int_property(chosen, "nvram", POP()); @@ -395,7 +395,7 @@ ob_macio_keylargo_init(const char *path, phys_addr_t addr) }
/* The NewWorld NVRAM is not located in the MacIO device */ - macio_nvram_init("", 0); + macio_nvram_init("/", 0); escc_init(path, addr); macio_ide_init(path, addr, 2); openpic_init(path, addr); diff --git a/include/packages/nvram.h b/include/packages/nvram.h index ba1b38b..7803814 100644 --- a/include/packages/nvram.h +++ b/include/packages/nvram.h @@ -17,8 +17,10 @@ #ifndef _H_NVRAM_PACKAGE #define _H_NVRAM_PACKAGE
+#include "kernel/stack.h" + extern void nvconf_init( void ); -extern void nvram_init( const char *path ); +extern phandle_t nvram_init( const char *path ); extern void update_nvram( void );
#endif /* _H_NVRAM_PACKAGE */ diff --git a/packages/nvram.c b/packages/nvram.c index e895fed..6fd39b1 100644 --- a/packages/nvram.c +++ b/packages/nvram.c @@ -291,7 +291,20 @@ nvram_size( __attribute__((unused)) nvram_ibuf_t *nd ) PUSH( nvram.size ); }
+static void +nvram_open( __attribute__((unused)) nvram_ibuf_t *nd ) +{ + RET(-1); +} + +static void +nvram_close( __attribute__((unused)) nvram_ibuf_t *nd ) +{ +} + NODE_METHODS( nvram ) = { + { "open", (void*)nvram_open }, + { "close", (void*)nvram_close }, { "size", (void*)nvram_size }, { "read", (void*)nvram_read }, { "write", (void*)nvram_write }, @@ -299,10 +312,25 @@ NODE_METHODS( nvram ) = { };
-void +phandle_t nvram_init( const char *path ) { + phandle_t ph; + + push_str(path); + fword("find-device"); + + fword("new-device"); + nvconf_init();
- REGISTER_NAMED_NODE( nvram, path ); + ph = get_cur_dev(); + + push_str("nvram"); + fword("device-name"); + + BIND_NODE_METHODS(get_cur_dev(), nvram); + fword("finish-device"); + + return ph; }
When generating the DT based upon the active package and current instance, we cannot change either when setting the alias. Instead look up the phandle and then set the properties directly.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/lsi.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/lsi.c b/drivers/lsi.c index 1f3f038..37e4b9d 100644 --- a/drivers/lsi.c +++ b/drivers/lsi.c @@ -624,13 +624,12 @@ NODE_METHODS(ob_lsi) = { static void add_alias(const char *device, const char *alias) { + phandle_t aliases; + DPRINTF("add_alias dev "%s" = alias "%s"\n", device, alias); - push_str("/aliases"); - fword("find-device"); - push_str(device); - fword("encode-string"); - push_str(alias); - fword("property"); + + aliases = find_dev("/aliases"); + set_property(aliases, alias, device, strlen(device) + 1); }
int
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/lsi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/lsi.c b/drivers/lsi.c index 37e4b9d..bc4893a 100644 --- a/drivers/lsi.c +++ b/drivers/lsi.c @@ -642,7 +642,7 @@ ob_lsi_init(const char *path, uint64_t mmio, uint64_t ram) int i; ucell addr;
- REGISTER_NODE_METHODS(ob_lsi, path); + BIND_NODE_METHODS(ph, ob_lsi);
lsi = malloc(sizeof(lsi_private_t)); if (!lsi) { @@ -744,10 +744,13 @@ ob_lsi_init(const char *path, uint64_t mmio, uint64_t ram) fword("encode+"); push_str("reg"); fword("property"); + + BIND_NODE_METHODS(get_cur_dev(), ob_sd); fword("finish-device"); + snprintf(nodebuff, sizeof(nodebuff), "%s/sd@%d", get_path_from_ph(ph), id); - REGISTER_NODE_METHODS(ob_sd, nodebuff); + if (lsi->sd[id].media == TYPE_ROM) { counter_ptr = &cdcount; } else {
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/virtio.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/virtio.c b/drivers/virtio.c index 171db5a..6008ae9 100644 --- a/drivers/virtio.c +++ b/drivers/virtio.c @@ -503,12 +503,11 @@ void ob_virtio_init(const char *path, const char *dev_name, uint64_t common_cfg, ucell addr; VDev *vdev, **_vdev;
- REGISTER_NODE_METHODS(ob_virtio, path); - /* Open ob_virtio */ fword("my-self"); push_str(path); feval("open-dev to my-self"); + BIND_NODE_METHODS(get_cur_dev(), ob_virtio);
ph = find_ih_method("vdev", my_self()); PUSH(ph); @@ -546,10 +545,9 @@ void ob_virtio_init(const char *path, const char *dev_name, uint64_t common_cfg, push_str("_vdev"); fword("property");
+ BIND_NODE_METHODS(get_cur_dev(), ob_virtio_disk); fword("finish-device");
snprintf(buf, sizeof(buf), "%s/disk", path); - REGISTER_NODE_METHODS(ob_virtio_disk, buf); - set_virtio_alias(buf, idx); }
Moving the setup of PCI devices to within a new-device...finish-device sequence as part of the conversion further enables us to move the PCI host bridge configuration logic from ob_pci_init() to ob_configure_pci_device() where it belongs.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/pci.c | 96 +++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 53 deletions(-)
diff --git a/drivers/pci.c b/drivers/pci.c index 60e3948..623f649 100644 --- a/drivers/pci.c +++ b/drivers/pci.c @@ -528,7 +528,9 @@ static void pci_set_bus_range(const pci_config_t *config) set_property(dev, "bus-range", (char *)props, 2 * sizeof(props[0])); }
-static void pci_host_set_reg(phandle_t phandle) +static void ob_pci_reload_device_path(phandle_t phandle, pci_config_t *config); + +static void pci_host_set_reg(phandle_t phandle, pci_config_t *config) { phandle_t dev = phandle;
@@ -544,6 +546,8 @@ static void pci_host_set_reg(phandle_t phandle)
set_property(dev, "reg", (char *)props, ncells * sizeof(props[0]));
+ ob_pci_reload_device_path(dev, config); + #if defined(CONFIG_DEBUG_PCI) dump_reg_property("pci_host_set_reg", 4, props); #endif @@ -579,8 +583,6 @@ static void pci_host_set_ranges(const pci_config_t *config)
int host_config_cb(const pci_config_t *config) { - //XXX this overrides "reg" property - pci_host_set_reg(get_cur_dev()); pci_host_set_ranges(config);
return 0; @@ -1265,6 +1267,7 @@ static void ob_pci_add_properties(phandle_t phandle, uint8_t rev; uint8_t class_prog; uint32_t class_code; + char path[256];
vendor_id = pci_config_read16(addr, PCI_VENDOR_ID); device_id = pci_config_read16(addr, PCI_DEVICE_ID); @@ -1272,24 +1275,22 @@ static void ob_pci_add_properties(phandle_t phandle, class_prog = pci_config_read8(addr, PCI_CLASS_PROG); class_code = pci_config_read16(addr, PCI_CLASS_DEVICE);
+ /* Default path if we don't match anything */ + snprintf(path, sizeof(path), "pci%x,%x", vendor_id, device_id); + if (pci_dev) { /**/ if (pci_dev->name) { push_str(pci_dev->name); - fword("encode-string"); - push_str("name"); - fword("property"); + fword("device-name"); } else { - char path[256]; - snprintf(path, sizeof(path), - "pci%x,%x", vendor_id, device_id); push_str(path); - fword("encode-string"); - push_str("name"); - fword("property"); + fword("device-name"); } } else { PCI_DPRINTF("*** missing pci_dev\n"); + push_str(path); + fword("device-name"); }
/* create properties as described in 2.5 */ @@ -1335,15 +1336,11 @@ static void ob_pci_add_properties(phandle_t phandle, if (pci_dev) { if (pci_dev->type) { push_str(pci_dev->type); - fword("encode-string"); - push_str("device_type"); - fword("property"); + fword("device-type"); } if (pci_dev->model) { push_str(pci_dev->model); - fword("encode-string"); - push_str("model"); - fword("property"); + fword("model"); } if (pci_dev->compat) set_property(dev, "compatible", @@ -1765,7 +1762,7 @@ static phandle_t ob_configure_pci_device(const char* parent_path, uint8_t class, subclass, iface; int num_bars, rom_bar;
- phandle_t phandle = 0; + phandle_t phandle = 0, t; int is_host_bridge = 0;
if (!ob_pci_read_identification(bus, devnum, fn, &vid, &did, &class, &subclass)) { @@ -1789,54 +1786,52 @@ static phandle_t ob_configure_pci_device(const char* parent_path, } }
- /* stop adding host bridge accessible from it's primary bus - PCI host bridge is to be added by host code - */ if (class == PCI_BASE_CLASS_BRIDGE && subclass == PCI_SUBCLASS_BRIDGE_HOST) { is_host_bridge = 1; }
+ /* stop adding host bridge accessible from it's primary bus + PCI host bridge is to be added by host code + */ if (is_host_bridge) { /* reuse device tree node */ PCI_DPRINTF("host bridge found - "); - snprintf(config.path, sizeof(config.path), - "%s", parent_path); + + t = find_dev(parent_path); + if (get_property(t, "vendor-id", NULL)) { + PCI_DPRINTF("host bridge already configured\n"); + return 0; + } } else if (pci_dev == NULL || pci_dev->name == NULL) { snprintf(config.path, sizeof(config.path), "%s/pci%x,%x", parent_path, vid, did); - } - else { + } else { snprintf(config.path, sizeof(config.path), "%s/%s", parent_path, pci_dev->name); }
+ fword("new-device"); + PCI_DPRINTF("%s - ", config.path);
config.dev = addr & 0x00FFFFFF;
+ phandle = get_cur_dev(); + switch (class) { case PCI_BASE_CLASS_BRIDGE: if (subclass != PCI_SUBCLASS_BRIDGE_HOST) { - REGISTER_NAMED_NODE_PHANDLE(ob_pci_bridge_node, config.path, phandle); + BIND_NODE_METHODS(phandle, ob_pci_bridge_node); + } else { + BIND_NODE_METHODS(phandle, ob_pci_bus_node); } break; default: - REGISTER_NAMED_NODE_PHANDLE(ob_pci_empty_node, config.path, phandle); + BIND_NODE_METHODS(phandle, ob_pci_empty_node); break; }
- if (is_host_bridge) { - phandle = find_dev(config.path); - - if (get_property(phandle, "vendor-id", NULL)) { - PCI_DPRINTF("host bridge already configured\n"); - return 0; - } - } - - activate_dev(phandle); - if (htype & PCI_HEADER_TYPE_BRIDGE) { num_bars = 2; rom_bar = PCI_ROM_ADDRESS1; @@ -1852,6 +1847,8 @@ static phandle_t ob_configure_pci_device(const char* parent_path,
if (!is_host_bridge) { pci_set_reg(phandle, &config, num_bars); + } else { + pci_host_set_reg(phandle, &config); }
/* call device-specific configuration callback */ @@ -1862,12 +1859,9 @@ static phandle_t ob_configure_pci_device(const char* parent_path,
/* if devices haven't supplied open/close words then supply them with simple defaults */ if (!find_package_method("open", phandle) && !find_package_method("close", phandle)) { - REGISTER_NODE_METHODS(ob_pci_simple_node, config.path); + BIND_NODE_METHODS(phandle, ob_pci_simple_node); }
- /* device is configured so we may move it out of scope */ - device_end(); - /* scan bus behind bridge device */ //if (htype & PCI_HEADER_TYPE_BRIDGE && class == PCI_BASE_CLASS_BRIDGE) { if ( class == PCI_BASE_CLASS_BRIDGE && @@ -1882,6 +1876,8 @@ static phandle_t ob_configure_pci_device(const char* parent_path, ob_configure_pci_bridge(addr, bus_num, mem_base, io_base, bus, &config); }
+ fword("finish-device"); + return phandle; }
@@ -2103,7 +2099,8 @@ int ob_pci_init(void)
PCI_DPRINTF("Initializing PCI host bridge...\n");
- activate_device("/"); + push_str("/"); + fword("find-device");
/* Find all PCI bridges */
@@ -2130,16 +2127,9 @@ int ob_pci_init(void) /* create root node for host PCI bridge */
/* configure */ - snprintf(config.path, sizeof(config.path), "/pci"); - - REGISTER_NAMED_NODE_PHANDLE(ob_pci_bus_node, config.path, phandle_host); - - pci_host_set_reg(phandle_host); - - /* update device path after changing "reg" property */ - ob_pci_reload_device_path(phandle_host, &config); + strncpy(config.path, "", sizeof(config.path));
- ob_configure_pci_device(config.path, &bus, &mem_base, &io_base, + phandle_host = ob_configure_pci_device(config.path, &bus, &mem_base, &io_base, bus, devnum, fn, 0);
/* we expect single host PCI bridge
The ob_pci_initialize() function can be removed as it is empty, whilst ob_pci_empty_node is no longer required since the existing fallback code will always apply the ob_pci_simple_node bindings if no callback is configured.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/pci.c | 15 --------------- 1 file changed, 15 deletions(-)
diff --git a/drivers/pci.c b/drivers/pci.c index 623f649..d497109 100644 --- a/drivers/pci.c +++ b/drivers/pci.c @@ -54,7 +54,6 @@ DECLARE_UNNAMED_NODE( ob_pci_bus_node, INSTALL_OPEN, 2*sizeof(int) ); DECLARE_UNNAMED_NODE( ob_pci_bridge_node, INSTALL_OPEN, 2*sizeof(int) ); DECLARE_UNNAMED_NODE( ob_pci_simple_node, 0, 2*sizeof(int) ); -DECLARE_UNNAMED_NODE( ob_pci_empty_node, 0, 2*sizeof(int) );
const pci_arch_t *arch;
@@ -189,11 +188,6 @@ ob_pci_close(int *idx) { }
-static void -ob_pci_initialize(int *idx) -{ -} - /* ( str len -- phys.lo phys.mid phys.hi ) */
static void @@ -462,7 +456,6 @@ ob_pci_dma_sync(int *idx) }
NODE_METHODS(ob_pci_bus_node) = { - { NULL, ob_pci_initialize }, { "open", ob_pci_open }, { "close", ob_pci_close }, { "decode-unit", ob_pci_decode_unit }, @@ -485,7 +478,6 @@ ob_pci_bridge_map_in(int *idx) }
NODE_METHODS(ob_pci_bridge_node) = { - { NULL, ob_pci_initialize }, { "open", ob_pci_open }, { "close", ob_pci_close }, { "decode-unit", ob_pci_decode_unit }, @@ -503,10 +495,6 @@ NODE_METHODS(ob_pci_simple_node) = { { "close", ob_pci_close }, };
-NODE_METHODS(ob_pci_empty_node) = { - { NULL, ob_pci_initialize } -}; - static void pci_set_bus_range(const pci_config_t *config) { phandle_t dev = find_dev(config->path); @@ -1827,9 +1815,6 @@ static phandle_t ob_configure_pci_device(const char* parent_path, BIND_NODE_METHODS(phandle, ob_pci_bus_node); } break; - default: - BIND_NODE_METHODS(phandle, ob_pci_empty_node); - break; }
if (htype & PCI_HEADER_TYPE_BRIDGE) {
Now that we've removed all references to these binding macros they can be removed completely.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- include/libopenbios/bindings.h | 11 ----------- 1 file changed, 11 deletions(-)
diff --git a/include/libopenbios/bindings.h b/include/libopenbios/bindings.h index 6360a4f..6b0302d 100644 --- a/include/libopenbios/bindings.h +++ b/include/libopenbios/bindings.h @@ -108,17 +108,6 @@ typedef struct { void *func; } method_t;
-#define REGISTER_NAMED_NODE( name, path ) do { \ - bind_new_node( name##_flags_, name##_size_, \ - path, name##_m, sizeof(name##_m)/sizeof(method_t)); \ - } while(0) - -#define REGISTER_NAMED_NODE_PHANDLE( name, path, phandle ) do { \ - phandle = \ - bind_new_node( name##_flags_, name##_size_, \ - path, name##_m, sizeof(name##_m)/sizeof(method_t)); \ - } while(0) - #define REGISTER_NODE_METHODS( name, path ) do { \ const char *paths[1]; \ \
As part of this separation we can also move "update-nvram" directly to the NVRAM node bindings.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/macio.c | 1 + packages/nvram.c | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/macio.c b/drivers/macio.c index 5a94252..33f29f1 100644 --- a/drivers/macio.c +++ b/drivers/macio.c @@ -91,6 +91,7 @@ void macio_nvram_init(const char *path, phys_addr_t addr) nvram_size = macio_nvram_size();
nvram = (char*)addr + nvram_offset; + nvconf_init(); snprintf(buf, sizeof(buf), "%s", path); dnode = nvram_init(buf); set_int_property(dnode, "#bytes", arch_nvram_size() ); diff --git a/packages/nvram.c b/packages/nvram.c index 6fd39b1..a402f00 100644 --- a/packages/nvram.c +++ b/packages/nvram.c @@ -186,8 +186,6 @@ nvconf_init( void ) nvram.data = malloc( nvram.size ); arch_nvram_get( nvram.data );
- bind_func( "update-nvram", update_nvram ); - for( ;; ) { nvpart_t *p = NULL; int err; @@ -309,6 +307,7 @@ NODE_METHODS( nvram ) = { { "read", (void*)nvram_read }, { "write", (void*)nvram_write }, { "seek", (void*)nvram_seek }, + { "update-nvram", (void*)update_nvram }, };
@@ -322,8 +321,6 @@ nvram_init( const char *path )
fword("new-device");
- nvconf_init(); - ph = get_cur_dev();
push_str("nvram");
Whilst the NVRAM device node exists under the mac-io device node for Old World Macs, both itself and the Uninorth device node exist under the root device node on New World Macs.
Move creation of both device nodes to arch_of_init() for New World machines to enable the active package and current instance to be set correctly during device tree construction.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- arch/ppc/qemu/init.c | 12 +++++++++++- drivers/macio.c | 5 +---- drivers/macio.h | 1 - drivers/pci.c | 1 - include/drivers/drivers.h | 2 ++ 5 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c index f72728c..9056975 100644 --- a/arch/ppc/qemu/init.c +++ b/arch/ppc/qemu/init.c @@ -859,7 +859,17 @@ arch_of_init(void) feval("['] ppc-dma-sync to (dma-sync)");
#ifdef CONFIG_DRIVER_PCI - ob_pci_init(); + switch (machine_id) { + case ARCH_MAC99: + case ARCH_MAC99_U3: + /* The NewWorld NVRAM is not located in the MacIO device */ + macio_nvram_init("/", 0); + ob_pci_init(); + ob_unin_init(); + break; + default: + ob_pci_init(); + } #endif
printk("\n"); diff --git a/drivers/macio.c b/drivers/macio.c index 33f29f1..62a1e74 100644 --- a/drivers/macio.c +++ b/drivers/macio.c @@ -262,7 +262,7 @@ NODE_METHODS(ob_macio) = { { "dma-sync", ob_macio_dma_sync }, };
-static void +void ob_unin_init(void) { phandle_t dnode; @@ -395,12 +395,9 @@ ob_macio_keylargo_init(const char *path, phys_addr_t addr) cuda_init(path, addr); }
- /* The NewWorld NVRAM is not located in the MacIO device */ - macio_nvram_init("/", 0); escc_init(path, addr); macio_ide_init(path, addr, 2); openpic_init(path, addr); - ob_unin_init();
aliases = find_dev("/aliases"); set_property(aliases, "mac-io", path, strlen(path) + 1); diff --git a/drivers/macio.h b/drivers/macio.h index 925b881..36cc4bf 100644 --- a/drivers/macio.h +++ b/drivers/macio.h @@ -2,4 +2,3 @@ extern phandle_t pic_handle;
void ob_macio_heathrow_init(const char *path, phys_addr_t addr); void ob_macio_keylargo_init(const char *path, phys_addr_t addr); -void macio_nvram_init(const char *path, phys_addr_t addr); diff --git a/drivers/pci.c b/drivers/pci.c index d497109..c2da62f 100644 --- a/drivers/pci.c +++ b/drivers/pci.c @@ -31,7 +31,6 @@ #include "pci.h" #include "pci_database.h" #ifdef CONFIG_DRIVER_MACIO -#include "cuda.h" #include "macio.h" #endif #ifdef CONFIG_DRIVER_USB diff --git a/include/drivers/drivers.h b/include/drivers/drivers.h index e568f28..3d6fa12 100644 --- a/include/drivers/drivers.h +++ b/include/drivers/drivers.h @@ -149,6 +149,8 @@ void ob_virtio_init(const char *path, const char *dev_name, uint64_t common_cfg, int macio_get_nvram_size(void); void macio_nvram_put(char *buf); void macio_nvram_get(char *buf); +void macio_nvram_init(const char *path, phys_addr_t addr); +void ob_unin_init(void);
/* drivers/timer.c */ void setup_timers(void);
Now that all PCI devices have been converted to new-device...finish-device we can set both the active package and current instance to the root device node before probe, giving all child devices a correct active package and instance chain during creation.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- arch/ppc/qemu/init.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/arch/ppc/qemu/init.c b/arch/ppc/qemu/init.c index 9056975..45cd77e 100644 --- a/arch/ppc/qemu/init.c +++ b/arch/ppc/qemu/init.c @@ -859,6 +859,10 @@ arch_of_init(void) feval("['] ppc-dma-sync to (dma-sync)");
#ifdef CONFIG_DRIVER_PCI + push_str("/"); + fword("find-device"); + feval("" /" open-dev to my-self"); + switch (machine_id) { case ARCH_MAC99: case ARCH_MAC99_U3: @@ -870,6 +874,8 @@ arch_of_init(void) default: ob_pci_init(); } + + feval("0 to my-self"); #endif
printk("\n");
Now that all PCI devices have been converted to new-device...finish-device we can set both the active package and current instance to the root device node before probe, giving all child devices a correct active package and instance chain during creation.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- arch/sparc64/openbios.c | 6 ++++++ drivers/ide.c | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/arch/sparc64/openbios.c b/arch/sparc64/openbios.c index e2f7e59..e9f4726 100644 --- a/arch/sparc64/openbios.c +++ b/arch/sparc64/openbios.c @@ -821,11 +821,17 @@ arch_init( void ) feval("['] sparc64-dma-sync to (dma-sync)");
#ifdef CONFIG_DRIVER_PCI + push_str("/"); + fword("find-device"); + feval("" /" open-dev to my-self"); + ob_pci_init();
/* Set TAS register to match the virtual-dma properties set during sabre configure */ sparc64_set_tas_register(PBM_PCI_TARGET_AS_CD_ENABLE); + + feval("0 to my-self"); #endif nvconf_init(); device_end(); diff --git a/drivers/ide.c b/drivers/ide.c index 18a27c6..36e3b89 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -1392,9 +1392,6 @@ int ob_ide_init(const char *path, uint32_t io_port0, uint32_t ctl_port0, io_ports[1] = io_port1; ctl_ports[1] = ctl_port1;
- push_str(path); - fword("find-device"); - for (i = 0; i < IDE_NUM_CHANNELS; i++, current_channel++) {
chan = malloc(sizeof(struct ide_channel));
Now that all PCI devices have been converted to new-device...finish-device we can set both the active package and current instance to the root device node before probe, giving all child devices a correct active package and instance chain during creation.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- arch/x86/openbios.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/arch/x86/openbios.c b/arch/x86/openbios.c index 8a48a95..1274d2b 100644 --- a/arch/x86/openbios.c +++ b/arch/x86/openbios.c @@ -56,8 +56,15 @@ arch_init( void ) openbios_init(); modules_init(); #ifdef CONFIG_DRIVER_PCI - arch = &default_pci_host; + arch = &default_pci_host; + + push_str("/"); + fword("find-device"); + feval("" /" open-dev to my-self"); + ob_pci_init(); + + feval("0 to my-self"); #endif #ifdef CONFIG_DRIVER_IDE setup_timers();
Since the correct active package is now being set during probe, there is no need to explicitly find the parent node before creating the device.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/adb_bus.c | 3 --- drivers/adb_kbd.c | 3 --- drivers/adb_mouse.c | 3 --- drivers/cuda.c | 3 --- drivers/escc.c | 5 ----- drivers/floppy.c | 3 --- drivers/ide.c | 3 --- drivers/macio.c | 7 ------- drivers/pc_kbd.c | 7 ------- drivers/pc_serial.c | 3 --- drivers/pci.c | 5 ----- drivers/pmu.c | 3 --- drivers/usbhid.c | 3 --- 13 files changed, 51 deletions(-)
diff --git a/drivers/adb_bus.c b/drivers/adb_bus.c index c505322..1aa442a 100644 --- a/drivers/adb_bus.c +++ b/drivers/adb_bus.c @@ -76,9 +76,6 @@ int adb_bus_init (char *path, adb_bus_t *bus) int reloc = 0, next_free = 7; int keep;
- push_str(path); - fword("find-device"); - fword("new-device");
push_str("adb"); diff --git a/drivers/adb_kbd.c b/drivers/adb_kbd.c index df53fe0..dec8366 100644 --- a/drivers/adb_kbd.c +++ b/drivers/adb_kbd.c @@ -552,9 +552,6 @@ void *adb_kbd_new (char *path, void *private) my_adb_dev = dev; }
- push_str(path); - fword("find-device"); - fword("new-device");
push_str("keyboard"); diff --git a/drivers/adb_mouse.c b/drivers/adb_mouse.c index 6ee512f..38eabd5 100644 --- a/drivers/adb_mouse.c +++ b/drivers/adb_mouse.c @@ -51,9 +51,6 @@ void adb_mouse_new (char *path, void *private) phandle_t aliases; adb_dev_t *dev = private;
- push_str(path); - fword("find-device"); - fword("new-device");
push_str("mouse"); diff --git a/drivers/cuda.c b/drivers/cuda.c index d88edf8..56d73e1 100644 --- a/drivers/cuda.c +++ b/drivers/cuda.c @@ -398,9 +398,6 @@ cuda_t *cuda_init (const char *path, phys_addr_t base) if (cuda == NULL) return NULL;
- push_str(path); - fword("find-device"); - fword("new-device");
push_str("via-cuda"); diff --git a/drivers/escc.c b/drivers/escc.c index 199d571..392625e 100644 --- a/drivers/escc.c +++ b/drivers/escc.c @@ -450,9 +450,6 @@ escc_add_channel(const char *path, const char *node, phys_addr_t addr,
/* add device */
- push_str(path); - fword("find-device"); - fword("new-device");
snprintf(buf, sizeof(buf), "ch-%s", node); @@ -531,8 +528,6 @@ escc_init(const char *path, phys_addr_t addr) int props[2]; phandle_t dnode;
- push_str(path); - fword("find-device"); fword("new-device");
push_str("escc"); diff --git a/drivers/floppy.c b/drivers/floppy.c index f34811a..a3dff1f 100644 --- a/drivers/floppy.c +++ b/drivers/floppy.c @@ -1146,9 +1146,6 @@ int ob_floppy_init(const char *path, const char *dev_name, char nodebuff[128]; phandle_t aliases;
- push_str(path); - fword("find-device"); - fword("new-device");
push_str(dev_name); diff --git a/drivers/ide.c b/drivers/ide.c index 36e3b89..e56cb4c 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -1585,9 +1585,6 @@ int macio_ide_init(const char *path, uint32_t addr, int nb_channels) * Also see comments in pci.c:ob_pci_host_set_interrupt_map() */ current_channel = 3;
- push_str(path); - fword("find-device"); - for (i = 0; i < nb_channels; i++) {
chan = malloc(sizeof(struct ide_channel)); diff --git a/drivers/macio.c b/drivers/macio.c index 62a1e74..496bab1 100644 --- a/drivers/macio.c +++ b/drivers/macio.c @@ -168,8 +168,6 @@ openpic_init(const char *path, phys_addr_t addr) int props[2]; char buf[128];
- push_str(path); - fword("find-device"); fword("new-device"); push_str("interrupt-controller"); fword("device-name"); @@ -268,8 +266,6 @@ ob_unin_init(void) phandle_t dnode; int props[2];
- push_str("/"); - fword("find-device"); fword("new-device"); push_str("uni-n"); fword("device-name"); @@ -287,9 +283,6 @@ ob_unin_init(void)
static void macio_gpio_init(const char *path) { - push_str(path); - fword("find-device"); - fword("new-device");
push_str("gpio"); diff --git a/drivers/pc_kbd.c b/drivers/pc_kbd.c index ed6b82c..dfb73bf 100644 --- a/drivers/pc_kbd.c +++ b/drivers/pc_kbd.c @@ -208,9 +208,6 @@ ob_pc_kbd_init(const char *path, const char *kdev_name, const char *mdev_name, { phandle_t chosen, aliases; char nodebuff[128]; - - push_str(path); - fword("find-device");
fword("new-device");
@@ -303,10 +300,6 @@ ob_pc_kbd_init(const char *path, const char *kdev_name, const char *mdev_name,
/* Mouse (optional) */ if (mdev_name != NULL) { - snprintf(nodebuff, sizeof(nodebuff), "%s/8042", path); - push_str(nodebuff); - fword("find-device"); - fword("new-device");
push_str(mdev_name); diff --git a/drivers/pc_serial.c b/drivers/pc_serial.c index 0d42689..c39afb4 100644 --- a/drivers/pc_serial.c +++ b/drivers/pc_serial.c @@ -168,9 +168,6 @@ ob_pc_serial_init(const char *path, const char *dev_name, uint64_t base, phandle_t aliases; char nodebuff[128];
- push_str(path); - fword("find-device"); - fword("new-device");
push_str(dev_name); diff --git a/drivers/pci.c b/drivers/pci.c index c2da62f..4fba12a 100644 --- a/drivers/pci.c +++ b/drivers/pci.c @@ -2083,9 +2083,6 @@ int ob_pci_init(void)
PCI_DPRINTF("Initializing PCI host bridge...\n");
- push_str("/"); - fword("find-device"); - /* Find all PCI bridges */
mem_base = arch->pci_mem_base; @@ -2128,7 +2125,5 @@ int ob_pci_init(void) intc = ob_pci_host_set_interrupt_map(phandle_host); ob_pci_bus_set_interrupt_map(phandle_host, intc, ob_pci_host_bus_interrupt);
- device_end(); - return 0; } diff --git a/drivers/pmu.c b/drivers/pmu.c index 38fa1e8..f74a30b 100644 --- a/drivers/pmu.c +++ b/drivers/pmu.c @@ -606,9 +606,6 @@ pmu_t *pmu_init(const char *path, phys_addr_t base) return NULL; }
- push_str(path); - fword("find-device"); - fword("new-device");
push_str("via-pmu"); diff --git a/drivers/usbhid.c b/drivers/usbhid.c index a847b6e..b8e1548 100644 --- a/drivers/usbhid.c +++ b/drivers/usbhid.c @@ -564,9 +564,6 @@ void ob_usb_hid_add_keyboard(const char *path) char name[128]; phandle_t aliases;
- push_str(path); - fword("find-device"); - fword("new-device");
push_str("keyboard");
Since the correct current instance is now being set during probe, there is no need to explicitly set it whilst creating the device.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/lsi.c | 5 ----- drivers/virtio.c | 4 ---- 2 files changed, 9 deletions(-)
diff --git a/drivers/lsi.c b/drivers/lsi.c index bc4893a..a325547 100644 --- a/drivers/lsi.c +++ b/drivers/lsi.c @@ -653,10 +653,6 @@ ob_lsi_init(const char *path, uint64_t mmio, uint64_t ram) global_lsi = lsi;
/* Buffer for commands */ - fword("my-self"); - push_str(path); - feval("open-dev to my-self"); - PUSH(0x1000); feval("dma-alloc"); addr = POP(); @@ -695,7 +691,6 @@ ob_lsi_init(const char *path, uint64_t mmio, uint64_t ram)
set_int_property(ph, "#address-cells", 1); set_int_property(ph, "#size-cells", 0); - feval("to my-self");
/* Initialise SCRIPTS */ lsi->mmio = (uint8_t *)(uint32_t)mmio; diff --git a/drivers/virtio.c b/drivers/virtio.c index 6008ae9..4f9f5ee 100644 --- a/drivers/virtio.c +++ b/drivers/virtio.c @@ -504,9 +504,6 @@ void ob_virtio_init(const char *path, const char *dev_name, uint64_t common_cfg, VDev *vdev, **_vdev;
/* Open ob_virtio */ - fword("my-self"); - push_str(path); - feval("open-dev to my-self"); BIND_NODE_METHODS(get_cur_dev(), ob_virtio);
ph = find_ih_method("vdev", my_self()); @@ -532,7 +529,6 @@ void ob_virtio_init(const char *path, const char *dev_name, uint64_t common_cfg, vdev->ring_area = cell2pointer(addr);
*_vdev = vdev; - feval("to my-self");
fword("new-device"); push_str("disk");
This is to ensure that the my-space and my-address words are set correctly for any PCI devices that wish to execute FCode.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/pci.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
diff --git a/drivers/pci.c b/drivers/pci.c index 4fba12a..9d501d3 100644 --- a/drivers/pci.c +++ b/drivers/pci.c @@ -1748,6 +1748,8 @@ static phandle_t ob_configure_pci_device(const char* parent_path, const pci_dev_t *pci_dev; uint8_t class, subclass, iface; int num_bars, rom_bar; + uint32_t props[3]; + char *unit_str;
phandle_t phandle = 0, t; int is_host_bridge = 0; @@ -1804,6 +1806,25 @@ static phandle_t ob_configure_pci_device(const char* parent_path,
config.dev = addr & 0x00FFFFFF;
+ if (!is_host_bridge) { + /* Get encoded address for set-args */ + pci_encode_phys_addr(props, 0, CONFIGURATION_SPACE, config.dev, 0, 0); + PUSH(props[2]); + PUSH(props[1]); + PUSH(props[0]); + call_parent_method("encode-unit"); + + unit_str = pop_fstr_copy(); + + /* Call set-args to set up my-space and my-address */ + PUSH(0); + PUSH(0); + push_str(unit_str); + fword("set-args"); + + free(unit_str); + } + phandle = get_cur_dev();
switch (class) {
Instead use an instance value and initialise the C instance parameter within the open word.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/pc_serial.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/pc_serial.c b/drivers/pc_serial.c index c39afb4..f67383d 100644 --- a/drivers/pc_serial.c +++ b/drivers/pc_serial.c @@ -142,19 +142,16 @@ pc_serial_close(void) static void pc_serial_open(unsigned long *address) { - RET ( -1 ); -} - -static void -pc_serial_init(unsigned long *address) -{ + PUSH(find_ih_method("address", my_self())); + fword("execute"); *address = POP(); + + RET ( -1 ); }
DECLARE_UNNAMED_NODE(pc_serial, 0, sizeof(unsigned long));
NODE_METHODS(pc_serial) = { - { "init", pc_serial_init }, { "open", pc_serial_open }, { "close", pc_serial_close }, { "read", pc_serial_read }, @@ -201,7 +198,7 @@ ob_pc_serial_init(const char *path, const char *dev_name, uint64_t base, BIND_NODE_METHODS(get_cur_dev(), pc_serial);
PUSH(offset); - feval("['] init execute"); + feval("value address");
fword("finish-device");
This simplifies the open word by avoiding having to locate and read the value of the address property.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/pc_kbd.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/pc_kbd.c b/drivers/pc_kbd.c index dfb73bf..a98e57e 100644 --- a/drivers/pc_kbd.c +++ b/drivers/pc_kbd.c @@ -181,15 +181,9 @@ pc_kbd_close(void) static void pc_kbd_open(unsigned long *address) { - int len; - phandle_t ph; - unsigned long *prop; - - fword("my-self"); - fword("ihandle>phandle"); - ph = (phandle_t)POP(); - prop = (unsigned long *)get_property(ph, "address", &len); - *address = *prop; + PUSH(find_ih_method("address", my_self())); + fword("execute"); + *address = POP();
RET ( -1 ); } @@ -285,6 +279,10 @@ ob_pc_kbd_init(const char *path, const char *kdev_name, const char *mdev_name, fword("property");
BIND_NODE_METHODS(get_cur_dev(), pc_kbd); + + PUSH(offset); + feval("value address"); + fword("finish-device");
snprintf(nodebuff, sizeof(nodebuff), "%s/8042/%s", path, kdev_name);
It is also possible to remove the global_lsi variable by adding a pointer to the parent lsi_private_t instance within sd_private_t.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/lsi.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/drivers/lsi.c b/drivers/lsi.c index a325547..51a541c 100644 --- a/drivers/lsi.c +++ b/drivers/lsi.c @@ -18,7 +18,11 @@ #include "drivers/drivers.h" #include "scsi.h"
-typedef struct sd_private { +typedef struct sd_private sd_private_t; +typedef struct lsi_table lsi_table_t; +typedef struct lsi_private lsi_private_t; + +struct sd_private { unsigned int bs; const char *media_str[2]; uint32_t sectors; @@ -26,9 +30,10 @@ typedef struct sd_private { uint8_t id; uint8_t present; char model[40]; -} sd_private_t; + lsi_private_t *lsi; +};
-typedef struct lsi_table { +struct lsi_table { uint32_t id; uint32_t id_addr; uint32_t msg_out_len; @@ -41,9 +46,9 @@ typedef struct lsi_table { uint32_t status_ptr; uint32_t msg_in_len; uint32_t msg_in_ptr; -} lsi_table_t; +};
-typedef struct lsi_private { +struct lsi_private { volatile uint8_t *mmio; uint32_t *scripts; uint32_t *scripts_iova; @@ -52,9 +57,7 @@ typedef struct lsi_private { volatile uint8_t *buffer; volatile uint8_t *buffer_iova; sd_private_t sd[8]; -} lsi_private_t; - -static lsi_private_t *global_lsi; +};
#ifdef CONFIG_DEBUG_LSI #define DPRINTF(fmt, args...) \ @@ -504,6 +507,7 @@ ob_sd_read_blocks(sd_private_t **sd) ucell blk = POP(); char *dest = (char*)POP(); int pos, spb, sect_offset; + lsi_private_t *lsi = (*sd)->lsi;
DPRINTF("ob_sd_read_blocks id %d %lx block=%d n=%d\n", (*sd)->id, (unsigned long)dest, blk, n );
@@ -516,12 +520,12 @@ ob_sd_read_blocks(sd_private_t **sd) sect_offset = blk / spb; pos = (blk - sect_offset * spb) * 512;
- if (ob_sd_read_sector(global_lsi, *sd, sect_offset)) { + if (ob_sd_read_sector(lsi, *sd, sect_offset)) { DPRINTF("ob_sd_read_blocks: error\n"); RET(0); } while (n && pos < spb * 512) { - memcpy(dest, (uint8_t *)&global_lsi->buffer[LSI_TABLE_DATA_OFFSET] + pos, 512); + memcpy(dest, (uint8_t *)&lsi->buffer[LSI_TABLE_DATA_OFFSET] + pos, 512); pos += 512; dest += 512; n--; @@ -540,12 +544,12 @@ ob_sd_block_size(__attribute__((unused))sd_private_t **sd) static void ob_sd_open(__attribute__((unused))sd_private_t **sd) { - int ret = 1, id; + int ret = 1; phandle_t ph;
- fword("my-unit"); - id = POP(); - *sd = &global_lsi->sd[id]; + PUSH(find_ih_method("sd-private", my_self())); + fword("execute"); + *sd = cell2pointer(POP());
#ifdef CONFIG_DEBUG_LSI { @@ -553,7 +557,7 @@ ob_sd_open(__attribute__((unused))sd_private_t **sd)
fword("my-args"); args = pop_fstr_copy(); - DPRINTF("opening drive %d args %s\n", id, args); + DPRINTF("opening drive args %s\n", args); free(args); } #endif @@ -650,8 +654,6 @@ ob_lsi_init(const char *path, uint64_t mmio, uint64_t ram) return -1; }
- global_lsi = lsi; - /* Buffer for commands */ PUSH(0x1000); feval("dma-alloc"); @@ -726,6 +728,9 @@ ob_lsi_init(const char *path, uint64_t mmio, uint64_t ram) for (id = 0; id < 8; id++) { if (!lsi->sd[id].present) continue; + + lsi->sd[id].lsi = lsi; + fword("new-device"); push_str("sd"); fword("device-name"); @@ -740,6 +745,9 @@ ob_lsi_init(const char *path, uint64_t mmio, uint64_t ram) push_str("reg"); fword("property");
+ PUSH(pointer2cell(&lsi->sd[id])); + feval("value sd-private"); + BIND_NODE_METHODS(get_cur_dev(), ob_sd); fword("finish-device");
This simplifies the open word by avoiding having to locate and read the value of the _vdev property.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/virtio.c | 46 +++++++++++----------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-)
diff --git a/drivers/virtio.c b/drivers/virtio.c index 4f9f5ee..ff7ed6f 100644 --- a/drivers/virtio.c +++ b/drivers/virtio.c @@ -337,9 +337,14 @@ ob_virtio_configure_device(VDev *vdev) static void ob_virtio_disk_open(VDev **_vdev) { - VDev *vdev = *_vdev; + VDev *vdev; phandle_t ph;
+ PUSH(find_ih_method("vdev", my_self())); + fword("execute"); + *_vdev = cell2pointer(POP()); + vdev = *_vdev; + vdev->pos = 0;
if (!vdev->configured) { @@ -409,24 +414,9 @@ static void set_virtio_alias(const char *path, int idx) set_property(aliases, name, path, strlen(path) + 1); }
-static void -ob_virtio_disk_initialize(VDev **_vdev) -{ - phandle_t ph = get_cur_dev(); - VDev *vdev; - int len; - - vdev = cell2pointer(get_int_property(ph, "_vdev", &len)); - push_str("_vdev"); - feval("delete-property"); - - *_vdev = vdev; -} - DECLARE_UNNAMED_NODE(ob_virtio_disk, 0, sizeof(VDev *));
NODE_METHODS(ob_virtio_disk) = { - { NULL, ob_virtio_disk_initialize }, { "open", ob_virtio_disk_open }, { "close", ob_virtio_disk_close }, { "seek", ob_virtio_disk_seek }, @@ -445,12 +435,6 @@ ob_virtio_close(VDev **_vdev) return; }
-static void -ob_virtio_vdev(VDev **_vdev) -{ - PUSH(pointer2cell(_vdev)); -} - static void ob_virtio_dma_alloc(__attribute__((unused)) VDev **_vdev) { @@ -486,7 +470,6 @@ DECLARE_UNNAMED_NODE(ob_virtio, 0, sizeof(VDev *)); NODE_METHODS(ob_virtio) = { { "open", ob_virtio_open }, { "close", ob_virtio_close }, - { "vdev", ob_virtio_vdev }, { "dma-alloc", ob_virtio_dma_alloc }, { "dma-free", ob_virtio_dma_free }, { "dma-map-in", ob_virtio_dma_map_in }, @@ -499,18 +482,12 @@ void ob_virtio_init(const char *path, const char *dev_name, uint64_t common_cfg, int idx) { char buf[256]; - phandle_t ph; ucell addr; - VDev *vdev, **_vdev; + VDev *vdev;
/* Open ob_virtio */ BIND_NODE_METHODS(get_cur_dev(), ob_virtio);
- ph = find_ih_method("vdev", my_self()); - PUSH(ph); - fword("execute"); - _vdev = cell2pointer(POP()); - vdev = malloc(sizeof(VDev)); vdev->common_cfg = common_cfg; vdev->device_cfg = device_cfg; @@ -518,6 +495,9 @@ void ob_virtio_init(const char *path, const char *dev_name, uint64_t common_cfg, vdev->notify_mult = notify_mult; vdev->configured = 0;
+ PUSH(pointer2cell(vdev)); + feval("value vdev"); + PUSH(sizeof(VRing) * VIRTIO_MAX_VQS); feval("dma-alloc"); addr = POP(); @@ -528,8 +508,6 @@ void ob_virtio_init(const char *path, const char *dev_name, uint64_t common_cfg, addr = POP(); vdev->ring_area = cell2pointer(addr);
- *_vdev = vdev; - fword("new-device"); push_str("disk"); fword("device-name"); @@ -537,9 +515,7 @@ void ob_virtio_init(const char *path, const char *dev_name, uint64_t common_cfg, fword("device-type");
PUSH(pointer2cell(vdev)); - fword("encode-int"); - push_str("_vdev"); - fword("property"); + feval("value vdev");
BIND_NODE_METHODS(get_cur_dev(), ob_virtio_disk); fword("finish-device");
On 18/08/2019 21:37, Mark Cave-Ayland wrote:
This patchset started off with the aim of building the PCI-based machine device trees downwards from the root node to avoid switching either the active package and/or current instance at various points during the tree construction.
The basis for this was to try and remove all named nodes (those which are placed at a given path) and instead build the hierarchy in order by using new-device and finish-device as per the IEEE-1275 specification. This was realised by creating a new BIND_NODE_METHODS() macro which is similar to REGISTER_NAMED_NODE() except that it doesn't alter either the active package or the current instance, and then working through the device tree from the root converting all the devices for the PCI-based machines to use it.
Once this conversion has been completed for all devices beneath the PCI node, it becomes possible to remove both the REGISTER_NAMED_NODE() and REGISTER_NAMED_NODE_PHANDLE() macros to prevent future patches from accidentally changing the tree construction order.
Next the x86, PPC and SPARC64 device tree roots were altered to set the active package and current instance, allowing the remaining places where the PCI code alters either of them to be removed.
At this point instance variables were working correctly, and I noticed that there were several PCI devices which made use of C initialisation functions and/or properties for initial configuration. These can now be replaced with instance variables to keep everything simple and consistent.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
v3:
- Rebase onto master
- Fix up USB debug string for keyboard reported by Zoltan
- Fix for creating devices that don't have an entry in the PCI database
- Fix for MacOS 9 not initialising network reported by Howard
v2:
- Fix up NVRAM initialisation so that -prom-env 'vga-ndrv?=false' works again
Mark Cave-Ayland (30): libopenbios: introduce BIND_NODE_METHODS() macro pc_kbd: convert to use BIND_NODE_METHODS() macro pc_serial: convert to use BIND_NODE_METHODS() macro floppy: convert to use BIND_NODE_METHODS() macro ide: convert to use BIND_NODE_METHODS() macro adb: convert to use BIND_NODE_METHODS() macro escc: convert to use BIND_NODE_METHODS() macro cuda: convert to use BIND_NODE_METHODS() macro macio: convert to use BIND_NODE_METHODS() macro pmu: convert to use BIND_NODE_METHODS() macro usbhid: convert to use BIND_NODE_METHODS() macro nvram: convert to use BIND_NODE_METHODS() macro lsi: don't change active package when setting device alias lsi: convert to use BIND_NODE_METHODS() macro virtio: convert to use BIND_NODE_METHODS() macro pci: convert to use BIND_NODE_METHODS() macro pci: remove ob_pci_initialize() and ob_pci_empty_node libopenbios: remove REGISTER_NAMED_NODE and REGISTER_NAMED_NODE_PHANDLE macros nvram: ensure that NVRAM configuration is separate from NVRAM node creation ppc: move New World uninorth and nvram device node creation to the root device ppc: set active package and current instance to root device node before probe SPARC64: set active package and current instance to root device node before probe x86: set active package and current instance to root device node before probe pci: remove explicit find-device from PCI devices pci: remove explicit setting of my-self from PCI devices pci: call set-args before configuring PCI device nodes pc_serial: remove separate init word pc_kbd: use instance value to initialise C instance parameter lsi: use instance value to hold sd_private_t pointer virtio: use instance value to initialise C instance parameter
arch/ppc/qemu/init.c | 18 +++- arch/sparc64/openbios.c | 6 ++ arch/x86/openbios.c | 9 +- drivers/adb_bus.c | 57 +++++++----- drivers/adb_kbd.c | 25 ++++-- drivers/adb_mouse.c | 31 ++++--- drivers/cuda.c | 158 ++++++++++++++++++++------------- drivers/escc.c | 113 ++++++++++++++--------- drivers/floppy.c | 68 +++++++------- drivers/ide.c | 123 +++++++++++++++---------- drivers/lsi.c | 65 +++++++------- drivers/macio.c | 118 ++++++++++++------------ drivers/macio.h | 1 - drivers/pc_kbd.c | 48 +++++----- drivers/pc_serial.c | 32 +++---- drivers/pci.c | 132 +++++++++++++-------------- drivers/pmu.c | 152 +++++++++++++++++++++---------- drivers/usbhid.c | 17 ++-- drivers/virtio.c | 56 +++--------- include/drivers/drivers.h | 2 + include/libopenbios/bindings.h | 19 ++-- include/packages/nvram.h | 4 +- libopenbios/bindings.c | 10 +++ packages/nvram.c | 35 ++++++-- 24 files changed, 755 insertions(+), 544 deletions(-)
I've had no bug reports since posting v3 last week, so I've now pushed this to master. Thanks to everyone for helping test the changes.
ATB,
Mark.
On Thu, 22 Aug 2019, Mark Cave-Ayland wrote:
I've had no bug reports since posting v3 last week, so I've now pushed this to master. Thanks to everyone for helping test the changes.
Thank you. Now only my pci-map-in patch is needed for ATI FCode ROM and I have sent another patch before to improve printing of assigned-addresses for what I've just sent a ping to remind you.
Regards, BALATON Zoltan