From patchwork Fri Sep 16 05:05:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 670689 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sb5zt1Xf9z9rxl for ; Fri, 16 Sep 2016 17:11:22 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3sb5zt0bY3zDsdM for ; Fri, 16 Sep 2016 17:11:22 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3sb3BS0PfszDsZR for ; Fri, 16 Sep 2016 15:05:19 +1000 (AEST) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u8G4wbjF114211 for ; Fri, 16 Sep 2016 01:05:17 -0400 Received: from e23smtp08.au.ibm.com (e23smtp08.au.ibm.com [202.81.31.141]) by mx0b-001b2d01.pphosted.com with ESMTP id 25fnnyrd02-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 16 Sep 2016 01:05:17 -0400 Received: from localhost by e23smtp08.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 16 Sep 2016 15:05:14 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp08.au.ibm.com (202.81.31.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 16 Sep 2016 15:05:13 +1000 Received: from d23relay10.au.ibm.com (d23relay10.au.ibm.com [9.190.26.77]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 7B7802CE8059 for ; Fri, 16 Sep 2016 15:05:12 +1000 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u8G55CN754853660 for ; Fri, 16 Sep 2016 15:05:12 +1000 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u8G55C3B020735 for ; Fri, 16 Sep 2016 15:05:12 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u8G55CuW020727; Fri, 16 Sep 2016 15:05:12 +1000 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id 0665EA013E; Fri, 16 Sep 2016 15:05:12 +1000 (AEST) Received: from gwshan (shangw.ozlabs.ibm.com [10.61.2.199]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id 01F85E3C16; Fri, 16 Sep 2016 15:05:12 +1000 (AEST) Received: by gwshan (Postfix, from userid 1000) id 75EE1941E19; Fri, 16 Sep 2016 15:05:32 +1000 (AEST) From: Gavin Shan To: skiboot@lists.ozlabs.org Date: Fri, 16 Sep 2016 15:05:11 +1000 X-Mailer: git-send-email 2.1.0 In-Reply-To: <1474002323-31380-1-git-send-email-gwshan@linux.vnet.ibm.com> References: <1474002323-31380-1-git-send-email-gwshan@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16091605-0048-0000-0000-000001BE2F85 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16091605-0049-0000-0000-00004691089B Message-Id: <1474002323-31380-5-git-send-email-gwshan@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-09-16_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609020000 definitions=main-1609160064 Subject: [Skiboot] [PATCH 04/16] platforms/astbmc: Support dynamic PCI slot X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.22 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" We might insert a PCIe switch to PHB direct slot and the downstream ports of the PCIe switch supports PCI hotplug. This creates dynamic PCI slots for the downstream ports in the scenario: * The dynamic PCI slot's label has fixed encoding: "S". * No associated platform slot. * The management on dynamic PCI slot relies on the generic layer implemented in pcie-slot.c. Signed-off-by: Gavin Shan --- platforms/astbmc/slots.c | 67 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/platforms/astbmc/slots.c b/platforms/astbmc/slots.c index ff69e99..47db021 100644 --- a/platforms/astbmc/slots.c +++ b/platforms/astbmc/slots.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -88,17 +89,24 @@ static void add_slot_properties(struct pci_slot *slot, struct dt_node *np) { struct phb *phb = slot->phb; + struct pci_device *pd = slot->pd; struct slot_table_entry *ent = slot->data; size_t base_loc_code_len, slot_label_len; - char loc_code[LOC_CODE_SIZE]; + char label[8], loc_code[LOC_CODE_SIZE]; - if (!np || !ent) + if (!np) return; - dt_add_property_string(np, "ibm,slot-label", ent->name); + if (ent) { + dt_add_property_string(np, "ibm,slot-label", ent->name); + slot_label_len = strlen(ent->name); + } else { + snprintf(label, 8, "S%04x%02x", phb->opal_id, pd->secondary_bus); + dt_add_property_string(np, "ibm,slot-label", label); + slot_label_len = strlen(label); + } base_loc_code_len = phb->base_loc_code ? strlen(phb->base_loc_code) : 0; - slot_label_len = strlen(ent->name); if ((base_loc_code_len + slot_label_len + 1) >= LOC_CODE_SIZE) return; @@ -110,7 +118,10 @@ static void add_slot_properties(struct pci_slot *slot, loc_code[0] = '\0'; } - strcat(loc_code, ent->name); + if (ent) + strcat(loc_code, ent->name); + else + strcat(loc_code, label); dt_add_property(np, "ibm,slot-location-code", loc_code, strlen(loc_code) + 1); } @@ -130,6 +141,48 @@ static void init_slot_info(struct pci_slot *slot, bool pluggable, void *data) slot->attn_led_ctl = PCI_SLOT_ATTN_LED_CTL_NONE; } +static void create_dynamic_slot(struct phb *phb, struct pci_device *pd) +{ + struct pci_slot *slot; + uint32_t ecap, val32; + uint16_t val16; + + if (!phb || !pd || pd->slot) + return; + + /* Try to create slot whose details aren't provided by platform. + * We only care the downstream ports of PCIe switch. + */ + if (pd->dev_type != PCIE_TYPE_SWITCH_DNPORT) + return; + + /* The dynamic PCI slots are created for below PCIe switches: + * + * 0x854611f8 - PCI bridge: PMC-Sierra Inc. Device 8546 + */ + if (pd->vdid != 0x854611f8) + return; + + /* Check the builtin PCI slot capability. As we already checked + * the downstream port's vendor/device ID, the below check is + * almost unnecessary, but not harmful. + */ + ecap = pci_cap(pd, PCI_CFG_CAP_ID_EXP, false); + if (!ecap) + return; + + pci_cfg_read16(phb, pd->bdfn, ecap + PCICAP_EXP_CAPABILITY_REG, &val16); + if (!(val16 & PCICAP_EXP_CAP_SLOT)) + return; + pci_cfg_read32(phb, pd->bdfn, ecap + PCICAP_EXP_SLOTCAP, &val32); + if (!(val32 & PCICAP_EXP_SLOTCAP_HPLUG_CAP)) + return; + + slot = pcie_slot_create(phb, pd); + assert(slot); + init_slot_info(slot, true, NULL); +} + void slot_table_get_slot_info(struct phb *phb, struct pci_device *pd) { const struct slot_table_entry *ent; @@ -139,8 +192,10 @@ void slot_table_get_slot_info(struct phb *phb, struct pci_device *pd) if (!pd || pd->slot) return; ent = match_slot_dev_entry(phb, pd); - if (!ent || !ent->name) + if (!ent || !ent->name) { + create_dynamic_slot(phb, pd); return; + } slot = pcie_slot_create(phb, pd); assert(slot);