From owner-svn-src-head@FreeBSD.ORG Sun Mar 1 00:39:42 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A58C71E9; Sun, 1 Mar 2015 00:39:42 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8606E14D; Sun, 1 Mar 2015 00:39:42 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t210dgFO090028; Sun, 1 Mar 2015 00:39:42 GMT (envelope-from rstone@FreeBSD.org) Received: (from rstone@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t210dfeH090021; Sun, 1 Mar 2015 00:39:41 GMT (envelope-from rstone@FreeBSD.org) Message-Id: <201503010039.t210dfeH090021@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: rstone set sender to rstone@FreeBSD.org using -f From: Ryan Stone Date: Sun, 1 Mar 2015 00:39:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r279443 - head/sys/dev/pci X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Mar 2015 00:39:42 -0000 Author: rstone Date: Sun Mar 1 00:39:40 2015 New Revision: 279443 URL: https://svnweb.freebsd.org/changeset/base/279443 Log: Add some pcib methods to get ARI-related information Differential Revision: https://reviews.freebsd.org/D72 Reviewed by: jhb MFC after: 1 month Sponsored by: Sandvine Inc. Modified: head/sys/dev/pci/pci_pci.c head/sys/dev/pci/pcib_if.m head/sys/dev/pci/pcib_private.h head/sys/dev/pci/pcib_support.c head/sys/dev/pci/pcireg.h Modified: head/sys/dev/pci/pci_pci.c ============================================================================== --- head/sys/dev/pci/pci_pci.c Sun Mar 1 00:39:33 2015 (r279442) +++ head/sys/dev/pci/pci_pci.c Sun Mar 1 00:39:40 2015 (r279443) @@ -64,6 +64,9 @@ static void pcib_write_config(device_t static int pcib_ari_maxslots(device_t dev); static int pcib_ari_maxfuncs(device_t dev); static int pcib_try_enable_ari(device_t pcib, device_t dev); +static int pcib_ari_enabled(device_t pcib); +static void pcib_ari_decode_rid(device_t pcib, uint16_t rid, + int *bus, int *slot, int *func); static device_method_t pcib_methods[] = { /* Device interface */ @@ -104,6 +107,8 @@ static device_method_t pcib_methods[] = DEVMETHOD(pcib_power_for_sleep, pcib_power_for_sleep), DEVMETHOD(pcib_get_rid, pcib_ari_get_rid), DEVMETHOD(pcib_try_enable_ari, pcib_try_enable_ari), + DEVMETHOD(pcib_ari_enabled, pcib_ari_enabled), + DEVMETHOD(pcib_decode_rid, pcib_ari_decode_rid), DEVMETHOD_END }; @@ -1883,6 +1888,24 @@ pcib_ari_maxfuncs(device_t dev) return (PCI_FUNCMAX); } +static void +pcib_ari_decode_rid(device_t pcib, uint16_t rid, int *bus, int *slot, + int *func) +{ + struct pcib_softc *sc; + + sc = device_get_softc(pcib); + + *bus = PCI_RID2BUS(rid); + if (sc->flags & PCIB_ENABLE_ARI) { + *slot = PCIE_ARI_RID2SLOT(rid); + *func = PCIE_ARI_RID2FUNC(rid); + } else { + *slot = PCI_RID2SLOT(rid); + *func = PCI_RID2FUNC(rid); + } +} + /* * Since we are a child of a PCI bus, its parent must support the pcib interface. */ @@ -2014,6 +2037,16 @@ pcib_power_for_sleep(device_t pcib, devi return (PCIB_POWER_FOR_SLEEP(bus, dev, pstate)); } +static int +pcib_ari_enabled(device_t pcib) +{ + struct pcib_softc *sc; + + sc = device_get_softc(pcib); + + return ((sc->flags & PCIB_ENABLE_ARI) != 0); +} + static uint16_t pcib_ari_get_rid(device_t pcib, device_t dev) { Modified: head/sys/dev/pci/pcib_if.m ============================================================================== --- head/sys/dev/pci/pcib_if.m Sun Mar 1 00:39:33 2015 (r279442) +++ head/sys/dev/pci/pcib_if.m Sun Mar 1 00:39:40 2015 (r279443) @@ -39,6 +39,13 @@ CODE { { return (PCI_INVALID_IRQ); } + + static int + pcib_null_ari_enabled(device_t pcib) + { + + return (0); + } }; # @@ -182,3 +189,21 @@ METHOD int try_enable_ari { device_t dev; }; +# +# Return non-zero if PCI ARI is enabled, or zero otherwise +# +METHOD int ari_enabled { + device_t pcib; +} DEFAULT pcib_null_ari_enabled; + +# +# Decode a PCI Routing Identifier (RID) into PCI bus/slot/function +# +METHOD void decode_rid { + device_t pcib; + uint16_t rid; + int *bus; + int *slot; + int *func; +} DEFAULT pcib_decode_rid; + Modified: head/sys/dev/pci/pcib_private.h ============================================================================== --- head/sys/dev/pci/pcib_private.h Sun Mar 1 00:39:33 2015 (r279442) +++ head/sys/dev/pci/pcib_private.h Sun Mar 1 00:39:40 2015 (r279443) @@ -170,5 +170,7 @@ int pcib_alloc_msix(device_t pcib, devi int pcib_release_msix(device_t pcib, device_t dev, int irq); int pcib_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data); uint16_t pcib_get_rid(device_t pcib, device_t dev); +void pcib_decode_rid(device_t pcib, uint16_t rid, int *bus, + int *slot, int *func); #endif Modified: head/sys/dev/pci/pcib_support.c ============================================================================== --- head/sys/dev/pci/pcib_support.c Sun Mar 1 00:39:33 2015 (r279442) +++ head/sys/dev/pci/pcib_support.c Sun Mar 1 00:39:40 2015 (r279443) @@ -66,3 +66,13 @@ pcib_get_rid(device_t pcib, device_t dev return (PCI_RID(bus, slot, func)); } +void +pcib_decode_rid(device_t pcib, uint16_t rid, int *bus, int *slot, + int *func) +{ + + *bus = PCI_RID2BUS(rid); + *slot = PCI_RID2SLOT(rid); + *func = PCI_RID2FUNC(rid); +} + Modified: head/sys/dev/pci/pcireg.h ============================================================================== --- head/sys/dev/pci/pcireg.h Sun Mar 1 00:39:33 2015 (r279442) +++ head/sys/dev/pci/pcireg.h Sun Mar 1 00:39:40 2015 (r279443) @@ -68,6 +68,10 @@ #define PCI_RID2SLOT(rid) (((rid) >> PCI_RID_SLOT_SHIFT) & PCI_SLOTMAX) #define PCI_RID2FUNC(rid) (((rid) >> PCI_RID_FUNC_SHIFT) & PCI_FUNCMAX) +#define PCIE_ARI_RID2SLOT(rid) (0) +#define PCIE_ARI_RID2FUNC(rid) \ + (((rid) >> PCI_RID_FUNC_SHIFT) & PCIE_ARI_FUNCMAX) + #define PCIE_ARI_SLOT(func) (((func) >> PCI_RID_SLOT_SHIFT) & PCI_SLOTMAX) #define PCIE_ARI_FUNC(func) (((func) >> PCI_RID_FUNC_SHIFT) & PCI_FUNCMAX)