Skip to content

Commit ea0d856

Browse files
Gavin Shanmpe
authored andcommitted
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>
1 parent 7e19bf3 commit ea0d856

5 files changed

Lines changed: 115 additions & 1 deletion

File tree

‎arch/powerpc/include/asm/opal-api.h‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@
158158
#define OPAL_LEDS_SET_INDICATOR 115
159159
#define OPAL_CEC_REBOOT2 116
160160
#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
162166

163167
/* Device tree flags */
164168

@@ -344,6 +348,18 @@ enum OpalPciResetState {
344348
OPAL_ASSERT_RESET = 1
345349
};
346350

351+
enum OpalPciSlotPresence {
352+
OPAL_PCI_SLOT_EMPTY = 0,
353+
OPAL_PCI_SLOT_PRESENT = 1
354+
};
355+
356+
enum OpalPciSlotPower {
357+
OPAL_PCI_SLOT_POWER_OFF = 0,
358+
OPAL_PCI_SLOT_POWER_ON = 1,
359+
OPAL_PCI_SLOT_OFFLINE = 2,
360+
OPAL_PCI_SLOT_ONLINE = 3
361+
};
362+
347363
enum OpalSlotLedType {
348364
OPAL_SLOT_LED_TYPE_ID = 0, /* IDENTIFY LED */
349365
OPAL_SLOT_LED_TYPE_FAULT = 1, /* FAULT LED */

‎arch/powerpc/include/asm/opal.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ int64_t opal_flash_write(uint64_t id, uint64_t offset, uint64_t buf,
209209
uint64_t size, uint64_t token);
210210
int64_t opal_flash_erase(uint64_t id, uint64_t offset, uint64_t size,
211211
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);
212218

213219
/* Internal functions */
214220
extern int early_init_dt_scan_opal(unsigned long node, const char *uname,

‎arch/powerpc/include/asm/pnv-pci.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@
1212

1313
#include <linux/pci.h>
1414
#include <misc/cxl-base.h>
15+
#include <asm/opal-api.h>
1516

1617
#define PCI_SLOT_ID_PREFIX 0x8000000000000000
1718
#define PCI_SLOT_ID(phb_id, bdfn) \
1819
(PCI_SLOT_ID_PREFIX | ((uint64_t)(bdfn) << 16) | (phb_id))
1920

2021
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);
2127

2228
int pnv_phb_to_cxl_mode(struct pci_dev *dev, uint64_t mode);
2329
int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,

‎arch/powerpc/platforms/powernv/opal-wrappers.S‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,7 @@ OPAL_CALL(opal_prd_msg, OPAL_PRD_MSG);
302302
OPAL_CALL(opal_leds_get_ind, OPAL_LEDS_GET_INDICATOR);
303303
OPAL_CALL(opal_leds_set_ind, OPAL_LEDS_SET_INDICATOR);
304304
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);

‎arch/powerpc/platforms/powernv/pci.c‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,88 @@ int pnv_pci_get_slot_id(struct device_node *np, uint64_t *id)
7474
}
7575
EXPORT_SYMBOL_GPL(pnv_pci_get_slot_id);
7676

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+
77159
#ifdef CONFIG_PCI_MSI
78160
int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
79161
{

0 commit comments

Comments
 (0)