From 04fa02213efdffbced013ad521094482d5bde2f8 Mon Sep 17 00:00:00 2001 From: Aurelien Jarno Date: Sun, 20 Jul 2014 17:12:14 +0000 Subject: [PATCH] [mips/malta] Backport from upstream power management support for Malta. svn path=/dists/sid/linux/; revision=21588 --- debian/changelog | 2 + ...ine-some-more-PIIX4-registers-values.patch | 41 ++++ ...-PIIX4-respond-to-PCI-special-cycles.patch | 45 ++++ ...PS-Malta-Setup-PM-I-O-region-on-boot.patch | 67 ++++++ ...S-Malta-add-suspend-state-entry-code.patch | 202 ++++++++++++++++++ .../mips/MIPS-Malta-hang-on-halt.patch | 51 +++++ .../MIPS-Malta-support-powering-down.patch | 45 ++++ debian/patches/series | 6 + 8 files changed, 459 insertions(+) create mode 100644 debian/patches/features/mips/MIPS-Define-some-more-PIIX4-registers-values.patch create mode 100644 debian/patches/features/mips/MIPS-Malta-Let-PIIX4-respond-to-PCI-special-cycles.patch create mode 100644 debian/patches/features/mips/MIPS-Malta-Setup-PM-I-O-region-on-boot.patch create mode 100644 debian/patches/features/mips/MIPS-Malta-add-suspend-state-entry-code.patch create mode 100644 debian/patches/features/mips/MIPS-Malta-hang-on-halt.patch create mode 100644 debian/patches/features/mips/MIPS-Malta-support-powering-down.patch diff --git a/debian/changelog b/debian/changelog index b422d8526..f7e9b694b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -62,6 +62,8 @@ linux (3.14.13-1) UNRELEASED; urgency=medium mode detection for Octeon. * [mips/sb1-91250a] Backport from upstream additional build flags to fix excessive kernel warnings. + * [mips/malta] Backport from upstream power management support for + Malta. [ Ben Hutchings ] * net/l2tp: don't fall back on UDP [get|set]sockopt (CVE-2014-4943) diff --git a/debian/patches/features/mips/MIPS-Define-some-more-PIIX4-registers-values.patch b/debian/patches/features/mips/MIPS-Define-some-more-PIIX4-registers-values.patch new file mode 100644 index 000000000..e79e996df --- /dev/null +++ b/debian/patches/features/mips/MIPS-Define-some-more-PIIX4-registers-values.patch @@ -0,0 +1,41 @@ +From: Paul Burton +Date: Wed, 7 May 2014 12:20:56 +0100 +Subject: [1/5] MIPS: Define some more PIIX4 registers & values +Origin: https://git.kernel.org/linus/643c5705bc9d30b64ca320715eb210b853d1f27e + +This patch simply adds definitions for some I/O registers in the PIIX4 +PM device, and the magic data for a special cycle which must occur on +the PCI bus in order for the PIIX4 to enter a suspend state. + +Signed-off-by: Paul Burton +Cc: linux-mips@linux-mips.org +Patchwork: https://patchwork.linux-mips.org/patch/6903/ +Signed-off-by: Ralf Baechle +--- + arch/mips/include/asm/mips-boards/piix4.h | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/arch/mips/include/asm/mips-boards/piix4.h b/arch/mips/include/asm/mips-boards/piix4.h +index 9cf5404..9e340be 100644 +--- a/arch/mips/include/asm/mips-boards/piix4.h ++++ b/arch/mips/include/asm/mips-boards/piix4.h +@@ -55,4 +55,16 @@ + #define PIIX4_FUNC3_PMREGMISC 0x80 + #define PIIX4_FUNC3_PMREGMISC_EN (1 << 0) + ++/* Power Management IO Space */ ++#define PIIX4_FUNC3IO_PMSTS 0x00 ++#define PIIX4_FUNC3IO_PMSTS_PWRBTN_STS (1 << 8) ++#define PIIX4_FUNC3IO_PMCNTRL 0x04 ++#define PIIX4_FUNC3IO_PMCNTRL_SUS_EN (1 << 13) ++#define PIIX4_FUNC3IO_PMCNTRL_SUS_TYP (0x7 << 10) ++#define PIIX4_FUNC3IO_PMCNTRL_SUS_TYP_SOFF (0x0 << 10) ++#define PIIX4_FUNC3IO_PMCNTRL_SUS_TYP_STR (0x1 << 10) ++ ++/* Data for magic special PCI cycle */ ++#define PIIX4_SUSPEND_MAGIC 0x00120002 ++ + #endif /* __ASM_MIPS_BOARDS_PIIX4_H */ +-- +2.0.0 + diff --git a/debian/patches/features/mips/MIPS-Malta-Let-PIIX4-respond-to-PCI-special-cycles.patch b/debian/patches/features/mips/MIPS-Malta-Let-PIIX4-respond-to-PCI-special-cycles.patch new file mode 100644 index 000000000..a35f6100a --- /dev/null +++ b/debian/patches/features/mips/MIPS-Malta-Let-PIIX4-respond-to-PCI-special-cycles.patch @@ -0,0 +1,45 @@ +From: Paul Burton +Date: Wed, 7 May 2014 12:20:58 +0100 +Subject: [3/5] MIPS: Malta: Let PIIX4 respond to PCI special cycles +Origin: https://git.kernel.org/linus/9e53481eea26891011ef7aa28e7990769fb6cf50 + +This patch enables the PIIX4 to respond to special cycles on the PCI +bus. One such special cycle must be used in order to enter a suspend +state, and if response to it is not enabled then the suspend state will +never be entered. + +Signed-off-by: Paul Burton +Cc: linux-mips@linux-mips.org +Patchwork: https://patchwork.linux-mips.org/patch/6904/ +Signed-off-by: Ralf Baechle +--- + arch/mips/pci/fixup-malta.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/arch/mips/pci/fixup-malta.c b/arch/mips/pci/fixup-malta.c +index 2f9e52a..40e920c 100644 +--- a/arch/mips/pci/fixup-malta.c ++++ b/arch/mips/pci/fixup-malta.c +@@ -68,6 +68,7 @@ static void malta_piix_func0_fixup(struct pci_dev *pdev) + { + unsigned char reg_val; + u32 reg_val32; ++ u16 reg_val16; + /* PIIX PIRQC[A:D] irq mappings */ + static int piixirqmap[PIIX4_FUNC0_PIRQRC_IRQ_ROUTING_MAX] = { + 0, 0, 0, 3, +@@ -107,6 +108,11 @@ static void malta_piix_func0_fixup(struct pci_dev *pdev) + pci_read_config_byte(pdev, PIIX4_FUNC0_SERIRQC, ®_val); + reg_val |= PIIX4_FUNC0_SERIRQC_EN | PIIX4_FUNC0_SERIRQC_CONT; + pci_write_config_byte(pdev, PIIX4_FUNC0_SERIRQC, reg_val); ++ ++ /* Enable response to special cycles */ ++ pci_read_config_word(pdev, PCI_COMMAND, ®_val16); ++ pci_write_config_word(pdev, PCI_COMMAND, ++ reg_val16 | PCI_COMMAND_SPECIAL); + } + + DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0, +-- +2.0.0 + diff --git a/debian/patches/features/mips/MIPS-Malta-Setup-PM-I-O-region-on-boot.patch b/debian/patches/features/mips/MIPS-Malta-Setup-PM-I-O-region-on-boot.patch new file mode 100644 index 000000000..375351638 --- /dev/null +++ b/debian/patches/features/mips/MIPS-Malta-Setup-PM-I-O-region-on-boot.patch @@ -0,0 +1,67 @@ +From: Paul Burton +Date: Fri, 21 Mar 2014 15:20:31 +0000 +Subject: MIPS: Malta: Setup PM I/O region on boot +Origin: https://git.kernel.org/linus/fa12b773b7fb5830469086d36eb5be9f6b512f4d + +This patch ensures that the kernel sets a sane base address for the +PIIX4 PM I/O register region during boot. Without this the kernel may +not successfully claim the region as a resource if the bootloader didn't +configure the region. With this patch the kernel will always succeed +with: + + pci 0000:00:0a.3: quirk: [io 0x1000-0x103f] claimed by PIIX4 ACPI + +The lack of the resource claiming is easily reproducible without this +patch using current versions of QEMU. + +Signed-off-by: Paul Burton +Tested-by: James Hogan +Cc: linux-mips@linux-mips.org +Patchwork: https://patchwork.linux-mips.org/patch/6641/ +Signed-off-by: Ralf Baechle +--- + arch/mips/include/asm/mips-boards/piix4.h | 5 +++++ + arch/mips/pci/fixup-malta.c | 13 +++++++++++++ + 2 files changed, 18 insertions(+) + +diff --git a/arch/mips/include/asm/mips-boards/piix4.h b/arch/mips/include/asm/mips-boards/piix4.h +index 836e2ed..9cf5404 100644 +--- a/arch/mips/include/asm/mips-boards/piix4.h ++++ b/arch/mips/include/asm/mips-boards/piix4.h +@@ -50,4 +50,9 @@ + #define PIIX4_FUNC1_IDETIM_SECONDARY_HI 0x43 + #define PIIX4_FUNC1_IDETIM_SECONDARY_HI_IDE_DECODE_EN (1 << 7) + ++/* Power Management Configuration Space */ ++#define PIIX4_FUNC3_PMBA 0x40 ++#define PIIX4_FUNC3_PMREGMISC 0x80 ++#define PIIX4_FUNC3_PMREGMISC_EN (1 << 0) ++ + #endif /* __ASM_MIPS_BOARDS_PIIX4_H */ +diff --git a/arch/mips/pci/fixup-malta.c b/arch/mips/pci/fixup-malta.c +index 7a0eda7..2f9e52a 100644 +--- a/arch/mips/pci/fixup-malta.c ++++ b/arch/mips/pci/fixup-malta.c +@@ -51,6 +51,19 @@ int pcibios_plat_dev_init(struct pci_dev *dev) + return 0; + } + ++static void malta_piix_func3_base_fixup(struct pci_dev *dev) ++{ ++ /* Set a sane PM I/O base address */ ++ pci_write_config_word(dev, PIIX4_FUNC3_PMBA, 0x1000); ++ ++ /* Enable access to the PM I/O region */ ++ pci_write_config_byte(dev, PIIX4_FUNC3_PMREGMISC, ++ PIIX4_FUNC3_PMREGMISC_EN); ++} ++ ++DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, ++ malta_piix_func3_base_fixup); ++ + static void malta_piix_func0_fixup(struct pci_dev *pdev) + { + unsigned char reg_val; +-- +2.0.0 + diff --git a/debian/patches/features/mips/MIPS-Malta-add-suspend-state-entry-code.patch b/debian/patches/features/mips/MIPS-Malta-add-suspend-state-entry-code.patch new file mode 100644 index 000000000..ee6c27796 --- /dev/null +++ b/debian/patches/features/mips/MIPS-Malta-add-suspend-state-entry-code.patch @@ -0,0 +1,202 @@ +From: Paul Burton +Date: Wed, 7 May 2014 12:20:57 +0100 +Subject: [2/5] MIPS: Malta: add suspend state entry code +Origin: https://git.kernel.org/linus/b6911bba598f5d611f7fdbb87b5af7f1712dbe9d + +This patch introduces code which will enter a suspend state via the +PIIX4. This can only be done when PCI support is enabled since it +requires access to PCI I/O space and the generation of a special cycle +on the PCI bus. In cases where PCI is disabled the mips_pm_suspend +function will simply always return an error. + +Signed-off-by: Paul Burton +Cc: linux-mips@linux-mips.org +Patchwork: https://patchwork.linux-mips.org/patch/6905/ +Signed-off-by: Ralf Baechle +--- + arch/mips/Kconfig | 6 ++ + arch/mips/include/asm/mach-malta/malta-pm.h | 37 +++++++++++ + arch/mips/mti-malta/Makefile | 2 + + arch/mips/mti-malta/malta-pm.c | 96 +++++++++++++++++++++++++++++ + 4 files changed, 141 insertions(+) + create mode 100644 arch/mips/include/asm/mach-malta/malta-pm.h + create mode 100644 arch/mips/mti-malta/malta-pm.c + +diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig +index 4e49591..2f2020f 100644 +--- a/arch/mips/Kconfig ++++ b/arch/mips/Kconfig +@@ -1671,6 +1671,12 @@ config SYS_HAS_CPU_XLR + config SYS_HAS_CPU_XLP + bool + ++config MIPS_MALTA_PM ++ depends on MIPS_MALTA ++ depends on PCI ++ bool ++ default y ++ + # + # CPU may reorder R->R, R->W, W->R, W->W + # Reordering beyond LL and SC is handled in WEAK_REORDERING_BEYOND_LLSC +diff --git a/arch/mips/include/asm/mach-malta/malta-pm.h b/arch/mips/include/asm/mach-malta/malta-pm.h +new file mode 100644 +index 0000000..c2c2e20 +--- /dev/null ++++ b/arch/mips/include/asm/mach-malta/malta-pm.h +@@ -0,0 +1,37 @@ ++/* ++ * Copyright (C) 2014 Imagination Technologies ++ * Author: Paul Burton ++ * ++ * This program is free software; you can redistribute it and/or modify it ++ * under the terms of the GNU General Public License as published by the ++ * Free Software Foundation; either version 2 of the License, or (at your ++ * option) any later version. ++ */ ++ ++#ifndef __ASM_MIPS_MACH_MALTA_PM_H__ ++#define __ASM_MIPS_MACH_MALTA_PM_H__ ++ ++#include ++ ++#ifdef CONFIG_MIPS_MALTA_PM ++ ++/** ++ * mips_pm_suspend - enter a suspend state ++ * @state: the state to enter, one of PIIX4_FUNC3IO_PMCNTRL_SUS_TYP_* ++ * ++ * Enters a suspend state via the Malta's PIIX4. If the state to be entered ++ * is one which loses context (eg. SOFF) then this function will never ++ * return. ++ */ ++extern int mips_pm_suspend(unsigned state); ++ ++#else /* !CONFIG_MIPS_MALTA_PM */ ++ ++static inline int mips_pm_suspend(unsigned state) ++{ ++ return -EINVAL; ++} ++ ++#endif /* !CONFIG_MIPS_MALTA_PM */ ++ ++#endif /* __ASM_MIPS_MACH_MALTA_PM_H__ */ +diff --git a/arch/mips/mti-malta/Makefile b/arch/mips/mti-malta/Makefile +index a851601..b9510ea 100644 +--- a/arch/mips/mti-malta/Makefile ++++ b/arch/mips/mti-malta/Makefile +@@ -8,6 +8,8 @@ + obj-y := malta-amon.o malta-display.o malta-init.o \ + malta-int.o malta-memory.o malta-platform.o \ + malta-reset.o malta-setup.o malta-time.o ++ ++obj-$(CONFIG_MIPS_MALTA_PM) += malta-pm.o + + # FIXME FIXME FIXME + obj-$(CONFIG_MIPS_MT_SMTC) += malta-smtc.o +diff --git a/arch/mips/mti-malta/malta-pm.c b/arch/mips/mti-malta/malta-pm.c +new file mode 100644 +index 0000000..c1e456c +--- /dev/null ++++ b/arch/mips/mti-malta/malta-pm.c +@@ -0,0 +1,96 @@ ++/* ++ * Copyright (C) 2014 Imagination Technologies ++ * Author: Paul Burton ++ * ++ * This program is free software; you can redistribute it and/or modify it ++ * under the terms of the GNU General Public License as published by the ++ * Free Software Foundation; either version 2 of the License, or (at your ++ * option) any later version. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include ++ ++static struct pci_bus *pm_pci_bus; ++static resource_size_t pm_io_offset; ++ ++int mips_pm_suspend(unsigned state) ++{ ++ int spec_devid; ++ u16 sts; ++ ++ if (!pm_pci_bus || !pm_io_offset) ++ return -ENODEV; ++ ++ /* Ensure the power button status is clear */ ++ while (1) { ++ sts = inw(pm_io_offset + PIIX4_FUNC3IO_PMSTS); ++ if (!(sts & PIIX4_FUNC3IO_PMSTS_PWRBTN_STS)) ++ break; ++ outw(sts, pm_io_offset + PIIX4_FUNC3IO_PMSTS); ++ } ++ ++ /* Enable entry to suspend */ ++ outw(state | PIIX4_FUNC3IO_PMCNTRL_SUS_EN, ++ pm_io_offset + PIIX4_FUNC3IO_PMCNTRL); ++ ++ /* If the special cycle occurs too soon this doesn't work... */ ++ mdelay(10); ++ ++ /* ++ * The PIIX4 will enter the suspend state only after seeing a special ++ * cycle with the correct magic data on the PCI bus. Generate that ++ * cycle now. ++ */ ++ spec_devid = PCI_DEVID(0, PCI_DEVFN(0x1f, 0x7)); ++ pci_bus_write_config_dword(pm_pci_bus, spec_devid, 0, ++ PIIX4_SUSPEND_MAGIC); ++ ++ /* Give the system some time to power down */ ++ mdelay(1000); ++ ++ return 0; ++} ++ ++static int __init malta_pm_setup(void) ++{ ++ struct pci_dev *dev; ++ int res, io_region = PCI_BRIDGE_RESOURCES; ++ ++ /* Find a reference to the PCI bus */ ++ pm_pci_bus = pci_find_next_bus(NULL); ++ if (!pm_pci_bus) { ++ pr_warn("malta-pm: failed to find reference to PCI bus\n"); ++ return -ENODEV; ++ } ++ ++ /* Find the PIIX4 PM device */ ++ dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, ++ PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID, ++ PCI_ANY_ID, NULL); ++ if (!dev) { ++ pr_warn("malta-pm: failed to find PIIX4 PM\n"); ++ return -ENODEV; ++ } ++ ++ /* Request access to the PIIX4 PM IO registers */ ++ res = pci_request_region(dev, io_region, "PIIX4 PM IO registers"); ++ if (res) { ++ pr_warn("malta-pm: failed to request PM IO registers (%d)\n", ++ res); ++ pci_dev_put(dev); ++ return -ENODEV; ++ } ++ ++ /* Find the offset to the PIIX4 PM IO registers */ ++ pm_io_offset = pci_resource_start(dev, io_region); ++ ++ pci_dev_put(dev); ++ return 0; ++} ++ ++late_initcall(malta_pm_setup); +-- +2.0.0 + diff --git a/debian/patches/features/mips/MIPS-Malta-hang-on-halt.patch b/debian/patches/features/mips/MIPS-Malta-hang-on-halt.patch new file mode 100644 index 000000000..edeb5a68d --- /dev/null +++ b/debian/patches/features/mips/MIPS-Malta-hang-on-halt.patch @@ -0,0 +1,51 @@ +From: Paul Burton +Date: Wed, 7 May 2014 12:20:59 +0100 +Subject: [4/5] MIPS: Malta: hang on halt +Origin: https://git.kernel.org/linus/37e5c835bbbce4fde11cccc30dfe6c7b853ea964 + +When the system is halted it makes little sense to reset it. Instead, +hang by executing an infinite loop. + +[ralf@linux-mips.org: Remove printk from mips_machine_halt() - this is not +the place to communicate with the user.] + +Suggested-by: Maciej W. Rozycki +Signed-off-by: Paul Burton +Cc: linux-mips@linux-mips.org +Patchwork: https://patchwork.linux-mips.org/patch/6906/ +Signed-off-by: Ralf Baechle +--- + arch/mips/mti-malta/malta-reset.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/arch/mips/mti-malta/malta-reset.c b/arch/mips/mti-malta/malta-reset.c +index d627d4b..199ed280 100644 +--- a/arch/mips/mti-malta/malta-reset.c ++++ b/arch/mips/mti-malta/malta-reset.c +@@ -24,17 +24,19 @@ static void mips_machine_restart(char *command) + + static void mips_machine_halt(void) + { +- unsigned int __iomem *softres_reg = +- ioremap(SOFTRES_REG, sizeof(unsigned int)); ++ while (true); ++} + +- __raw_writel(GORESET, softres_reg); ++static void mips_machine_power_off(void) ++{ ++ mips_machine_restart(NULL); + } + + static int __init mips_reboot_setup(void) + { + _machine_restart = mips_machine_restart; + _machine_halt = mips_machine_halt; +- pm_power_off = mips_machine_halt; ++ pm_power_off = mips_machine_power_off; + + return 0; + } +-- +2.0.0 + diff --git a/debian/patches/features/mips/MIPS-Malta-support-powering-down.patch b/debian/patches/features/mips/MIPS-Malta-support-powering-down.patch new file mode 100644 index 000000000..be608552f --- /dev/null +++ b/debian/patches/features/mips/MIPS-Malta-support-powering-down.patch @@ -0,0 +1,45 @@ +From: Paul Burton +Date: Wed, 7 May 2014 12:22:12 +0100 +Subject: [5/5] MIPS: Malta: support powering down +Origin: https://git.kernel.org/linus/dadaa1c2c0eddc09d11d7494b040c3f331ecd98f + +This patch powers down the Malta in response to a power off command (eg. +poweroff or shutdown -P). It may then be powered back up by pressing the +"ON/NMI" button (S4) on the board. In cases where the power off state +cannot be entered (eg. because the required PCI support is disabled) the +current reset behaviour will be used as a fallback. + +Signed-off-by: Paul Burton +Tested-by: James Hogan +Cc: linux-mips@linux-mips.org +Patchwork: https://patchwork.linux-mips.org/patch/6907/ +Signed-off-by: Ralf Baechle +--- + arch/mips/mti-malta/malta-reset.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/arch/mips/mti-malta/malta-reset.c b/arch/mips/mti-malta/malta-reset.c +index 199ed280..2fd2cc2 100644 +--- a/arch/mips/mti-malta/malta-reset.c ++++ b/arch/mips/mti-malta/malta-reset.c +@@ -10,6 +10,7 @@ + #include + + #include ++#include + + #define SOFTRES_REG 0x1f000500 + #define GORESET 0x42 +@@ -29,6 +30,9 @@ static void mips_machine_halt(void) + + static void mips_machine_power_off(void) + { ++ mips_pm_suspend(PIIX4_FUNC3IO_PMCNTRL_SUS_TYP_SOFF); ++ ++ pr_info("Failed to power down, resetting\n"); + mips_machine_restart(NULL); + } + +-- +2.0.0 + diff --git a/debian/patches/series b/debian/patches/series index 55e59ac6e..d688d0484 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -101,3 +101,9 @@ features/mips/0012-MIPS-Loongson-3-Add-CPU-hotplug-support.patch features/mips/0013-MIPS-Loongson-Add-a-Loongson-3-default-config-file.patch features/mips/MIPS-Octeon-Add-PCIe2-support-in-arch_setup_msi_irq.patch features/mips/MIPS-octeon-Add-interface-mode-detection-for-Octeon-.patch +features/mips/MIPS-Malta-Setup-PM-I-O-region-on-boot.patch +features/mips/MIPS-Define-some-more-PIIX4-registers-values.patch +features/mips/MIPS-Malta-add-suspend-state-entry-code.patch +features/mips/MIPS-Malta-Let-PIIX4-respond-to-PCI-special-cycles.patch +features/mips/MIPS-Malta-hang-on-halt.patch +features/mips/MIPS-Malta-support-powering-down.patch