Skip to content

Commit

Permalink
platform: Restructure bmc_platform type
Browse files Browse the repository at this point in the history
Segregate the BMC platform configuration into hardware and software
components. This allows population of platform default values for
hardware configuration that may no-longer be accessible by the host.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
[stewart: fixup pci-quirk unit test]
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
  • Loading branch information
amboar authored and stewartsmith committed Oct 11, 2018
1 parent dd554ba commit 9a830ee
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 49 deletions.
21 changes: 17 additions & 4 deletions core/pci-quirk.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
* limitations under the License.
*/

#define pr_fmt(fmt) "PCI-QUIRK: " fmt

#include <skiboot.h>
#include <pci.h>
#include <pci-quirk.h>
#include <platform.h>
#include <ast.h>

static void quirk_astbmc_vga(struct phb *phb __unused,
Expand All @@ -25,10 +28,20 @@ static void quirk_astbmc_vga(struct phb *phb __unused,
struct dt_node *np = pd->dn;
uint32_t revision, mcr_configuration, mcr_scu_mpll, mcr_scu_strap;

revision = ast_ahb_readl(SCU_REVISION_ID);
mcr_configuration = ast_ahb_readl(MCR_CONFIGURATION);
mcr_scu_mpll = ast_ahb_readl(MCR_SCU_MPLL);
mcr_scu_strap = ast_ahb_readl(MCR_SCU_STRAP);
if (ast_sio_is_enabled()) {
revision = ast_ahb_readl(SCU_REVISION_ID);
mcr_configuration = ast_ahb_readl(MCR_CONFIGURATION);
mcr_scu_mpll = ast_ahb_readl(MCR_SCU_MPLL);
mcr_scu_strap = ast_ahb_readl(MCR_SCU_STRAP);
} else {
prlog(PR_WARNING, "Assumed platform default parameters for %s\n",
__func__);
revision = bmc_platform->hw->scu_revision_id;
mcr_configuration = bmc_platform->hw->mcr_configuration;
mcr_scu_mpll = bmc_platform->hw->mcr_scu_mpll;
mcr_scu_strap = bmc_platform->hw->mcr_scu_strap;
}

dt_add_property_cells(np, "aspeed,scu-revision-id", revision);
dt_add_property_cells(np, "aspeed,mcr-configuration", mcr_configuration);
dt_add_property_cells(np, "aspeed,mcr-scu-mpll", mcr_scu_mpll);
Expand Down
8 changes: 8 additions & 0 deletions core/test/run-pci-quirk.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
struct dt_property;
struct dt_node;

static struct bmc_platform fake_bmc;
const struct bmc_platform *bmc_platform = &fake_bmc;

static int ast_sio_is_enabled(void)
{
return 0;
}

static uint32_t ast_ahb_readl(uint32_t reg)
{
return reg;
Expand Down
2 changes: 1 addition & 1 deletion hw/ast-bmc/ast-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static void ast_setup_sio_irq_polarity(void)
bmc_sio_put(true);
}

static bool ast_sio_is_enabled(void)
bool ast_sio_is_enabled(void)
{
int64_t rc;

Expand Down
8 changes: 4 additions & 4 deletions hw/ipmi/ipmi-sel.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ static void ipmi_elog_poll(struct ipmi_msg *msg)
struct errorlog *elog_buf = (struct errorlog *) msg->user_data;
size_t req_size;

if (bmc_platform->ipmi_oem_partial_add_esel == 0) {
if (bmc_platform->sw->ipmi_oem_partial_add_esel == 0) {
prlog(PR_WARNING, "Dropped eSEL: BMC code is buggy/missing\n");
return;
}
Expand Down Expand Up @@ -392,7 +392,7 @@ static void ipmi_elog_poll(struct ipmi_msg *msg)
}

ipmi_init_msg(msg, IPMI_DEFAULT_INTERFACE,
bmc_platform->ipmi_oem_partial_add_esel,
bmc_platform->sw->ipmi_oem_partial_add_esel,
ipmi_elog_poll, elog_buf, req_size, 2);

msg->data[0] = reservation_id & 0xff;
Expand Down Expand Up @@ -464,7 +464,7 @@ static void sel_pnor(uint8_t access, void *context __unused)
switch (access) {
case REQUEST_PNOR:
prlog(PR_NOTICE, "PNOR access requested\n");
if (bmc_platform->ipmi_oem_pnor_access_status == 0) {
if (bmc_platform->sw->ipmi_oem_pnor_access_status == 0) {
/**
* @fwts-label PNORAccessYeahButNoBut
* @fwts-advice OPAL doesn't know that the BMC supports
Expand All @@ -479,7 +479,7 @@ static void sel_pnor(uint8_t access, void *context __unused)
if (granted)
occ_pnor_set_owner(PNOR_OWNER_EXTERNAL);
/* Ack the request */
msg = ipmi_mkmsg_simple(bmc_platform->ipmi_oem_pnor_access_status, &granted, 1);
msg = ipmi_mkmsg_simple(bmc_platform->sw->ipmi_oem_pnor_access_status, &granted, 1);
ipmi_queue_msg(msg);
break;
case RELEASE_PNOR:
Expand Down
1 change: 1 addition & 0 deletions include/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
void ast_ahb_writel(uint32_t val, uint32_t reg);
uint32_t ast_ahb_readl(uint32_t reg);

bool ast_sio_is_enabled(void);
bool ast_sio_init(void);
bool ast_io_init(void);
bool ast_io_is_rw(void);
Expand Down
16 changes: 14 additions & 2 deletions include/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ enum resource_id {
#define RESOURCE_SUBID_NONE 0
#define RESOURCE_SUBID_SUPPORTED 1

struct bmc_platform {
const char *name;

struct bmc_hw_config {
uint32_t scu_revision_id;
uint32_t mcr_configuration;
uint32_t mcr_scu_mpll;
uint32_t mcr_scu_strap;
};

struct bmc_sw_config {
/*
* Map IPMI_OEM_X to vendor commands for this BMC
* 0 = unimplimented
Expand All @@ -46,6 +52,12 @@ struct bmc_platform {
uint32_t ipmi_oem_hiomap_cmd;
};

struct bmc_platform {
const char *name;
const struct bmc_hw_config *hw;
const struct bmc_sw_config *sw;
};

/* OpenCAPI platform-specific I2C information */
struct platform_ocapi {
uint8_t i2c_engine; /* I2C engine number */
Expand Down
31 changes: 16 additions & 15 deletions libflash/ipmi-hiomap.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ static bool hiomap_get_info(struct ipmi_hiomap *ctx)
req[2] = HIOMAP_V2;

msg = ipmi_mkmsg(IPMI_DEFAULT_INTERFACE,
bmc_platform->ipmi_oem_hiomap_cmd, ipmi_hiomap_cmd_cb,
&res, req, sizeof(req), 6);
bmc_platform->sw->ipmi_oem_hiomap_cmd,
ipmi_hiomap_cmd_cb, &res, req, sizeof(req), 6);
ipmi_queue_msg_sync(msg);

if (res.cc != IPMI_CC_NO_ERROR) {
Expand All @@ -251,8 +251,8 @@ static bool hiomap_get_flash_info(struct ipmi_hiomap *ctx)
req[0] = HIOMAP_C_GET_FLASH_INFO;
req[1] = ++ctx->seq;
msg = ipmi_mkmsg(IPMI_DEFAULT_INTERFACE,
bmc_platform->ipmi_oem_hiomap_cmd, ipmi_hiomap_cmd_cb,
&res, req, sizeof(req), 2 + 2 + 2);
bmc_platform->sw->ipmi_oem_hiomap_cmd,
ipmi_hiomap_cmd_cb, &res, req, sizeof(req), 2 + 2 + 2);
ipmi_queue_msg_sync(msg);

if (res.cc != IPMI_CC_NO_ERROR) {
Expand Down Expand Up @@ -294,8 +294,9 @@ static bool hiomap_window_move(struct ipmi_hiomap *ctx, uint8_t command,
unlock(&ctx->lock);

msg = ipmi_mkmsg(IPMI_DEFAULT_INTERFACE,
bmc_platform->ipmi_oem_hiomap_cmd, ipmi_hiomap_cmd_cb,
&res, req, sizeof(req), 2 + 2 + 2 + 2);
bmc_platform->sw->ipmi_oem_hiomap_cmd,
ipmi_hiomap_cmd_cb, &res, req, sizeof(req),
2 + 2 + 2 + 2);
ipmi_queue_msg_sync(msg);

if (res.cc != IPMI_CC_NO_ERROR) {
Expand Down Expand Up @@ -348,8 +349,8 @@ static bool hiomap_mark_dirty(struct ipmi_hiomap *ctx, uint64_t offset,
range->size = cpu_to_le16(bytes_to_blocks(ctx, size));

msg = ipmi_mkmsg(IPMI_DEFAULT_INTERFACE,
bmc_platform->ipmi_oem_hiomap_cmd, ipmi_hiomap_cmd_cb,
&res, req, sizeof(req), 2);
bmc_platform->sw->ipmi_oem_hiomap_cmd,
ipmi_hiomap_cmd_cb, &res, req, sizeof(req), 2);
ipmi_queue_msg_sync(msg);

if (res.cc != IPMI_CC_NO_ERROR) {
Expand Down Expand Up @@ -381,8 +382,8 @@ static bool hiomap_flush(struct ipmi_hiomap *ctx)
req[1] = ++ctx->seq;

msg = ipmi_mkmsg(IPMI_DEFAULT_INTERFACE,
bmc_platform->ipmi_oem_hiomap_cmd, ipmi_hiomap_cmd_cb,
&res, req, sizeof(req), 2);
bmc_platform->sw->ipmi_oem_hiomap_cmd,
ipmi_hiomap_cmd_cb, &res, req, sizeof(req), 2);
ipmi_queue_msg_sync(msg);

if (res.cc != IPMI_CC_NO_ERROR) {
Expand All @@ -406,8 +407,8 @@ static bool hiomap_ack(struct ipmi_hiomap *ctx, uint8_t ack)
req[2] = ack;

msg = ipmi_mkmsg(IPMI_DEFAULT_INTERFACE,
bmc_platform->ipmi_oem_hiomap_cmd, ipmi_hiomap_cmd_cb,
&res, req, sizeof(req), 2);
bmc_platform->sw->ipmi_oem_hiomap_cmd,
ipmi_hiomap_cmd_cb, &res, req, sizeof(req), 2);
ipmi_queue_msg_sync(msg);

if (res.cc != IPMI_CC_NO_ERROR) {
Expand Down Expand Up @@ -446,8 +447,8 @@ static bool hiomap_erase(struct ipmi_hiomap *ctx, uint64_t offset,
range->size = cpu_to_le16(bytes_to_blocks(ctx, size));

msg = ipmi_mkmsg(IPMI_DEFAULT_INTERFACE,
bmc_platform->ipmi_oem_hiomap_cmd, ipmi_hiomap_cmd_cb,
&res, req, sizeof(req), 2);
bmc_platform->sw->ipmi_oem_hiomap_cmd,
ipmi_hiomap_cmd_cb, &res, req, sizeof(req), 2);
ipmi_queue_msg_sync(msg);

if (res.cc != IPMI_CC_NO_ERROR) {
Expand Down Expand Up @@ -787,7 +788,7 @@ int ipmi_hiomap_init(struct blocklevel_device **bl)
struct ipmi_hiomap *ctx;
int rc;

if (!bmc_platform->ipmi_oem_hiomap_cmd)
if (!bmc_platform->sw->ipmi_oem_hiomap_cmd)
/* FIXME: Find a better error code */
return FLASH_ERR_DEVICE_GONE;

Expand Down
9 changes: 7 additions & 2 deletions platforms/astbmc/astbmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef __ASTBMC_H
#define __ASTBMC_H

#include <platform.h>

#define ST_LOC_PHB(chip_id, phb_idx) ((chip_id) << 16 | (phb_idx))
#define ST_LOC_DEVFN(dev, fn) ((dev) << 3 | (fn))
/*
Expand Down Expand Up @@ -87,8 +89,11 @@ static struct slot_table_entry st_name[] = \
##__VA_ARGS__ \
}

extern const struct bmc_platform astbmc_ami;
extern const struct bmc_platform astbmc_openbmc;
extern const struct bmc_hw_config bmc_hw_ast2400;
extern const struct bmc_hw_config bmc_hw_ast2500;
extern const struct bmc_platform bmc_plat_ast2400_ami;
extern const struct bmc_platform bmc_plat_ast2500_ami;
extern const struct bmc_platform bmc_plat_ast2500_openbmc;

extern void astbmc_early_init(void);
extern int64_t astbmc_ipmi_reboot(void);
Expand Down
40 changes: 36 additions & 4 deletions platforms/astbmc/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,46 @@ void astbmc_exit(void)
ipmi_wdt_final_reset();
}

const struct bmc_platform astbmc_ami = {
.name = "AMI",
const struct bmc_sw_config bmc_sw_ami = {
.ipmi_oem_partial_add_esel = IPMI_CODE(0x3a, 0xf0),
.ipmi_oem_pnor_access_status = IPMI_CODE(0x3a, 0x07),
};

const struct bmc_platform astbmc_openbmc = {
.name = "OpenBMC",
const struct bmc_sw_config bmc_sw_openbmc = {
.ipmi_oem_partial_add_esel = IPMI_CODE(0x3a, 0xf0),
.ipmi_oem_hiomap_cmd = IPMI_CODE(0x3a, 0x5a),
};

/* Extracted from a Palmetto */
const struct bmc_hw_config bmc_hw_ast2400 = {
.scu_revision_id = 0x2010303,
.mcr_configuration = 0x00000577,
.mcr_scu_mpll = 0x000050c0,
.mcr_scu_strap = 0x00000000,
};

/* Extracted from a Witherspoon */
const struct bmc_hw_config bmc_hw_ast2500 = {
.scu_revision_id = 0x04030303,
.mcr_configuration = 0x11200756,
.mcr_scu_mpll = 0x000071C1,
.mcr_scu_strap = 0x00000000,
};

const struct bmc_platform bmc_plat_ast2400_ami = {
.name = "ast2400:ami",
.hw = &bmc_hw_ast2400,
.sw = &bmc_sw_ami,
};

const struct bmc_platform bmc_plat_ast2500_ami = {
.name = "ast2500:ami",
.hw = &bmc_hw_ast2500,
.sw = &bmc_sw_ami,
};

const struct bmc_platform bmc_plat_ast2500_openbmc = {
.name = "ast2500:openbmc",
.hw = &bmc_hw_ast2500,
.sw = &bmc_sw_openbmc,
};
2 changes: 1 addition & 1 deletion platforms/astbmc/firestone.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static bool firestone_probe(void)

DECLARE_PLATFORM(firestone) = {
.name = "Firestone",
.bmc = &astbmc_ami,
.bmc = &bmc_plat_ast2400_ami,
.probe = firestone_probe,
.init = astbmc_init,
.pci_get_slot_info = slot_table_get_slot_info,
Expand Down
2 changes: 1 addition & 1 deletion platforms/astbmc/garrison.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static bool garrison_probe(void)

DECLARE_PLATFORM(garrison) = {
.name = "Garrison",
.bmc = &astbmc_ami,
.bmc = &bmc_plat_ast2400_ami,
.probe = garrison_probe,
.init = astbmc_init,
.pci_get_slot_info = slot_table_get_slot_info,
Expand Down
2 changes: 1 addition & 1 deletion platforms/astbmc/habanero.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static bool habanero_probe(void)

DECLARE_PLATFORM(habanero) = {
.name = "Habanero",
.bmc = &astbmc_ami,
.bmc = &bmc_plat_ast2400_ami,
.probe = habanero_probe,
.init = astbmc_init,
.pci_get_slot_info = slot_table_get_slot_info,
Expand Down
11 changes: 8 additions & 3 deletions platforms/astbmc/p8dnu.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,21 @@ static bool p8dnu_probe(void)
return true;
}

static const struct bmc_platform astbmc_smc = {
.name = "SMC",
static const struct bmc_sw_config bmc_sw_smc = {
.ipmi_oem_partial_add_esel = IPMI_CODE(0x3a, 0xf0),
.ipmi_oem_pnor_access_status = IPMI_CODE(0x3a, 0x07),
};

static const struct bmc_platform bmc_plat_ast2400_smc = {
.name = "SMC",
.hw = &bmc_hw_ast2400,
.sw = &bmc_sw_smc,
};

DECLARE_PLATFORM(p8dnu) = {
.name = "P8DNU",
.probe = p8dnu_probe,
.bmc = &astbmc_smc,
.bmc = &bmc_plat_ast2400_smc,
.init = astbmc_init,
.pci_get_slot_info = slot_table_get_slot_info,
.cec_power_down = astbmc_ipmi_power_down,
Expand Down
12 changes: 8 additions & 4 deletions platforms/astbmc/p8dtu.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,21 @@ static bool p8dtu2u_probe(void)
return true;
}

static const struct bmc_platform astbmc_smc = {
.name = "SMC",
static const struct bmc_sw_config bmc_sw_smc = {
.ipmi_oem_partial_add_esel = IPMI_CODE(0x3a, 0xf0),
.ipmi_oem_pnor_access_status = IPMI_CODE(0x3a, 0x07),
};

static const struct bmc_platform bmc_plat_ast2400_smc = {
.name = "SMC",
.hw = &bmc_hw_ast2400,
.sw = &bmc_sw_smc,
};

DECLARE_PLATFORM(p8dtu1u) = {
.name = "p8dtu1u",
.probe = p8dtu1u_probe,
.bmc = &astbmc_smc,
.bmc = &bmc_plat_ast2400_smc,
.init = astbmc_init,
.pci_get_slot_info = slot_table_get_slot_info,
.pci_probe_complete = check_all_slot_table,
Expand All @@ -254,7 +258,7 @@ DECLARE_PLATFORM(p8dtu1u) = {
DECLARE_PLATFORM(p8dtu2u) = {
.name = "p8dtu2u",
.probe = p8dtu2u_probe,
.bmc = &astbmc_smc,
.bmc = &bmc_plat_ast2400_smc,
.init = astbmc_init,
.pci_get_slot_info = slot_table_get_slot_info,
.pci_probe_complete = check_all_slot_table,
Expand Down

0 comments on commit 9a830ee

Please sign in to comment.