From patchwork Fri Feb 24 05:03:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 731897 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 ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vTzXc4KSmz9s7R for ; Fri, 24 Feb 2017 16:04:00 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3vTzXc3WJVzDqHZ for ; Fri, 24 Feb 2017 16:04:00 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from russell.cc (russell.cc [IPv6:2404:9400:2:0:216:3eff:fee0:3370]) (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 3vTzXT3XVYzDqGp for ; Fri, 24 Feb 2017 16:03:53 +1100 (AEDT) Received: from snap.ozlabs.ibm.com (static-82-10.transact.net.au [122.99.82.10]) by russell.cc (OpenSMTPD) with ESMTPSA id c2598c30 (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128:NO); Fri, 24 Feb 2017 05:03:47 +0000 (UTC) From: Russell Currey To: skiboot@lists.ozlabs.org Date: Fri, 24 Feb 2017 16:03:35 +1100 Message-Id: <20170224050336.2689-1-ruscur@russell.cc> X-Mailer: git-send-email 2.11.1 Subject: [Skiboot] [PATCH v2 1/2] pci: Add a framework for quirks X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 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" In future we may want to be able to do fixups for specific PCI devices in skiboot, so add a small framework for doing this. This is not intended for the same purposes as quirks in the Linux kernel, as the PCI devices that quirks can match for in skiboot are not properly configured. This is intended to enable having a custom path to make changes that don't directly interact with the PCI device, for example adding device tree entries. Signed-off-by: Russell Currey Signed-off-by: Benjamin Herrenschmidt --- v2 [ruscur]: Drop dt_node from pci_handle_quirk() thanks to Gavin --- core/Makefile.inc | 2 +- core/pci-quirk.c | 41 +++++++++++++++++++++++++++++++++++++++++ core/pci.c | 3 +++ include/pci-quirk.h | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 core/pci-quirk.c create mode 100644 include/pci-quirk.h diff --git a/core/Makefile.inc b/core/Makefile.inc index ae3c2979..b09c30c0 100644 --- a/core/Makefile.inc +++ b/core/Makefile.inc @@ -8,7 +8,7 @@ CORE_OBJS += pci-opal.o fast-reboot.o device.o exceptions.o trace.o affinity.o CORE_OBJS += vpd.o hostservices.o platform.o nvram.o nvram-format.o hmi.o CORE_OBJS += console-log.o ipmi.o time-utils.o pel.o pool.o errorlog.o CORE_OBJS += timer.o i2c.o rtc.o flash.o sensor.o ipmi-opal.o -CORE_OBJS += flash-subpartition.o bitmap.o buddy.o +CORE_OBJS += flash-subpartition.o bitmap.o buddy.o pci-quirk.o ifeq ($(SKIBOOT_GCOV),1) CORE_OBJS += gcov-profiling.o diff --git a/core/pci-quirk.c b/core/pci-quirk.c new file mode 100644 index 00000000..93f613eb --- /dev/null +++ b/core/pci-quirk.c @@ -0,0 +1,41 @@ +/* Copyright 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +/* Quirks are: {fixup function, vendor ID, (device ID or PCI_ANY_ID)} */ +static const struct pci_quirk quirk_table[] = { + {0} +}; + +void pci_handle_quirk(struct phb *phb, + struct pci_device *pd, + uint16_t vendor_id, + uint16_t device_id) +{ + const struct pci_quirk *quirks = quirk_table; + + while (quirks->vendor_id) { + if (vendor_id == quirks->vendor_id && + (quirks->device_id == PCI_ANY_ID || + device_id == quirks->device_id)) + quirks->fixup(phb, pd); + quirks++; + } +} diff --git a/core/pci.c b/core/pci.c index 9889dbf8..fe4e73d8 100644 --- a/core/pci.c +++ b/core/pci.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -1430,6 +1431,8 @@ static void pci_add_one_device_node(struct phb *phb, if (intpin) dt_add_property_cells(np, "interrupts", intpin); + pci_handle_quirk(phb, pd, vdid & 0xffff, vdid >> 16); + /* XXX FIXME: Add a few missing ones such as * * - devsel-speed (!express) diff --git a/include/pci-quirk.h b/include/pci-quirk.h new file mode 100644 index 00000000..c7669733 --- /dev/null +++ b/include/pci-quirk.h @@ -0,0 +1,35 @@ +/* Copyright 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __PCI_QUIRK_H +#define __PCI_QUIRK_H + +#include + +#define PCI_ANY_ID 0xFFFF + +struct pci_quirk { + void (*fixup)(struct phb *, struct pci_device *); + uint16_t vendor_id; + uint16_t device_id; +}; + +void pci_handle_quirk(struct phb *phb, + struct pci_device *pd, + uint16_t vendor_id, + uint16_t device_id); + +#endif /* __PCI_QUIRK_H */