Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/powernv: Functions to get/set PCI slot state

This exports 4 functions, which base on the corresponding OPAL
APIs to get/set PCI slot status. Those functions are going to
be used by PowerNV PCI hotplug driver:

pnv_pci_get_device_tree() opal_get_device_tree()
pnv_pci_get_presence_state() opal_pci_get_presence_state()
pnv_pci_get_power_state() opal_pci_get_power_state()
pnv_pci_set_power_state() opal_pci_set_power_state()

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Gavin Shan and committed by
Michael Ellerman
ea0d856c 7e19bf32

+115 -1
+17 -1
arch/powerpc/include/asm/opal-api.h
··· 158 158 #define OPAL_LEDS_SET_INDICATOR 115 159 159 #define OPAL_CEC_REBOOT2 116 160 160 #define OPAL_CONSOLE_FLUSH 117 161 - #define OPAL_LAST 117 161 + #define OPAL_GET_DEVICE_TREE 118 162 + #define OPAL_PCI_GET_PRESENCE_STATE 119 163 + #define OPAL_PCI_GET_POWER_STATE 120 164 + #define OPAL_PCI_SET_POWER_STATE 121 165 + #define OPAL_LAST 121 162 166 163 167 /* Device tree flags */ 164 168 ··· 346 342 enum OpalPciResetState { 347 343 OPAL_DEASSERT_RESET = 0, 348 344 OPAL_ASSERT_RESET = 1 345 + }; 346 + 347 + enum OpalPciSlotPresence { 348 + OPAL_PCI_SLOT_EMPTY = 0, 349 + OPAL_PCI_SLOT_PRESENT = 1 350 + }; 351 + 352 + enum OpalPciSlotPower { 353 + OPAL_PCI_SLOT_POWER_OFF = 0, 354 + OPAL_PCI_SLOT_POWER_ON = 1, 355 + OPAL_PCI_SLOT_OFFLINE = 2, 356 + OPAL_PCI_SLOT_ONLINE = 3 349 357 }; 350 358 351 359 enum OpalSlotLedType {
+6
arch/powerpc/include/asm/opal.h
··· 209 209 uint64_t size, uint64_t token); 210 210 int64_t opal_flash_erase(uint64_t id, uint64_t offset, uint64_t size, 211 211 uint64_t token); 212 + int64_t opal_get_device_tree(uint32_t phandle, uint64_t buf, uint64_t len); 213 + int64_t opal_pci_get_presence_state(uint64_t id, uint64_t data); 214 + int64_t opal_pci_get_power_state(uint64_t id, uint64_t data); 215 + int64_t opal_pci_set_power_state(uint64_t async_token, uint64_t id, 216 + uint64_t data); 217 + int64_t opal_pci_poll2(uint64_t id, uint64_t data); 212 218 213 219 /* Internal functions */ 214 220 extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
+6
arch/powerpc/include/asm/pnv-pci.h
··· 12 12 13 13 #include <linux/pci.h> 14 14 #include <misc/cxl-base.h> 15 + #include <asm/opal-api.h> 15 16 16 17 #define PCI_SLOT_ID_PREFIX 0x8000000000000000 17 18 #define PCI_SLOT_ID(phb_id, bdfn) \ 18 19 (PCI_SLOT_ID_PREFIX | ((uint64_t)(bdfn) << 16) | (phb_id)) 19 20 20 21 extern int pnv_pci_get_slot_id(struct device_node *np, uint64_t *id); 22 + extern int pnv_pci_get_device_tree(uint32_t phandle, void *buf, uint64_t len); 23 + extern int pnv_pci_get_presence_state(uint64_t id, uint8_t *state); 24 + extern int pnv_pci_get_power_state(uint64_t id, uint8_t *state); 25 + extern int pnv_pci_set_power_state(uint64_t id, uint8_t state, 26 + struct opal_msg *msg); 21 27 22 28 int pnv_phb_to_cxl_mode(struct pci_dev *dev, uint64_t mode); 23 29 int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,
+4
arch/powerpc/platforms/powernv/opal-wrappers.S
··· 302 302 OPAL_CALL(opal_leds_get_ind, OPAL_LEDS_GET_INDICATOR); 303 303 OPAL_CALL(opal_leds_set_ind, OPAL_LEDS_SET_INDICATOR); 304 304 OPAL_CALL(opal_console_flush, OPAL_CONSOLE_FLUSH); 305 + OPAL_CALL(opal_get_device_tree, OPAL_GET_DEVICE_TREE); 306 + OPAL_CALL(opal_pci_get_presence_state, OPAL_PCI_GET_PRESENCE_STATE); 307 + OPAL_CALL(opal_pci_get_power_state, OPAL_PCI_GET_POWER_STATE); 308 + OPAL_CALL(opal_pci_set_power_state, OPAL_PCI_SET_POWER_STATE);
+82
arch/powerpc/platforms/powernv/pci.c
··· 74 74 } 75 75 EXPORT_SYMBOL_GPL(pnv_pci_get_slot_id); 76 76 77 + int pnv_pci_get_device_tree(uint32_t phandle, void *buf, uint64_t len) 78 + { 79 + int64_t rc; 80 + 81 + if (!opal_check_token(OPAL_GET_DEVICE_TREE)) 82 + return -ENXIO; 83 + 84 + rc = opal_get_device_tree(phandle, (uint64_t)buf, len); 85 + if (rc < OPAL_SUCCESS) 86 + return -EIO; 87 + 88 + return rc; 89 + } 90 + EXPORT_SYMBOL_GPL(pnv_pci_get_device_tree); 91 + 92 + int pnv_pci_get_presence_state(uint64_t id, uint8_t *state) 93 + { 94 + int64_t rc; 95 + 96 + if (!opal_check_token(OPAL_PCI_GET_PRESENCE_STATE)) 97 + return -ENXIO; 98 + 99 + rc = opal_pci_get_presence_state(id, (uint64_t)state); 100 + if (rc != OPAL_SUCCESS) 101 + return -EIO; 102 + 103 + return 0; 104 + } 105 + EXPORT_SYMBOL_GPL(pnv_pci_get_presence_state); 106 + 107 + int pnv_pci_get_power_state(uint64_t id, uint8_t *state) 108 + { 109 + int64_t rc; 110 + 111 + if (!opal_check_token(OPAL_PCI_GET_POWER_STATE)) 112 + return -ENXIO; 113 + 114 + rc = opal_pci_get_power_state(id, (uint64_t)state); 115 + if (rc != OPAL_SUCCESS) 116 + return -EIO; 117 + 118 + return 0; 119 + } 120 + EXPORT_SYMBOL_GPL(pnv_pci_get_power_state); 121 + 122 + int pnv_pci_set_power_state(uint64_t id, uint8_t state, struct opal_msg *msg) 123 + { 124 + struct opal_msg m; 125 + int token, ret; 126 + int64_t rc; 127 + 128 + if (!opal_check_token(OPAL_PCI_SET_POWER_STATE)) 129 + return -ENXIO; 130 + 131 + token = opal_async_get_token_interruptible(); 132 + if (unlikely(token < 0)) 133 + return token; 134 + 135 + rc = opal_pci_set_power_state(token, id, (uint64_t)&state); 136 + if (rc == OPAL_SUCCESS) { 137 + ret = 0; 138 + goto exit; 139 + } else if (rc != OPAL_ASYNC_COMPLETION) { 140 + ret = -EIO; 141 + goto exit; 142 + } 143 + 144 + ret = opal_async_wait_response(token, &m); 145 + if (ret < 0) 146 + goto exit; 147 + 148 + if (msg) { 149 + ret = 1; 150 + memcpy(msg, &m, sizeof(m)); 151 + } 152 + 153 + exit: 154 + opal_async_release_token(token); 155 + return ret; 156 + } 157 + EXPORT_SYMBOL_GPL(pnv_pci_set_power_state); 158 + 77 159 #ifdef CONFIG_PCI_MSI 78 160 int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) 79 161 {