Message ID | 20190929074651.8787-4-npiggin@gmail.com |
---|---|
State | Superseded |
Headers | show |
Series | little endian skiboot | expand |
Context | Check | Description |
---|---|---|
snowpatch_ozlabs/apply_patch | success | Successfully applied on branch master (470ffb5f29d741c3bed600f7bb7bf0cbb270e05a) |
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot | fail | Test snowpatch/job/snowpatch-skiboot on branch master |
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco | success | Signed-off-by present |
On Sun, 2019-09-29 at 17:46 +1000, Nicholas Piggin wrote: > 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> > --- > core/console.c | 19 ++++++---- > core/interrupts.c | 8 +++-- > core/ipmi-opal.c | 6 ++-- > core/pci-opal.c | 80 +++++++++++++++++++++++++++++++++-------- > core/powercap.c | 12 +++++-- > core/psr.c | 12 +++++-- > core/sensor.c | 32 +++++++++++------ > hw/fake-rtc.c | 9 +++-- > hw/fsp/fsp-console.c | 26 ++++++++------ > hw/fsp/fsp-rtc.c | 20 ++++++----- > hw/ipmi/ipmi-rtc.c | 6 +++- > hw/lpc-rtc.c | 6 +++- > hw/lpc-uart.c | 16 ++++----- > hw/npu2-opencapi.c | 10 ++++-- > hw/xscom.c | 19 ++++++++-- > include/console.h | 6 ++-- > platforms/mambo/mambo.c | 7 +++- > 17 files changed, 213 insertions(+), 81 deletions(-) > > diff --git a/core/console.c b/core/console.c > index 139ba4a97..ac88f0c71 100644 > --- a/core/console.c > +++ b/core/console.c > @@ -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; > @@ -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; > diff --git a/core/interrupts.c b/core/interrupts.c > index 10baa15f6..d4a2c3124 100644 > --- a/core/interrupts.c > +++ b/core/interrupts.c > @@ -439,9 +439,11 @@ 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; > @@ -449,7 +451,9 @@ static int64_t opal_get_xive(uint32_t isn, uint16_t *server, uint8_t *priority) > 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); > > diff --git a/core/ipmi-opal.c b/core/ipmi-opal.c > index 796508ca0..d36962d36 100644 > --- a/core/ipmi-opal.c > +++ b/core/ipmi-opal.c > @@ -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; > @@ -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; > } > @@ -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; > diff --git a/core/pci-opal.c b/core/pci-opal.c > index 213a72565..e0ab3cf91 100644 > --- a/core/pci-opal.c > +++ b/core/pci-opal.c > @@ -58,9 +58,36 @@ 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); > @@ -87,10 +114,11 @@ 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) > @@ -108,7 +136,8 @@ static int64_t opal_pci_eeh_freeze_status(uint64_t phb_id, uint64_t pe_number, > 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; > @@ -371,9 +400,11 @@ 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; I'd rather you kept it consistent and used the __ prefix for the BE output variables rather than the native endian ones. Makes for a less noisy diff too since we can leave the phb->ops.func() call sites as-is. > if (!opal_addr_valid(msi_address) || !opal_addr_valid(message_data)) > @@ -385,18 +416,23 @@ 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)) > @@ -408,9 +444,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); > @@ -820,10 +859,13 @@ 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) || > @@ -837,10 +879,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); > @@ -901,9 +947,10 @@ 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)) > return OPAL_PARAMETER; > @@ -914,8 +961,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); > diff --git a/core/powercap.c b/core/powercap.c > index b9d172b54..cb24e92dc 100644 > --- a/core/powercap.c > +++ b/core/powercap.c > @@ -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)) > 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; > }; > diff --git a/core/psr.c b/core/psr.c > index 4cd3768ae..641c41260 100644 > --- a/core/psr.c > +++ b/core/psr.c > @@ -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)) > 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; > }; > diff --git a/core/sensor.c b/core/sensor.c > index a804f968a..226a5af5e 100644 > --- a/core/sensor.c > +++ b/core/sensor.c > @@ -21,11 +21,11 @@ static LIST_HEAD(async_read_list); > struct sensor_async_read { > struct list_node link; > u64 *sensor_data64; > - u32 *sensor_data32; > + __be32 *sensor_data32; > int token; > }; > > -static int add_to_async_read_list(int token, u32 *data32, u64 *data64) > +static int add_to_async_read_list(int token, __be32 *data32, u64 *data64) > { > struct sensor_async_read *req; > > @@ -59,7 +59,7 @@ void check_sensor_read(int token) > if (!req) > goto out; > > - *req->sensor_data32 = *req->sensor_data64; > + *req->sensor_data32 = cpu_to_be32(*req->sensor_data64); > free(req->sensor_data64); > list_del(&req->link); > free(req); > @@ -67,25 +67,37 @@ out: > unlock(&async_read_list_lock); > } > > -static s64 opal_sensor_read_u64(u32 sensor_hndl, int token, u64 *sensor_data) > +static s64 opal_sensor_read_u64(u32 sensor_hndl, int token, __be64 *sensor_data) > { > + u64 data; > + s64 rc; > + > switch (sensor_get_family(sensor_hndl)) { > case SENSOR_DTS: > - return dts_sensor_read(sensor_hndl, token, sensor_data); > + rc = dts_sensor_read(sensor_hndl, token, &data); > + *sensor_data = cpu_to_be64(data); > + return rc; > + > case SENSOR_OCC: > - return occ_sensor_read(sensor_hndl, sensor_data); > + rc = occ_sensor_read(sensor_hndl, &data); > + *sensor_data = cpu_to_be64(data); > + return rc; > + > default: > break; > } > > - if (platform.sensor_read) > - return platform.sensor_read(sensor_hndl, token, sensor_data); > + if (platform.sensor_read) { > + rc = platform.sensor_read(sensor_hndl, token, &data); > + *sensor_data = cpu_to_be64(data); > + return rc; > + } > > return OPAL_UNSUPPORTED; > } > > static int64_t opal_sensor_read(uint32_t sensor_hndl, int token, > - uint32_t *sensor_data) > + __be32 *sensor_data) > { > u64 *val; > s64 ret; > @@ -96,7 +108,7 @@ static int64_t opal_sensor_read(uint32_t sensor_hndl, int token, > > ret = opal_sensor_read_u64(sensor_hndl, token, val); > if (!ret) { > - *sensor_data = *val; > + *sensor_data = cpu_to_be32(*val); > free(val); > } else if (ret == OPAL_ASYNC_COMPLETION) { > ret = add_to_async_read_list(token, sensor_data, val); > diff --git a/hw/fake-rtc.c b/hw/fake-rtc.c > index 328be97d9..60dd047e9 100644 > --- a/hw/fake-rtc.c > +++ b/hw/fake-rtc.c > @@ -34,11 +34,13 @@ static int64_t fake_rtc_write(uint32_t ymd, uint64_t hmsm) > return OPAL_SUCCESS; > } > > -static int64_t fake_rtc_read(uint32_t *ymd, uint64_t *hmsm) > +static int64_t fake_rtc_read(__be32 *ymd, __be32 *hmsm) > { > > time_t sec; > struct tm tm_calculated; > + uint32_t __ymd; > + uint64_t __hmsm; > > if (!ymd || !hmsm) > return OPAL_PARAMETER; > @@ -48,10 +50,13 @@ static int64_t fake_rtc_read(uint32_t *ymd, uint64_t *hmsm) > > sec = tb_to_secs(mftb() - tb_synctime) + mktime(&tm_offset); > gmtime_r(&sec, &tm_calculated); > - tm_to_datetime(&tm_calculated, ymd, hmsm); > + tm_to_datetime(&tm_calculated, &__ymd, &__hmsm); > > unlock(&emulation_lock); > > + *ymd = cpu_to_be32(__ymd); > + *hmsm = cpu_to_be64(__hmsm); > + > return OPAL_SUCCESS; > } > > diff --git a/hw/fsp/fsp-console.c b/hw/fsp/fsp-console.c > index 42fb98806..bc3284fc1 100644 > --- a/hw/fsp/fsp-console.c > +++ b/hw/fsp/fsp-console.c > @@ -579,7 +579,7 @@ void fsp_console_preinit(void) > > } > > -static int64_t fsp_console_write(int64_t term_number, int64_t *length, > +static int64_t fsp_console_write(int64_t term_number, __be64 *length, > const uint8_t *buffer) > { > struct fsp_serial *fs; > @@ -596,7 +596,7 @@ static int64_t fsp_console_write(int64_t term_number, int64_t *length, > return OPAL_CLOSED; > } > /* Clamp to a reasonable size */ > - requested = *length; > + requested = be64_to_cpu(*length); > if (requested > 0x1000) > requested = 0x1000; > written = fsp_write_vserial(fs, buffer, requested); > @@ -618,7 +618,7 @@ static int64_t fsp_console_write(int64_t term_number, int64_t *length, > buffer[6], buffer[6], buffer[7], buffer[7]); > #endif /* OPAL_DEBUG_CONSOLE_IO */ > > - *length = written; > + *length = cpu_to_be64(written); > unlock(&fsp_con_lock); > > if (written) > @@ -628,11 +628,12 @@ static int64_t fsp_console_write(int64_t term_number, int64_t *length, > } > > static int64_t fsp_console_write_buffer_space(int64_t term_number, > - int64_t *length) > + __be64 *length) > { > static bool elog_generated = false; > struct fsp_serial *fs; > struct fsp_serbuf_hdr *sb; > + int64_t l; > > if (term_number < 0 || term_number >= MAX_SERIAL) > return OPAL_PARAMETER; > @@ -645,15 +646,16 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number, > return OPAL_CLOSED; > } > sb = fs->out_buf; > - *length = (sb->next_out + SER_BUF_DATA_SIZE - sb->next_in - 1) > + l = (sb->next_out + SER_BUF_DATA_SIZE - sb->next_in - 1) > % SER_BUF_DATA_SIZE; > unlock(&fsp_con_lock); > > /* Console buffer has enough space to write incoming data */ > - if (*length != fs->out_buf_prev_len) { > - fs->out_buf_prev_len = *length; > + if (l != fs->out_buf_prev_len) { > + fs->out_buf_prev_len = l; > fs->out_buf_timeout = 0; > > + *length = cpu_to_be64(l); > return OPAL_SUCCESS; > } > > @@ -667,8 +669,10 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number, > secs_to_tb(SER_BUFFER_OUT_TIMEOUT); > } > > - if (tb_compare(mftb(), fs->out_buf_timeout) != TB_AAFTERB) > + if (tb_compare(mftb(), fs->out_buf_timeout) != TB_AAFTERB) { > + *length = cpu_to_be64(l); > return OPAL_SUCCESS; > + } > > /* > * FSP is still active but not reading console data. Hence > @@ -686,13 +690,13 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number, > return OPAL_RESOURCE; > } > > -static int64_t fsp_console_read(int64_t term_number, int64_t *length, > +static int64_t fsp_console_read(int64_t term_number, __be64 *length, > uint8_t *buffer) > { > struct fsp_serial *fs; > struct fsp_serbuf_hdr *sb; > bool pending = false; > - uint32_t old_nin, n, i, chunk, req = *length; > + uint32_t old_nin, n, i, chunk, req = be64_to_cpu(*length); > int rc = OPAL_SUCCESS; > > if (term_number < 0 || term_number >= MAX_SERIAL) > @@ -716,7 +720,7 @@ static int64_t fsp_console_read(int64_t term_number, int64_t *length, > pending = true; > n = req; > } > - *length = n; > + *length = cpu_to_be64(n); > > chunk = SER_BUF_DATA_SIZE - sb->next_out; > if (chunk > n) > diff --git a/hw/fsp/fsp-rtc.c b/hw/fsp/fsp-rtc.c > index 53838f87c..5dd0f14fc 100644 > --- a/hw/fsp/fsp-rtc.c > +++ b/hw/fsp/fsp-rtc.c > @@ -253,6 +253,8 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, > uint64_t *hour_minute_second_millisecond) > { > int64_t rc; > + uint32_t __ymd; > + uint64_t __hmsm; > > if (!year_month_day || !hour_minute_second_millisecond) > return OPAL_PARAMETER; > @@ -267,8 +269,7 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, > /* During R/R of FSP, read cached TOD */ > if (fsp_in_rr()) { > if (rtc_tod_state == RTC_TOD_VALID) { > - rtc_cache_get_datetime(year_month_day, > - hour_minute_second_millisecond); > + rtc_cache_get_datetime(&__ymd, &__hmsm); > rc = OPAL_SUCCESS; > } else { > rc = OPAL_INTERNAL_ERROR; > @@ -290,11 +291,9 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, > opal_rtc_eval_events(true); > > if (rtc_tod_state == RTC_TOD_VALID) { > - rtc_cache_get_datetime(year_month_day, > - hour_minute_second_millisecond); > + rtc_cache_get_datetime(&__ymd, &__hmsm); > prlog(PR_TRACE,"FSP-RTC Cached datetime: %x %llx\n", > - *year_month_day, > - *hour_minute_second_millisecond); > + __ymd, __hmsm); > rc = OPAL_SUCCESS; > } else { > rc = OPAL_INTERNAL_ERROR; > @@ -306,8 +305,7 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, > prlog(PR_TRACE, "RTC read timed out\n"); > > if (rtc_tod_state == RTC_TOD_VALID) { > - rtc_cache_get_datetime(year_month_day, > - hour_minute_second_millisecond); > + rtc_cache_get_datetime(&__ymd, &__hmsm); > rc = OPAL_SUCCESS; > } else { > rc = OPAL_INTERNAL_ERROR; > @@ -319,6 +317,12 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, > } > out: > unlock(&rtc_lock); > + > + if (rc == OPAL_SUCCESS) { > + *year_month_day = cpu_to_be32(__ymd); > + *hour_minute_second_millisecond = cpu_to_be64(__hmsm); > + } > + > return rc; > } > > diff --git a/hw/ipmi/ipmi-rtc.c b/hw/ipmi/ipmi-rtc.c > index deb4addcb..127b3c604 100644 > --- a/hw/ipmi/ipmi-rtc.c > +++ b/hw/ipmi/ipmi-rtc.c > @@ -66,6 +66,8 @@ static int64_t ipmi_opal_rtc_read(uint32_t *y_m_d, > uint64_t *h_m_s_m) > { > int ret = 0; > + uint32_t __ymd; > + uint64_t __hmsm; > > if (!y_m_d || !h_m_s_m) > return OPAL_PARAMETER; > @@ -83,7 +85,9 @@ static int64_t ipmi_opal_rtc_read(uint32_t *y_m_d, > break; > > case updated: > - rtc_cache_get_datetime(y_m_d, h_m_s_m); > + rtc_cache_get_datetime(&__ymd, &__hmsm); > + *y_m_d = cpu_to_be32(__ymd); > + *h_m_s_m = cpu_to_be64(__hmsm); > time_status = idle; > ret = OPAL_SUCCESS; > break; > diff --git a/hw/lpc-rtc.c b/hw/lpc-rtc.c > index f560c8c9f..301a7d872 100644 > --- a/hw/lpc-rtc.c > +++ b/hw/lpc-rtc.c > @@ -145,6 +145,8 @@ static int64_t lpc_opal_rtc_read(uint32_t *y_m_d, > uint8_t val; > int64_t rc = OPAL_SUCCESS; > struct tm tm; > + uint32_t __ymd; > + uint64_t __hmsm; > > if (!y_m_d || !h_m_s_m) > return OPAL_PARAMETER; > @@ -172,7 +174,9 @@ static int64_t lpc_opal_rtc_read(uint32_t *y_m_d, > rtc_cache_update(&tm); > > /* Convert to OPAL time */ > - tm_to_datetime(&tm, y_m_d, h_m_s_m); > + tm_to_datetime(&tm, &__ymd, &__hmsm); > + *y_m_d = cpu_to_be32(__ymd); > + *h_m_s_m = cpu_to_be64(__hmsm); > } > > return rc; > diff --git a/hw/lpc-uart.c b/hw/lpc-uart.c > index feca229b6..51baf4008 100644 > --- a/hw/lpc-uart.c > +++ b/hw/lpc-uart.c > @@ -255,10 +255,10 @@ static uint32_t uart_tx_buf_space(void) > (out_buf_prod + OUT_BUF_SIZE - out_buf_cons) % OUT_BUF_SIZE; > } > > -static int64_t uart_opal_write(int64_t term_number, int64_t *length, > +static int64_t uart_opal_write(int64_t term_number, __be64 *length, > const uint8_t *buffer) > { > - size_t written = 0, len = *length; > + size_t written = 0, len = be64_to_cpu(*length); > > if (term_number != 0) > return OPAL_PARAMETER; > @@ -277,19 +277,19 @@ static int64_t uart_opal_write(int64_t term_number, int64_t *length, > > unlock(&uart_lock); > > - *length = written; > + *length = cpu_to_be64(written); > > return OPAL_SUCCESS; > } > > static int64_t uart_opal_write_buffer_space(int64_t term_number, > - int64_t *length) > + __be64 *length) > { > if (term_number != 0) > return OPAL_PARAMETER; > > lock(&uart_lock); > - *length = uart_tx_buf_space(); > + *length = cpu_to_be64(uart_tx_buf_space()); > unlock(&uart_lock); > > return OPAL_SUCCESS; > @@ -326,10 +326,10 @@ static void uart_adjust_opal_event(void) > } > > /* This is called with the console lock held */ > -static int64_t uart_opal_read(int64_t term_number, int64_t *length, > +static int64_t uart_opal_read(int64_t term_number, __be64 *length, > uint8_t *buffer) > { > - size_t req_count = *length, read_cnt = 0; > + size_t req_count = be64_to_cpu(*length), read_cnt = 0; > uint8_t lsr = 0; > > if (term_number != 0) > @@ -373,7 +373,7 @@ static int64_t uart_opal_read(int64_t term_number, int64_t *length, > /* Adjust the OPAL event */ > uart_adjust_opal_event(); > > - *length = read_cnt; > + *length = cpu_to_be64(read_cnt); > return OPAL_SUCCESS; > } > > diff --git a/hw/npu2-opencapi.c b/hw/npu2-opencapi.c > index 9a391bb01..73ec6f099 100644 > --- a/hw/npu2-opencapi.c > +++ b/hw/npu2-opencapi.c > @@ -2167,10 +2167,12 @@ out: > } > > static int64_t opal_npu_mem_alloc(uint64_t phb_id, uint32_t __unused bdfn, > - uint64_t size, uint64_t *bar) > + uint64_t size, __be64 *bar) > { > struct phb *phb = pci_get_phb(phb_id); > struct npu2_dev *dev; > + uint64_t __bar; > + int64_t rc; > > > if (!phb || phb->phb_type != phb_type_npu_v2_opencapi) > @@ -2183,7 +2185,11 @@ static int64_t opal_npu_mem_alloc(uint64_t phb_id, uint32_t __unused bdfn, > if (!opal_addr_valid(bar)) > return OPAL_PARAMETER; > > - return alloc_mem_bar(dev, size, bar); > + rc = alloc_mem_bar(dev, size, &__bar); > + if (rc == OPAL_SUCCESS) > + *bar = cpu_to_be64(__bar); > + > + return rc; > } > opal_call(OPAL_NPU_MEM_ALLOC, opal_npu_mem_alloc, 4); > > diff --git a/hw/xscom.c b/hw/xscom.c > index 9b28422d2..3f445fc91 100644 > --- a/hw/xscom.c > +++ b/hw/xscom.c > @@ -639,7 +639,17 @@ int _xscom_read(uint32_t partid, uint64_t pcb_addr, uint64_t *val, bool take_loc > return rc; > } > > -opal_call(OPAL_XSCOM_READ, xscom_read, 3); > +static int64_t opal_xscom_read(uint32_t partid, uint64_t pcb_addr, __be64 *val) > +{ > + uint64_t __val; > + int64_t rc; > + > + rc = xscom_read(partid, pcb_addr, &__val); > + *val = cpu_to_be64(__val); > + > + return rc; > +} > +opal_call(OPAL_XSCOM_READ, opal_xscom_read, 3); > > int _xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val, bool take_lock) > { > @@ -683,7 +693,12 @@ int _xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val, bool take_loc > unlock(&xscom_lock); > return rc; > } > -opal_call(OPAL_XSCOM_WRITE, xscom_write, 3); > + > +static int64_t opal_xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val) > +{ > + return xscom_write(partid, pcb_addr, val); > +} > +opal_call(OPAL_XSCOM_WRITE, opal_xscom_write, 3); > > /* > * Perform a xscom read-modify-write. > diff --git a/include/console.h b/include/console.h > index 26602b7ac..a5f7988cc 100644 > --- a/include/console.h > +++ b/include/console.h > @@ -47,13 +47,13 @@ struct opal_con_ops { > */ > void (*init)(void); > > - int64_t (*write)(int64_t term, int64_t *len, const uint8_t *buf); > - int64_t (*read)(int64_t term, int64_t *len, uint8_t *buf); > + int64_t (*write)(int64_t term, __be64 *len, const uint8_t *buf); > + int64_t (*read)(int64_t term, __be64 *len, uint8_t *buf); > > /* > * returns the amount of space available in the console write buffer > */ > - int64_t (*space)(int64_t term_number, int64_t *length); > + int64_t (*space)(int64_t term_number, __be64 *length); > > /* > * Forces the write buffer to be flushed by the driver > diff --git a/platforms/mambo/mambo.c b/platforms/mambo/mambo.c > index e523cd3eb..f33b72d20 100644 > --- a/platforms/mambo/mambo.c > +++ b/platforms/mambo/mambo.c > @@ -178,6 +178,8 @@ static int64_t mambo_rtc_read(uint32_t *ymd, uint64_t *hmsm) > int64_t mambo_time; > struct tm t; > time_t mt; > + uint32_t __ymd; > + uint64_t __hmsm; > > if (!ymd || !hmsm) > return OPAL_PARAMETER; > @@ -185,7 +187,10 @@ static int64_t mambo_rtc_read(uint32_t *ymd, uint64_t *hmsm) > mambo_time = callthru0(SIM_GET_TIME_CODE); > mt = mambo_time >> 32; > gmtime_r(&mt, &t); > - tm_to_datetime(&t, ymd, hmsm); > + tm_to_datetime(&t, &__ymd, &__hmsm); > + > + *ymd = cpu_to_be32(__ymd); > + *hmsm = cpu_to_be64(__hmsm); > > return OPAL_SUCCESS; > }
Oliver O'Halloran's on October 1, 2019 1:14 pm: > On Sun, 2019-09-29 at 17:46 +1000, Nicholas Piggin wrote: >> 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> >> --- >> core/console.c | 19 ++++++---- >> core/interrupts.c | 8 +++-- >> core/ipmi-opal.c | 6 ++-- >> core/pci-opal.c | 80 +++++++++++++++++++++++++++++++++-------- >> core/powercap.c | 12 +++++-- >> core/psr.c | 12 +++++-- >> core/sensor.c | 32 +++++++++++------ >> hw/fake-rtc.c | 9 +++-- >> hw/fsp/fsp-console.c | 26 ++++++++------ >> hw/fsp/fsp-rtc.c | 20 ++++++----- >> hw/ipmi/ipmi-rtc.c | 6 +++- >> hw/lpc-rtc.c | 6 +++- >> hw/lpc-uart.c | 16 ++++----- >> hw/npu2-opencapi.c | 10 ++++-- >> hw/xscom.c | 19 ++++++++-- >> include/console.h | 6 ++-- >> platforms/mambo/mambo.c | 7 +++- >> 17 files changed, 213 insertions(+), 81 deletions(-) >> >> diff --git a/core/console.c b/core/console.c >> index 139ba4a97..ac88f0c71 100644 >> --- a/core/console.c >> +++ b/core/console.c >> @@ -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; >> @@ -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; >> diff --git a/core/interrupts.c b/core/interrupts.c >> index 10baa15f6..d4a2c3124 100644 >> --- a/core/interrupts.c >> +++ b/core/interrupts.c >> @@ -439,9 +439,11 @@ 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; >> @@ -449,7 +451,9 @@ static int64_t opal_get_xive(uint32_t isn, uint16_t *server, uint8_t *priority) >> 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); >> >> diff --git a/core/ipmi-opal.c b/core/ipmi-opal.c >> index 796508ca0..d36962d36 100644 >> --- a/core/ipmi-opal.c >> +++ b/core/ipmi-opal.c >> @@ -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; >> @@ -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; >> } >> @@ -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; >> diff --git a/core/pci-opal.c b/core/pci-opal.c >> index 213a72565..e0ab3cf91 100644 >> --- a/core/pci-opal.c >> +++ b/core/pci-opal.c >> @@ -58,9 +58,36 @@ 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); >> @@ -87,10 +114,11 @@ 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) >> @@ -108,7 +136,8 @@ static int64_t opal_pci_eeh_freeze_status(uint64_t phb_id, uint64_t pe_number, >> 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; >> @@ -371,9 +400,11 @@ 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; > > I'd rather you kept it consistent and used the __ prefix for the BE > output variables rather than the native endian ones. Makes for a less Whatever you prefer. My thought process was the non-prefixed is the acutal OPAL API format, but that may actually be more confusing. Your call so I'll change it. Thanks, Nick
diff --git a/core/console.c b/core/console.c index 139ba4a97..ac88f0c71 100644 --- a/core/console.c +++ b/core/console.c @@ -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; @@ -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; diff --git a/core/interrupts.c b/core/interrupts.c index 10baa15f6..d4a2c3124 100644 --- a/core/interrupts.c +++ b/core/interrupts.c @@ -439,9 +439,11 @@ 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; @@ -449,7 +451,9 @@ static int64_t opal_get_xive(uint32_t isn, uint16_t *server, uint8_t *priority) 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); diff --git a/core/ipmi-opal.c b/core/ipmi-opal.c index 796508ca0..d36962d36 100644 --- a/core/ipmi-opal.c +++ b/core/ipmi-opal.c @@ -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; @@ -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; } @@ -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; diff --git a/core/pci-opal.c b/core/pci-opal.c index 213a72565..e0ab3cf91 100644 --- a/core/pci-opal.c +++ b/core/pci-opal.c @@ -58,9 +58,36 @@ 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); @@ -87,10 +114,11 @@ 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) @@ -108,7 +136,8 @@ static int64_t opal_pci_eeh_freeze_status(uint64_t phb_id, uint64_t pe_number, 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; @@ -371,9 +400,11 @@ 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)) @@ -385,18 +416,23 @@ 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)) @@ -408,9 +444,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); @@ -820,10 +859,13 @@ 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) || @@ -837,10 +879,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); @@ -901,9 +947,10 @@ 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)) return OPAL_PARAMETER; @@ -914,8 +961,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); diff --git a/core/powercap.c b/core/powercap.c index b9d172b54..cb24e92dc 100644 --- a/core/powercap.c +++ b/core/powercap.c @@ -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)) 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; }; diff --git a/core/psr.c b/core/psr.c index 4cd3768ae..641c41260 100644 --- a/core/psr.c +++ b/core/psr.c @@ -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)) 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; }; diff --git a/core/sensor.c b/core/sensor.c index a804f968a..226a5af5e 100644 --- a/core/sensor.c +++ b/core/sensor.c @@ -21,11 +21,11 @@ static LIST_HEAD(async_read_list); struct sensor_async_read { struct list_node link; u64 *sensor_data64; - u32 *sensor_data32; + __be32 *sensor_data32; int token; }; -static int add_to_async_read_list(int token, u32 *data32, u64 *data64) +static int add_to_async_read_list(int token, __be32 *data32, u64 *data64) { struct sensor_async_read *req; @@ -59,7 +59,7 @@ void check_sensor_read(int token) if (!req) goto out; - *req->sensor_data32 = *req->sensor_data64; + *req->sensor_data32 = cpu_to_be32(*req->sensor_data64); free(req->sensor_data64); list_del(&req->link); free(req); @@ -67,25 +67,37 @@ out: unlock(&async_read_list_lock); } -static s64 opal_sensor_read_u64(u32 sensor_hndl, int token, u64 *sensor_data) +static s64 opal_sensor_read_u64(u32 sensor_hndl, int token, __be64 *sensor_data) { + u64 data; + s64 rc; + switch (sensor_get_family(sensor_hndl)) { case SENSOR_DTS: - return dts_sensor_read(sensor_hndl, token, sensor_data); + rc = dts_sensor_read(sensor_hndl, token, &data); + *sensor_data = cpu_to_be64(data); + return rc; + case SENSOR_OCC: - return occ_sensor_read(sensor_hndl, sensor_data); + rc = occ_sensor_read(sensor_hndl, &data); + *sensor_data = cpu_to_be64(data); + return rc; + default: break; } - if (platform.sensor_read) - return platform.sensor_read(sensor_hndl, token, sensor_data); + if (platform.sensor_read) { + rc = platform.sensor_read(sensor_hndl, token, &data); + *sensor_data = cpu_to_be64(data); + return rc; + } return OPAL_UNSUPPORTED; } static int64_t opal_sensor_read(uint32_t sensor_hndl, int token, - uint32_t *sensor_data) + __be32 *sensor_data) { u64 *val; s64 ret; @@ -96,7 +108,7 @@ static int64_t opal_sensor_read(uint32_t sensor_hndl, int token, ret = opal_sensor_read_u64(sensor_hndl, token, val); if (!ret) { - *sensor_data = *val; + *sensor_data = cpu_to_be32(*val); free(val); } else if (ret == OPAL_ASYNC_COMPLETION) { ret = add_to_async_read_list(token, sensor_data, val); diff --git a/hw/fake-rtc.c b/hw/fake-rtc.c index 328be97d9..60dd047e9 100644 --- a/hw/fake-rtc.c +++ b/hw/fake-rtc.c @@ -34,11 +34,13 @@ static int64_t fake_rtc_write(uint32_t ymd, uint64_t hmsm) return OPAL_SUCCESS; } -static int64_t fake_rtc_read(uint32_t *ymd, uint64_t *hmsm) +static int64_t fake_rtc_read(__be32 *ymd, __be32 *hmsm) { time_t sec; struct tm tm_calculated; + uint32_t __ymd; + uint64_t __hmsm; if (!ymd || !hmsm) return OPAL_PARAMETER; @@ -48,10 +50,13 @@ static int64_t fake_rtc_read(uint32_t *ymd, uint64_t *hmsm) sec = tb_to_secs(mftb() - tb_synctime) + mktime(&tm_offset); gmtime_r(&sec, &tm_calculated); - tm_to_datetime(&tm_calculated, ymd, hmsm); + tm_to_datetime(&tm_calculated, &__ymd, &__hmsm); unlock(&emulation_lock); + *ymd = cpu_to_be32(__ymd); + *hmsm = cpu_to_be64(__hmsm); + return OPAL_SUCCESS; } diff --git a/hw/fsp/fsp-console.c b/hw/fsp/fsp-console.c index 42fb98806..bc3284fc1 100644 --- a/hw/fsp/fsp-console.c +++ b/hw/fsp/fsp-console.c @@ -579,7 +579,7 @@ void fsp_console_preinit(void) } -static int64_t fsp_console_write(int64_t term_number, int64_t *length, +static int64_t fsp_console_write(int64_t term_number, __be64 *length, const uint8_t *buffer) { struct fsp_serial *fs; @@ -596,7 +596,7 @@ static int64_t fsp_console_write(int64_t term_number, int64_t *length, return OPAL_CLOSED; } /* Clamp to a reasonable size */ - requested = *length; + requested = be64_to_cpu(*length); if (requested > 0x1000) requested = 0x1000; written = fsp_write_vserial(fs, buffer, requested); @@ -618,7 +618,7 @@ static int64_t fsp_console_write(int64_t term_number, int64_t *length, buffer[6], buffer[6], buffer[7], buffer[7]); #endif /* OPAL_DEBUG_CONSOLE_IO */ - *length = written; + *length = cpu_to_be64(written); unlock(&fsp_con_lock); if (written) @@ -628,11 +628,12 @@ static int64_t fsp_console_write(int64_t term_number, int64_t *length, } static int64_t fsp_console_write_buffer_space(int64_t term_number, - int64_t *length) + __be64 *length) { static bool elog_generated = false; struct fsp_serial *fs; struct fsp_serbuf_hdr *sb; + int64_t l; if (term_number < 0 || term_number >= MAX_SERIAL) return OPAL_PARAMETER; @@ -645,15 +646,16 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number, return OPAL_CLOSED; } sb = fs->out_buf; - *length = (sb->next_out + SER_BUF_DATA_SIZE - sb->next_in - 1) + l = (sb->next_out + SER_BUF_DATA_SIZE - sb->next_in - 1) % SER_BUF_DATA_SIZE; unlock(&fsp_con_lock); /* Console buffer has enough space to write incoming data */ - if (*length != fs->out_buf_prev_len) { - fs->out_buf_prev_len = *length; + if (l != fs->out_buf_prev_len) { + fs->out_buf_prev_len = l; fs->out_buf_timeout = 0; + *length = cpu_to_be64(l); return OPAL_SUCCESS; } @@ -667,8 +669,10 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number, secs_to_tb(SER_BUFFER_OUT_TIMEOUT); } - if (tb_compare(mftb(), fs->out_buf_timeout) != TB_AAFTERB) + if (tb_compare(mftb(), fs->out_buf_timeout) != TB_AAFTERB) { + *length = cpu_to_be64(l); return OPAL_SUCCESS; + } /* * FSP is still active but not reading console data. Hence @@ -686,13 +690,13 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number, return OPAL_RESOURCE; } -static int64_t fsp_console_read(int64_t term_number, int64_t *length, +static int64_t fsp_console_read(int64_t term_number, __be64 *length, uint8_t *buffer) { struct fsp_serial *fs; struct fsp_serbuf_hdr *sb; bool pending = false; - uint32_t old_nin, n, i, chunk, req = *length; + uint32_t old_nin, n, i, chunk, req = be64_to_cpu(*length); int rc = OPAL_SUCCESS; if (term_number < 0 || term_number >= MAX_SERIAL) @@ -716,7 +720,7 @@ static int64_t fsp_console_read(int64_t term_number, int64_t *length, pending = true; n = req; } - *length = n; + *length = cpu_to_be64(n); chunk = SER_BUF_DATA_SIZE - sb->next_out; if (chunk > n) diff --git a/hw/fsp/fsp-rtc.c b/hw/fsp/fsp-rtc.c index 53838f87c..5dd0f14fc 100644 --- a/hw/fsp/fsp-rtc.c +++ b/hw/fsp/fsp-rtc.c @@ -253,6 +253,8 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, uint64_t *hour_minute_second_millisecond) { int64_t rc; + uint32_t __ymd; + uint64_t __hmsm; if (!year_month_day || !hour_minute_second_millisecond) return OPAL_PARAMETER; @@ -267,8 +269,7 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, /* During R/R of FSP, read cached TOD */ if (fsp_in_rr()) { if (rtc_tod_state == RTC_TOD_VALID) { - rtc_cache_get_datetime(year_month_day, - hour_minute_second_millisecond); + rtc_cache_get_datetime(&__ymd, &__hmsm); rc = OPAL_SUCCESS; } else { rc = OPAL_INTERNAL_ERROR; @@ -290,11 +291,9 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, opal_rtc_eval_events(true); if (rtc_tod_state == RTC_TOD_VALID) { - rtc_cache_get_datetime(year_month_day, - hour_minute_second_millisecond); + rtc_cache_get_datetime(&__ymd, &__hmsm); prlog(PR_TRACE,"FSP-RTC Cached datetime: %x %llx\n", - *year_month_day, - *hour_minute_second_millisecond); + __ymd, __hmsm); rc = OPAL_SUCCESS; } else { rc = OPAL_INTERNAL_ERROR; @@ -306,8 +305,7 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, prlog(PR_TRACE, "RTC read timed out\n"); if (rtc_tod_state == RTC_TOD_VALID) { - rtc_cache_get_datetime(year_month_day, - hour_minute_second_millisecond); + rtc_cache_get_datetime(&__ymd, &__hmsm); rc = OPAL_SUCCESS; } else { rc = OPAL_INTERNAL_ERROR; @@ -319,6 +317,12 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, } out: unlock(&rtc_lock); + + if (rc == OPAL_SUCCESS) { + *year_month_day = cpu_to_be32(__ymd); + *hour_minute_second_millisecond = cpu_to_be64(__hmsm); + } + return rc; } diff --git a/hw/ipmi/ipmi-rtc.c b/hw/ipmi/ipmi-rtc.c index deb4addcb..127b3c604 100644 --- a/hw/ipmi/ipmi-rtc.c +++ b/hw/ipmi/ipmi-rtc.c @@ -66,6 +66,8 @@ static int64_t ipmi_opal_rtc_read(uint32_t *y_m_d, uint64_t *h_m_s_m) { int ret = 0; + uint32_t __ymd; + uint64_t __hmsm; if (!y_m_d || !h_m_s_m) return OPAL_PARAMETER; @@ -83,7 +85,9 @@ static int64_t ipmi_opal_rtc_read(uint32_t *y_m_d, break; case updated: - rtc_cache_get_datetime(y_m_d, h_m_s_m); + rtc_cache_get_datetime(&__ymd, &__hmsm); + *y_m_d = cpu_to_be32(__ymd); + *h_m_s_m = cpu_to_be64(__hmsm); time_status = idle; ret = OPAL_SUCCESS; break; diff --git a/hw/lpc-rtc.c b/hw/lpc-rtc.c index f560c8c9f..301a7d872 100644 --- a/hw/lpc-rtc.c +++ b/hw/lpc-rtc.c @@ -145,6 +145,8 @@ static int64_t lpc_opal_rtc_read(uint32_t *y_m_d, uint8_t val; int64_t rc = OPAL_SUCCESS; struct tm tm; + uint32_t __ymd; + uint64_t __hmsm; if (!y_m_d || !h_m_s_m) return OPAL_PARAMETER; @@ -172,7 +174,9 @@ static int64_t lpc_opal_rtc_read(uint32_t *y_m_d, rtc_cache_update(&tm); /* Convert to OPAL time */ - tm_to_datetime(&tm, y_m_d, h_m_s_m); + tm_to_datetime(&tm, &__ymd, &__hmsm); + *y_m_d = cpu_to_be32(__ymd); + *h_m_s_m = cpu_to_be64(__hmsm); } return rc; diff --git a/hw/lpc-uart.c b/hw/lpc-uart.c index feca229b6..51baf4008 100644 --- a/hw/lpc-uart.c +++ b/hw/lpc-uart.c @@ -255,10 +255,10 @@ static uint32_t uart_tx_buf_space(void) (out_buf_prod + OUT_BUF_SIZE - out_buf_cons) % OUT_BUF_SIZE; } -static int64_t uart_opal_write(int64_t term_number, int64_t *length, +static int64_t uart_opal_write(int64_t term_number, __be64 *length, const uint8_t *buffer) { - size_t written = 0, len = *length; + size_t written = 0, len = be64_to_cpu(*length); if (term_number != 0) return OPAL_PARAMETER; @@ -277,19 +277,19 @@ static int64_t uart_opal_write(int64_t term_number, int64_t *length, unlock(&uart_lock); - *length = written; + *length = cpu_to_be64(written); return OPAL_SUCCESS; } static int64_t uart_opal_write_buffer_space(int64_t term_number, - int64_t *length) + __be64 *length) { if (term_number != 0) return OPAL_PARAMETER; lock(&uart_lock); - *length = uart_tx_buf_space(); + *length = cpu_to_be64(uart_tx_buf_space()); unlock(&uart_lock); return OPAL_SUCCESS; @@ -326,10 +326,10 @@ static void uart_adjust_opal_event(void) } /* This is called with the console lock held */ -static int64_t uart_opal_read(int64_t term_number, int64_t *length, +static int64_t uart_opal_read(int64_t term_number, __be64 *length, uint8_t *buffer) { - size_t req_count = *length, read_cnt = 0; + size_t req_count = be64_to_cpu(*length), read_cnt = 0; uint8_t lsr = 0; if (term_number != 0) @@ -373,7 +373,7 @@ static int64_t uart_opal_read(int64_t term_number, int64_t *length, /* Adjust the OPAL event */ uart_adjust_opal_event(); - *length = read_cnt; + *length = cpu_to_be64(read_cnt); return OPAL_SUCCESS; } diff --git a/hw/npu2-opencapi.c b/hw/npu2-opencapi.c index 9a391bb01..73ec6f099 100644 --- a/hw/npu2-opencapi.c +++ b/hw/npu2-opencapi.c @@ -2167,10 +2167,12 @@ out: } static int64_t opal_npu_mem_alloc(uint64_t phb_id, uint32_t __unused bdfn, - uint64_t size, uint64_t *bar) + uint64_t size, __be64 *bar) { struct phb *phb = pci_get_phb(phb_id); struct npu2_dev *dev; + uint64_t __bar; + int64_t rc; if (!phb || phb->phb_type != phb_type_npu_v2_opencapi) @@ -2183,7 +2185,11 @@ static int64_t opal_npu_mem_alloc(uint64_t phb_id, uint32_t __unused bdfn, if (!opal_addr_valid(bar)) return OPAL_PARAMETER; - return alloc_mem_bar(dev, size, bar); + rc = alloc_mem_bar(dev, size, &__bar); + if (rc == OPAL_SUCCESS) + *bar = cpu_to_be64(__bar); + + return rc; } opal_call(OPAL_NPU_MEM_ALLOC, opal_npu_mem_alloc, 4); diff --git a/hw/xscom.c b/hw/xscom.c index 9b28422d2..3f445fc91 100644 --- a/hw/xscom.c +++ b/hw/xscom.c @@ -639,7 +639,17 @@ int _xscom_read(uint32_t partid, uint64_t pcb_addr, uint64_t *val, bool take_loc return rc; } -opal_call(OPAL_XSCOM_READ, xscom_read, 3); +static int64_t opal_xscom_read(uint32_t partid, uint64_t pcb_addr, __be64 *val) +{ + uint64_t __val; + int64_t rc; + + rc = xscom_read(partid, pcb_addr, &__val); + *val = cpu_to_be64(__val); + + return rc; +} +opal_call(OPAL_XSCOM_READ, opal_xscom_read, 3); int _xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val, bool take_lock) { @@ -683,7 +693,12 @@ int _xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val, bool take_loc unlock(&xscom_lock); return rc; } -opal_call(OPAL_XSCOM_WRITE, xscom_write, 3); + +static int64_t opal_xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val) +{ + return xscom_write(partid, pcb_addr, val); +} +opal_call(OPAL_XSCOM_WRITE, opal_xscom_write, 3); /* * Perform a xscom read-modify-write. diff --git a/include/console.h b/include/console.h index 26602b7ac..a5f7988cc 100644 --- a/include/console.h +++ b/include/console.h @@ -47,13 +47,13 @@ struct opal_con_ops { */ void (*init)(void); - int64_t (*write)(int64_t term, int64_t *len, const uint8_t *buf); - int64_t (*read)(int64_t term, int64_t *len, uint8_t *buf); + int64_t (*write)(int64_t term, __be64 *len, const uint8_t *buf); + int64_t (*read)(int64_t term, __be64 *len, uint8_t *buf); /* * returns the amount of space available in the console write buffer */ - int64_t (*space)(int64_t term_number, int64_t *length); + int64_t (*space)(int64_t term_number, __be64 *length); /* * Forces the write buffer to be flushed by the driver diff --git a/platforms/mambo/mambo.c b/platforms/mambo/mambo.c index e523cd3eb..f33b72d20 100644 --- a/platforms/mambo/mambo.c +++ b/platforms/mambo/mambo.c @@ -178,6 +178,8 @@ static int64_t mambo_rtc_read(uint32_t *ymd, uint64_t *hmsm) int64_t mambo_time; struct tm t; time_t mt; + uint32_t __ymd; + uint64_t __hmsm; if (!ymd || !hmsm) return OPAL_PARAMETER; @@ -185,7 +187,10 @@ static int64_t mambo_rtc_read(uint32_t *ymd, uint64_t *hmsm) mambo_time = callthru0(SIM_GET_TIME_CODE); mt = mambo_time >> 32; gmtime_r(&mt, &t); - tm_to_datetime(&t, ymd, hmsm); + tm_to_datetime(&t, &__ymd, &__hmsm); + + *ymd = cpu_to_be32(__ymd); + *hmsm = cpu_to_be64(__hmsm); return OPAL_SUCCESS; }
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> --- core/console.c | 19 ++++++---- core/interrupts.c | 8 +++-- core/ipmi-opal.c | 6 ++-- core/pci-opal.c | 80 +++++++++++++++++++++++++++++++++-------- core/powercap.c | 12 +++++-- core/psr.c | 12 +++++-- core/sensor.c | 32 +++++++++++------ hw/fake-rtc.c | 9 +++-- hw/fsp/fsp-console.c | 26 ++++++++------ hw/fsp/fsp-rtc.c | 20 ++++++----- hw/ipmi/ipmi-rtc.c | 6 +++- hw/lpc-rtc.c | 6 +++- hw/lpc-uart.c | 16 ++++----- hw/npu2-opencapi.c | 10 ++++-- hw/xscom.c | 19 ++++++++-- include/console.h | 6 ++-- platforms/mambo/mambo.c | 7 +++- 17 files changed, 213 insertions(+), 81 deletions(-)