Wed Jul 24 03:01:38 2013 UTC ()
Add pci_kludgey_find_dev to <linux/pci.h>.

This is not a Linux KPI, but the Linux KPI (pci_get_bus_and_slot)
doesn't pass along the original pci device or bus, so this is what
we'll use to replace uses of it (or, the one use of it) without
changing much code.


(riastradh)
diff -r1.1.2.4 -r1.1.2.5 src/sys/external/bsd/drm2/include/linux/pci.h

cvs diff -r1.1.2.4 -r1.1.2.5 src/sys/external/bsd/drm2/include/linux/pci.h (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/include/linux/pci.h 2013/07/24 03:01:09 1.1.2.4
+++ src/sys/external/bsd/drm2/include/linux/pci.h 2013/07/24 03:01:38 1.1.2.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pci.h,v 1.1.2.4 2013/07/24 03:01:09 riastradh Exp $ */ 1/* $NetBSD: pci.h,v 1.1.2.5 2013/07/24 03:01:38 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -24,38 +24,40 @@ @@ -24,38 +24,40 @@
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#ifndef _LINUX_PCI_H_ 32#ifndef _LINUX_PCI_H_
33#define _LINUX_PCI_H_ 33#define _LINUX_PCI_H_
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/bus.h> 36#include <sys/bus.h>
 37#include <sys/kmem.h>
37#include <sys/systm.h> 38#include <sys/systm.h>
38 39
39#include <dev/pci/pcivar.h> 40#include <dev/pci/pcivar.h>
40 41
41#include <linux/ioport.h> 42#include <linux/ioport.h>
42 43
43struct pci_bus; 44struct pci_bus;
44struct pci_device_id; 45struct pci_device_id;
45 46
46struct pci_dev { 47struct pci_dev {
47 struct pci_bus *bus; 48 struct pci_bus *bus;
48 struct pci_attach_args pd_pa; 49 struct pci_attach_args pd_pa;
 50 bool pd_kludged; /* XXX pci_kludgey_find_dev hack */
49}; 51};
50 52
51#define PCI_CAP_ID_AGP PCI_CAP_AGP 53#define PCI_CAP_ID_AGP PCI_CAP_AGP
52 54
53static inline int 55static inline int
54pci_find_capability(struct pci_dev *pdev, int cap) 56pci_find_capability(struct pci_dev *pdev, int cap)
55{ 57{
56 return pci_get_capability(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, cap, 58 return pci_get_capability(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, cap,
57 NULL, NULL); 59 NULL, NULL);
58} 60}
59 61
60static inline void 62static inline void
61pci_read_config_dword(struct pci_dev *pdev, int reg, uint32_t *valuep) 63pci_read_config_dword(struct pci_dev *pdev, int reg, uint32_t *valuep)
@@ -102,14 +104,54 @@ pci_bus_alloc_resource(struct pci_bus *b @@ -102,14 +104,54 @@ pci_bus_alloc_resource(struct pci_bus *b
102 panic("I don't know what kind of resource you want!"); 104 panic("I don't know what kind of resource you want!");
103 } 105 }
104 106
105 resource->r_bst = bst; 107 resource->r_bst = bst;
106 error = bus_space_alloc(bst, start, 0xffffffffffffffffULL /* XXX */, 108 error = bus_space_alloc(bst, start, 0xffffffffffffffffULL /* XXX */,
107 size, align, 0, 0, &resource->start, &resource->r_bsh); 109 size, align, 0, 0, &resource->start, &resource->r_bsh);
108 if (error) 110 if (error)
109 return error; 111 return error;
110 112
111 resource->size = size; 113 resource->size = size;
112 return 0; 114 return 0;
113} 115}
114 116
 117/*
 118 * XXX Mega-kludgerific!
 119 *
 120 * XXX Doesn't check whether any such device actually exists.
 121 */
 122
 123static inline struct pci_dev *
 124pci_kludgey_find_dev(struct pci_dev *pdev, int bus, int dev, int func)
 125{
 126 struct pci_dev *const otherdev = kmem_zalloc(sizeof(*otherdev),
 127 KM_SLEEP);
 128
 129#ifdef DIAGNOSTIC
 130 {
 131 int obus, odev, ofunc;
 132
 133 pci_decompose_tag(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, &obus,
 134 &odev, &ofunc);
 135 KASSERT(obus == bus);
 136 }
 137#endif
 138
 139 otherdev->bus = NULL; /* XXX struct pci_dev::bus */
 140 otherdev->device = dev;
 141 otherdev->pd_pa = pdev->pd_pa;
 142 otherdev->pd_pa.pa_tag = pci_make_tag(otherdev->pd_pa.pa_pc,
 143 bus, dev, func);
 144 otherdev->pd_kludged = true;
 145
 146 return otherdev;
 147}
 148
 149static inline void
 150pci_dev_put(struct pci_dev *pdev)
 151{
 152
 153 KASSERT(pdev->pd_kludged);
 154 kmem_free(pdev, sizeof(*pdev));
 155}
 156
115#endif /* _LINUX_PCI_H_ */ 157#endif /* _LINUX_PCI_H_ */