These patches, in conjunction with the corresponding QEMU patch, implement the power-off word for SPARC32 and SPARC64. For SPARC64 we also implement the SUNW,power-off CIF service which is used by most OSs to power down the machine.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
Mark Cave-Ayland (5): admin: add power.fs with initial dummy power-off implementation SPARC32: implement power-off word SPARC64: add power device under the ebus device SPARC64: implement power-off word ciface.fs: implement SUNW,power-off service
arch/sparc64/openbios.c | 27 +++++++++++++++++++++++++++ drivers/obio.c | 10 ++++++++++ drivers/pci.c | 34 ++++++++++++++++++++++++++++++++++ forth/admin/build.xml | 1 + forth/admin/power.fs | 9 +++++++++ forth/system/ciface.fs | 8 ++++++++ 6 files changed, 89 insertions(+) create mode 100644 forth/admin/power.fs
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- forth/admin/build.xml | 1 + forth/admin/power.fs | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 forth/admin/power.fs
diff --git a/forth/admin/build.xml b/forth/admin/build.xml index 6654496..c1dfbc9 100644 --- a/forth/admin/build.xml +++ b/forth/admin/build.xml @@ -16,6 +16,7 @@ <object source="iocontrol.fs"/> <object source="banner.fs"/> <object source="reset.fs"/> + <object source="power.fs"/> <object source="script.fs"/> <object source="security.fs"/> <object source="selftest.fs"/> diff --git a/forth/admin/power.fs b/forth/admin/power.fs new file mode 100644 index 0000000..237bc72 --- /dev/null +++ b/forth/admin/power.fs @@ -0,0 +1,9 @@ +\ Power + +defer power-off ( -- ) + +: no-power-off + s" power-off is not available on this platform." type cr + ; + +' no-power-off to power-off
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/obio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/drivers/obio.c b/drivers/obio.c index a3778f4..12cdb46 100644 --- a/drivers/obio.c +++ b/drivers/obio.c @@ -224,6 +224,12 @@ volatile unsigned char *power_reg; volatile unsigned int *reset_reg;
static void +sparc32_power_off(void) +{ + *power_reg = 1; +} + +static void sparc32_reset_all(void) { *reset_reg = 1; @@ -237,6 +243,10 @@ ob_aux2_reset_init(uint64_t base, uint64_t offset, int intr)
power_reg = (void *)ob_reg(base, offset, AUXIO2_REGS, 1);
+ bind_func("sparc32-power-off", sparc32_power_off); + push_str("' sparc32-power-off to power-off"); + fword("eval"); + // Not in device tree reset_reg = (unsigned int *)ofmem_map_io(base + (uint64_t)SLAVIO_RESET, RESET_REGS);
Due to limitations in the current QEMU PCI IO BAR layout, it isn't possible to use the offset of 0x7240000 as used in a real Ultra 5.
For the moment locate the power device at offset 0x7240 as a reminder of its true origin.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- drivers/pci.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
diff --git a/drivers/pci.c b/drivers/pci.c index 672dcd0..ce329ce 100644 --- a/drivers/pci.c +++ b/drivers/pci.c @@ -1044,6 +1044,40 @@ int ebus_config_cb(const pci_config_t *config) fword("device-name"); fword("finish-device");
+ /* Build power node */ + fword("new-device"); + PUSH(0x14); + fword("encode-int"); + PUSH(0x7240); + fword("encode-int"); + fword("encode+"); + PUSH(0x4); + fword("encode-int"); + fword("encode+"); + push_str("reg"); + fword("property"); + + PUSH(0); + PUSH(0); + push_str("button"); + fword("property"); + + PUSH(1); + fword("encode-int"); + push_str("interrupts"); + fword("property"); + + /* Map the power registers so we can use them */ + virt = ofmem_map_io(io_phys_base + 0x7240, 0x4); + PUSH(virt); + fword("encode-int"); + push_str("address"); + fword("property"); + + push_str("power"); + fword("device-name"); + fword("finish-device"); + #ifdef CONFIG_DRIVER_FLOPPY ob_floppy_init(config->path, "fdthree", 0x3f0ULL, 0); #endif
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- arch/sparc64/openbios.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
diff --git a/arch/sparc64/openbios.c b/arch/sparc64/openbios.c index c0e1d0d..46d44ea 100644 --- a/arch/sparc64/openbios.c +++ b/arch/sparc64/openbios.c @@ -120,6 +120,28 @@ sparc64_reset_all(void) : : "r" (val), "r" (addr) : "memory"); }
+/* Power off */ +static void +sparc64_power_off(void) +{ + /* Locate address of ebus power device */ + phandle_t ph; + uint32_t addr; + volatile uint32_t *p; + int len; + + ph = find_dev("/pci/pci@1,1/ebus/power"); + if (ph) { + addr = get_int_property(ph, "address", &len); + + if (len) { + /* Set bit 24 to invoke power off */ + p = cell2pointer(addr); + *p = 0x1000000; + } + } +} + /* PCI Target Address Space Register (see UltraSPARC IIi User's Manual section 19.3.0.4) */ #define PBM_PCI_TARGET_AS 0x2028 @@ -727,6 +749,11 @@ arch_init( void ) bind_func("spacel@", spacel_read); bind_func("spacex@", spacex_read);
+ /* Bind power functions */ + bind_func("sparc64-power-off", sparc64_power_off); + push_str("' sparc64-power-off to power-off"); + fword("eval"); + bind_func("platform-boot", boot ); }
This is a Sun-specific service which is only enabled for the SPARC64 architecture.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- forth/system/ciface.fs | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/forth/system/ciface.fs b/forth/system/ciface.fs index 9dc433c..146561a 100644 --- a/forth/system/ciface.fs +++ b/forth/system/ciface.fs @@ -348,6 +348,14 @@ external find-method 0= if -1 else drop 0 then ;
+[IFDEF] CONFIG_SPARC64 + +: SUNW,power-off ( -- ) + power-off +; + +[THEN] + finish-device device-end
On 15/01/18 21:04, Mark Cave-Ayland wrote:
These patches, in conjunction with the corresponding QEMU patch, implement the power-off word for SPARC32 and SPARC64. For SPARC64 we also implement the SUNW,power-off CIF service which is used by most OSs to power down the machine.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
Mark Cave-Ayland (5): admin: add power.fs with initial dummy power-off implementation SPARC32: implement power-off word SPARC64: add power device under the ebus device SPARC64: implement power-off word ciface.fs: implement SUNW,power-off service
arch/sparc64/openbios.c | 27 +++++++++++++++++++++++++++ drivers/obio.c | 10 ++++++++++ drivers/pci.c | 34 ++++++++++++++++++++++++++++++++++ forth/admin/build.xml | 1 + forth/admin/power.fs | 9 +++++++++ forth/system/ciface.fs | 8 ++++++++ 6 files changed, 89 insertions(+) create mode 100644 forth/admin/power.fs
No further comments, so applied to master.
ATB,
Mark.