From patchwork Thu Aug 20 01:29:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 508890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AC6CE14028E for ; Thu, 20 Aug 2015 11:30:13 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 8F37F1A0103 for ; Thu, 20 Aug 2015 11:30:13 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id B05CF1A1D62 for ; Thu, 20 Aug 2015 11:30:02 +1000 (AEST) Received: from pasglop.ozlabs.ibm.com (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id t7K1TclY007680; Wed, 19 Aug 2015 20:29:43 -0500 From: Benjamin Herrenschmidt To: skiboot@lists.ozlabs.org Date: Thu, 20 Aug 2015 11:29:29 +1000 Message-Id: <1440034170-20249-4-git-send-email-benh@kernel.crashing.org> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1440034170-20249-1-git-send-email-benh@kernel.crashing.org> References: <1440034170-20249-1-git-send-email-benh@kernel.crashing.org> Subject: [Skiboot] [RFC PATCH 4/5] plat/bmc: Add infrastructure for slot tables X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This adds some basic infrastructure for simple slot tables allowing us to name slots and built-in devices on OPP machines. Signed-off-by: Benjamin Herrenschmidt --- platforms/astbmc/Makefile.inc | 2 +- platforms/astbmc/astbmc.h | 18 +++++++++ platforms/astbmc/slots.c | 85 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 platforms/astbmc/slots.c diff --git a/platforms/astbmc/Makefile.inc b/platforms/astbmc/Makefile.inc index d0151d2..8c749e8 100644 --- a/platforms/astbmc/Makefile.inc +++ b/platforms/astbmc/Makefile.inc @@ -1,6 +1,6 @@ SUBDIRS += $(PLATDIR)/astbmc -ASTBMC_OBJS = palmetto.o habanero.o firestone.o garrison.o pnor.o common.o +ASTBMC_OBJS = palmetto.o habanero.o firestone.o garrison.o pnor.o common.o slots.o ASTBMC = $(PLATDIR)/astbmc/built-in.o $(ASTBMC): $(ASTBMC_OBJS:%=$(PLATDIR)/astbmc/%) diff --git a/platforms/astbmc/astbmc.h b/platforms/astbmc/astbmc.h index 489ffd2..23c31c7 100644 --- a/platforms/astbmc/astbmc.h +++ b/platforms/astbmc/astbmc.h @@ -18,6 +18,21 @@ #ifndef __ASTBMC_H #define __ASTBMC_H +#define ST_LOC_PHB(chip_id, phb_idx) ((chip_id) << 16 | (phb_idx)) +#define ST_LOC_DEVFN(dev, fn) ((dev) << 3 | (fn)) + +struct slot_table_entry { + enum slot_table_etype { + st_end, /* End of list */ + st_phb, + st_pluggable_slot, + st_builtin_dev, + } etype; + uint32_t location; + const char *name; + const struct slot_table_entry *children; +}; + extern void astbmc_early_init(void); extern int64_t astbmc_ipmi_reboot(void); extern int64_t astbmc_ipmi_power_down(uint64_t request); @@ -25,4 +40,7 @@ extern void astbmc_init(void); extern void astbmc_ext_irq_serirq_cpld(unsigned int chip_id); extern int pnor_init(void); +extern void slot_table_init(const struct slot_table_entry *top_table); +extern void slot_table_get_slot_info(struct phb *phb, struct pci_device * pd); + #endif /* __ASTBMC_H */ diff --git a/platforms/astbmc/slots.c b/platforms/astbmc/slots.c new file mode 100644 index 0000000..a3aa476 --- /dev/null +++ b/platforms/astbmc/slots.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include + +#include "astbmc.h" + +static const struct slot_table_entry *slot_top_table; + +void slot_table_init(const struct slot_table_entry *top_table) +{ + slot_top_table = top_table; +} + +static const struct slot_table_entry *match_slot_phb_entry(struct phb *phb) +{ + uint32_t chip_id = dt_get_chip_id(phb->dt_node); + uint32_t phb_idx = dt_prop_get_u32_def(phb->dt_node, + "ibm,phb-index", 0); + const struct slot_table_entry *ent; + + if (!slot_top_table) + return NULL; + + for (ent = slot_top_table; ent->etype != st_end; ent++) { + if (ent->etype != st_phb) { + prerror("SLOT: Bad DEV entry type in table !\n"); + continue; + } + if (ent->location == ST_LOC_PHB(chip_id, phb_idx)) + return ent; + } + return NULL; +} + +static const struct slot_table_entry *match_slot_dev_entry(struct phb *phb, + struct pci_device *pd) +{ + const struct slot_table_entry *parent, *ent; + + /* Find a parent recursively */ + if (pd->parent) + parent = match_slot_dev_entry(phb, pd->parent); + else { + /* No parent, this is a root complex, find the PHB */ + parent = match_slot_phb_entry(phb); + } + /* No parent ? Oops ... */ + if (!parent || !parent->children) + return NULL; + for (ent = parent->children; ent->etype != st_end; ent++) { + if (ent->etype == st_phb) { + prerror("SLOT: Bad PHB entry type in table !\n"); + continue; + } + if (ent->location == (pd->bdfn & 0xff)) + return ent; + } + return NULL; +} + +void slot_table_get_slot_info(struct phb *phb, struct pci_device * pd) +{ + const struct slot_table_entry *ent; + struct pci_slot_info *si; + + if (!pd || pd->slot_info) + return; + ent = match_slot_dev_entry(phb, pd); + if (!ent || !ent->name) + return; + pd->slot_info = si = zalloc(sizeof(struct pci_slot_info)); + assert(pd->slot_info); + strncpy(si->label, ent->name, sizeof(si->label) - 1); + si->pluggable = ent->etype == st_pluggable_slot; + si->power_ctl = false; + si->wired_lanes = -1; + si->bus_clock = -1; + si->connector_type = -1; + si->card_desc = -1; + si->card_mech = -1; + si->pwr_led_ctl = -1; + si->attn_led_ctl = -1; +}