Module Name: src Committed By: dyoung Date: Tue Oct 18 23:30:54 UTC 2011
Modified Files: src/sys/arch/x86/pci: pci_ranges.c Log Message: Add an implementation of device_pci_props_register(). To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x86/pci/pci_ranges.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/x86/pci/pci_ranges.c diff -u src/sys/arch/x86/pci/pci_ranges.c:1.2 src/sys/arch/x86/pci/pci_ranges.c:1.3 --- src/sys/arch/x86/pci/pci_ranges.c:1.2 Tue Sep 13 18:09:52 2011 +++ src/sys/arch/x86/pci/pci_ranges.c Tue Oct 18 23:30:54 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_ranges.c,v 1.2 2011/09/13 18:09:52 dyoung Exp $ */ +/* $NetBSD: pci_ranges.c,v 1.3 2011/10/18 23:30:54 dyoung Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pci_ranges.c,v 1.2 2011/09/13 18:09:52 dyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_ranges.c,v 1.3 2011/10/18 23:30:54 dyoung Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -47,6 +47,8 @@ __KERNEL_RCSID(0, "$NetBSD: pci_ranges.c #include <dev/pci/pcireg.h> #include <dev/pci/pccbbreg.h> +#include <machine/autoconf.h> + typedef enum pci_alloc_regtype { PCI_ALLOC_REGTYPE_NONE = 0 , PCI_ALLOC_REGTYPE_BAR = 1 @@ -956,3 +958,63 @@ pci_ranges_infer(pci_chipset_tag_t pc, i prop_object_release(memdict); /* XXX release iorsvns, memrsvns */ } + +static bool +pcibus_rsvn_predicate(void *arg, prop_dictionary_t rsvn) +{ + struct pcibus_attach_args *pba = arg; + uint8_t bus; + + if (!prop_dictionary_get_uint8(rsvn, "bus", &bus)) + return false; + + return pba->pba_bus <= bus && bus <= pba->pba_sub; +} + +static bool +pci_rsvn_predicate(void *arg, prop_dictionary_t rsvn) +{ + struct pci_attach_args *pa = arg; + uint8_t bus, device, function; + bool rc; + + rc = prop_dictionary_get_uint8(rsvn, "bus", &bus) && + prop_dictionary_get_uint8(rsvn, "device", &device) && + prop_dictionary_get_uint8(rsvn, "function", &function); + + if (!rc) + return false; + + return pa->pa_bus == bus && pa->pa_device == device && + pa->pa_function == function; +} + +void +device_pci_props_register(device_t dev, void *aux) +{ + cfdata_t cf; + prop_dictionary_t dict; + + cf = (device_parent(dev) != NULL) ? device_cfdata(dev) : NULL; +#if 0 + aprint_normal_dev(dev, "is%s a pci, parent %p, cf %p, ifattr %s\n", + device_is_a(dev, "pci") ? "" : " not", + (const void *)device_parent(dev), + cf, + cf != NULL ? cfdata_ifattr(cf) : ""); +#endif + if (pci_rsrc_dict == NULL) + return; + + if (!device_is_a(dev, "pci") && + (cf == NULL || strcmp(cfdata_ifattr(cf), "pci") != 0)) + return; + + dict = pci_rsrc_filter(pci_rsrc_dict, + device_is_a(dev, "pci") ? &pcibus_rsvn_predicate + : &pci_rsvn_predicate, aux); + if (dict == NULL) + return; + (void)prop_dictionary_set(device_properties(dev), + "pci-resources", dict); +}