Skip to content

Commit

Permalink
opal-api: add endian conversions to most opal calls
Browse files Browse the repository at this point in the history
This adds missing endian conversions to most calls, sufficient at least
to handle calls from a kernel booting on mambo.

Subsystems requiring more extensive changes (e.g., xive) will be done
with individual changes.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
  • Loading branch information
npiggin authored and oohal committed Dec 16, 2019
1 parent 0ed09ec commit 1b9a449
Show file tree
Hide file tree
Showing 29 changed files with 290 additions and 151 deletions.
19 changes: 13 additions & 6 deletions core/console.c
Expand Up @@ -351,22 +351,25 @@ void memcons_add_properties(void)
* complicated since they can come from the in-memory console (BML) or from the
* internal skiboot console driver.
*/
static int64_t dummy_console_write(int64_t term_number, int64_t *length,
static int64_t dummy_console_write(int64_t term_number, __be64 *length,
const uint8_t *buffer)
{
uint64_t l;

if (term_number != 0)
return OPAL_PARAMETER;

if (!opal_addr_valid(length) || !opal_addr_valid(buffer))
return OPAL_PARAMETER;

write(0, buffer, *length);
l = be64_to_cpu(*length);
write(0, buffer, l);

return OPAL_SUCCESS;
}

static int64_t dummy_console_write_buffer_space(int64_t term_number,
int64_t *length)
__be64 *length)
{
if (term_number != 0)
return OPAL_PARAMETER;
Expand All @@ -375,21 +378,25 @@ static int64_t dummy_console_write_buffer_space(int64_t term_number,
return OPAL_PARAMETER;

if (length)
*length = INMEM_CON_OUT_LEN;
*length = cpu_to_be64(INMEM_CON_OUT_LEN);

return OPAL_SUCCESS;
}

static int64_t dummy_console_read(int64_t term_number, int64_t *length,
static int64_t dummy_console_read(int64_t term_number, __be64 *length,
uint8_t *buffer)
{
uint64_t l;

if (term_number != 0)
return OPAL_PARAMETER;

if (!opal_addr_valid(length) || !opal_addr_valid(buffer))
return OPAL_PARAMETER;

*length = read(0, buffer, *length);
l = be64_to_cpu(*length);
l = read(0, buffer, l);
*length = cpu_to_be64(l);
opal_update_pending_evt(OPAL_EVENT_CONSOLE_INPUT, 0);

return OPAL_SUCCESS;
Expand Down
8 changes: 6 additions & 2 deletions core/interrupts.c
Expand Up @@ -439,17 +439,21 @@ static int64_t opal_set_xive(uint32_t isn, uint16_t server, uint8_t priority)
}
opal_call(OPAL_SET_XIVE, opal_set_xive, 3);

static int64_t opal_get_xive(uint32_t isn, uint16_t *server, uint8_t *priority)
static int64_t opal_get_xive(uint32_t isn, __be16 *server, uint8_t *priority)
{
struct irq_source *is = irq_find_source(isn);
uint16_t s;
int64_t ret;

if (!opal_addr_valid(server))
return OPAL_PARAMETER;

if (!is || !is->ops->get_xive)
return OPAL_PARAMETER;

return is->ops->get_xive(is, isn, server, priority);
ret = is->ops->get_xive(is, isn, &s, priority);
*server = cpu_to_be16(s);
return ret;
}
opal_call(OPAL_GET_XIVE, opal_get_xive, 3);

Expand Down
6 changes: 3 additions & 3 deletions core/ipmi-opal.c
Expand Up @@ -57,7 +57,7 @@ static int64_t opal_ipmi_send(uint64_t interface,
}

static int64_t opal_ipmi_recv(uint64_t interface,
struct opal_ipmi_msg *opal_ipmi_msg, uint64_t *msg_len)
struct opal_ipmi_msg *opal_ipmi_msg, __be64 *msg_len)
{
struct ipmi_msg *msg;
int64_t rc;
Expand All @@ -82,7 +82,7 @@ static int64_t opal_ipmi_recv(uint64_t interface,
goto out_del_msg;
}

if (*msg_len - sizeof(struct opal_ipmi_msg) < msg->resp_size + 1) {
if (be64_to_cpu(*msg_len) - sizeof(struct opal_ipmi_msg) < msg->resp_size + 1) {
rc = OPAL_RESOURCE;
goto out_del_msg;
}
Expand All @@ -101,7 +101,7 @@ static int64_t opal_ipmi_recv(uint64_t interface,
msg->cmd, msg->netfn >> 2, msg->resp_size);

/* Add one as the completion code is returned in the message data */
*msg_len = msg->resp_size + sizeof(struct opal_ipmi_msg) + 1;
*msg_len = cpu_to_be64(msg->resp_size + sizeof(struct opal_ipmi_msg) + 1);
ipmi_free_msg(msg);

return OPAL_SUCCESS;
Expand Down
100 changes: 76 additions & 24 deletions core/pci-opal.c
Expand Up @@ -58,9 +58,38 @@ OPAL_PCICFG_ACCESS_WRITE(write_byte, write8, uint8_t)
OPAL_PCICFG_ACCESS_WRITE(write_half_word, write16, uint16_t)
OPAL_PCICFG_ACCESS_WRITE(write_word, write32, uint32_t)

static int64_t opal_pci_config_read_half_word_be(uint64_t phb_id,
uint64_t bus_dev_func,
uint64_t offset,
__be16 *__data)
{
uint16_t data;
int64_t rc;

rc = opal_pci_config_read_half_word(phb_id, bus_dev_func, offset, &data);
*__data = cpu_to_be16(data);

return rc;
}

static int64_t opal_pci_config_read_word_be(uint64_t phb_id,
uint64_t bus_dev_func,
uint64_t offset,
__be32 *__data)
{
uint32_t data;
int64_t rc;

rc = opal_pci_config_read_word(phb_id, bus_dev_func, offset, &data);
*__data = cpu_to_be32(data);

return rc;
}


opal_call(OPAL_PCI_CONFIG_READ_BYTE, opal_pci_config_read_byte, 4);
opal_call(OPAL_PCI_CONFIG_READ_HALF_WORD, opal_pci_config_read_half_word, 4);
opal_call(OPAL_PCI_CONFIG_READ_WORD, opal_pci_config_read_word, 4);
opal_call(OPAL_PCI_CONFIG_READ_HALF_WORD, opal_pci_config_read_half_word_be, 4);
opal_call(OPAL_PCI_CONFIG_READ_WORD, opal_pci_config_read_word_be, 4);
opal_call(OPAL_PCI_CONFIG_WRITE_BYTE, opal_pci_config_write_byte, 4);
opal_call(OPAL_PCI_CONFIG_WRITE_HALF_WORD, opal_pci_config_write_half_word, 4);
opal_call(OPAL_PCI_CONFIG_WRITE_WORD, opal_pci_config_write_word, 4);
Expand All @@ -87,14 +116,15 @@ void opal_pci_eeh_clear_evt(uint64_t phb_id)

static int64_t opal_pci_eeh_freeze_status(uint64_t phb_id, uint64_t pe_number,
uint8_t *freeze_state,
uint16_t *pci_error_type,
uint64_t *phb_status)
__be16 *__pci_error_type,
__be64 *__phb_status)
{
struct phb *phb = pci_get_phb(phb_id);
uint16_t pci_error_type;
int64_t rc;

if (!opal_addr_valid(freeze_state) || !opal_addr_valid(pci_error_type)
|| !opal_addr_valid(phb_status))
if (!opal_addr_valid(freeze_state) || !opal_addr_valid(__pci_error_type)
|| !opal_addr_valid(__phb_status))
return OPAL_PARAMETER;

if (!phb)
Expand All @@ -103,12 +133,13 @@ static int64_t opal_pci_eeh_freeze_status(uint64_t phb_id, uint64_t pe_number,
return OPAL_UNSUPPORTED;
phb_lock(phb);

if (phb_status)
if (__phb_status)
prlog(PR_ERR, "PHB#%04llx: %s: deprecated PHB status\n",
phb_id, __func__);

rc = phb->ops->eeh_freeze_status(phb, pe_number, freeze_state,
pci_error_type, NULL);
&pci_error_type, NULL);
*__pci_error_type = cpu_to_be16(pci_error_type);
phb_unlock(phb);

return rc;
Expand Down Expand Up @@ -371,12 +402,14 @@ opal_call(OPAL_PCI_SET_XIVE_PE, opal_pci_set_xive_pe, 3);

static int64_t opal_get_msi_32(uint64_t phb_id, uint32_t mve_number,
uint32_t xive_num, uint8_t msi_range,
uint32_t *msi_address, uint32_t *message_data)
__be32 *__msi_address, __be32 *__message_data)
{
struct phb *phb = pci_get_phb(phb_id);
uint32_t msi_address;
uint32_t message_data;
int64_t rc;

if (!opal_addr_valid(msi_address) || !opal_addr_valid(message_data))
if (!opal_addr_valid(__msi_address) || !opal_addr_valid(__message_data))
return OPAL_PARAMETER;

if (!phb)
Expand All @@ -385,21 +418,26 @@ static int64_t opal_get_msi_32(uint64_t phb_id, uint32_t mve_number,
return OPAL_UNSUPPORTED;
phb_lock(phb);
rc = phb->ops->get_msi_32(phb, mve_number, xive_num, msi_range,
msi_address, message_data);
&msi_address, &message_data);
phb_unlock(phb);

*__msi_address = cpu_to_be32(msi_address);
*__message_data = cpu_to_be32(message_data);

return rc;
}
opal_call(OPAL_GET_MSI_32, opal_get_msi_32, 6);

static int64_t opal_get_msi_64(uint64_t phb_id, uint32_t mve_number,
uint32_t xive_num, uint8_t msi_range,
uint64_t *msi_address, uint32_t *message_data)
__be64 *__msi_address, __be32 *__message_data)
{
struct phb *phb = pci_get_phb(phb_id);
uint64_t msi_address;
uint32_t message_data;
int64_t rc;

if (!opal_addr_valid(msi_address) || !opal_addr_valid(message_data))
if (!opal_addr_valid(__msi_address) || !opal_addr_valid(__message_data))
return OPAL_PARAMETER;

if (!phb)
Expand All @@ -408,9 +446,12 @@ static int64_t opal_get_msi_64(uint64_t phb_id, uint32_t mve_number,
return OPAL_UNSUPPORTED;
phb_lock(phb);
rc = phb->ops->get_msi_64(phb, mve_number, xive_num, msi_range,
msi_address, message_data);
&msi_address, &message_data);
phb_unlock(phb);

*__msi_address = cpu_to_be64(msi_address);
*__message_data = cpu_to_be32(message_data);

return rc;
}
opal_call(OPAL_GET_MSI_64, opal_get_msi_64, 6);
Expand Down Expand Up @@ -482,7 +523,7 @@ static int64_t opal_phb_set_option(uint64_t phb_id, uint64_t opt,
opal_call(OPAL_PHB_SET_OPTION, opal_phb_set_option, 3);

static int64_t opal_phb_get_option(uint64_t phb_id, uint64_t opt,
uint64_t *setting)
__be64 *setting)
{
struct phb *phb = pci_get_phb(phb_id);
int64_t rc;
Expand Down Expand Up @@ -958,14 +999,17 @@ static int64_t opal_pci_get_phb_diag_data2(uint64_t phb_id,
}
opal_call(OPAL_PCI_GET_PHB_DIAG_DATA2, opal_pci_get_phb_diag_data2, 3);

static int64_t opal_pci_next_error(uint64_t phb_id, uint64_t *first_frozen_pe,
uint16_t *pci_error_type, uint16_t *severity)
static int64_t opal_pci_next_error(uint64_t phb_id, __be64 *__first_frozen_pe,
__be16 *__pci_error_type, __be16 *__severity)
{
struct phb *phb = pci_get_phb(phb_id);
uint64_t first_frozen_pe;
uint16_t pci_error_type;
uint16_t severity;
int64_t rc;

if (!opal_addr_valid(first_frozen_pe) ||
!opal_addr_valid(pci_error_type) || !opal_addr_valid(severity))
if (!opal_addr_valid(__first_frozen_pe) ||
!opal_addr_valid(__pci_error_type) || !opal_addr_valid(__severity))
return OPAL_PARAMETER;

if (!phb)
Expand All @@ -975,10 +1019,14 @@ static int64_t opal_pci_next_error(uint64_t phb_id, uint64_t *first_frozen_pe,
phb_lock(phb);

opal_pci_eeh_clear_evt(phb_id);
rc = phb->ops->next_error(phb, first_frozen_pe, pci_error_type,
severity);
rc = phb->ops->next_error(phb, &first_frozen_pe, &pci_error_type,
&severity);
phb_unlock(phb);

*__first_frozen_pe = cpu_to_be64(first_frozen_pe);
*__pci_error_type = cpu_to_be16(pci_error_type);
*__severity = cpu_to_be16(severity);

return rc;
}
opal_call(OPAL_PCI_NEXT_ERROR, opal_pci_next_error, 4);
Expand Down Expand Up @@ -1039,11 +1087,12 @@ static int64_t opal_pci_set_p2p(uint64_t phbid_init, uint64_t phbid_target,
}
opal_call(OPAL_PCI_SET_P2P, opal_pci_set_p2p, 4);

static int64_t opal_pci_get_pbcq_tunnel_bar(uint64_t phb_id, uint64_t *addr)
static int64_t opal_pci_get_pbcq_tunnel_bar(uint64_t phb_id, __be64 *__addr)
{
struct phb *phb = pci_get_phb(phb_id);
uint64_t addr;

if (!opal_addr_valid(addr))
if (!opal_addr_valid(__addr))
return OPAL_PARAMETER;

if (!phb)
Expand All @@ -1052,8 +1101,11 @@ static int64_t opal_pci_get_pbcq_tunnel_bar(uint64_t phb_id, uint64_t *addr)
return OPAL_UNSUPPORTED;

phb_lock(phb);
phb->ops->get_tunnel_bar(phb, addr);
phb->ops->get_tunnel_bar(phb, &addr);
phb_unlock(phb);

*__addr = cpu_to_be64(addr);

return OPAL_SUCCESS;
}
opal_call(OPAL_PCI_GET_PBCQ_TUNNEL_BAR, opal_pci_get_pbcq_tunnel_bar, 2);
Expand Down
14 changes: 10 additions & 4 deletions core/powercap.c
Expand Up @@ -7,13 +7,19 @@

#include <powercap.h>

static int opal_get_powercap(u32 handle, int token __unused, u32 *pcap)
static int opal_get_powercap(u32 handle, int token __unused, __be32 *__pcap)
{
if (!pcap || !opal_addr_valid(pcap))
if (!__pcap || !opal_addr_valid(__pcap))
return OPAL_PARAMETER;

if (powercap_get_class(handle) == POWERCAP_CLASS_OCC)
return occ_get_powercap(handle, pcap);
if (powercap_get_class(handle) == POWERCAP_CLASS_OCC) {
u32 pcap;
int rc;

rc = occ_get_powercap(handle, &pcap);
*__pcap = cpu_to_be32(pcap);
return rc;
}

return OPAL_UNSUPPORTED;
};
Expand Down
14 changes: 10 additions & 4 deletions core/psr.c
Expand Up @@ -10,13 +10,19 @@
#include <psr.h>

static int opal_get_power_shift_ratio(u32 handle, int token __unused,
u32 *ratio)
__be32 *__ratio)
{
if (!ratio || !opal_addr_valid(ratio))
if (!__ratio || !opal_addr_valid(__ratio))
return OPAL_PARAMETER;

if (psr_get_class(handle) == PSR_CLASS_OCC)
return occ_get_psr(handle, ratio);
if (psr_get_class(handle) == PSR_CLASS_OCC) {
u32 ratio;
int rc;

rc = occ_get_psr(handle, &ratio);
*__ratio = cpu_to_be32(ratio);
return rc;
}

return OPAL_UNSUPPORTED;
};
Expand Down

0 comments on commit 1b9a449

Please sign in to comment.