Wed Jul 24 03:32:19 2013 UTC ()
Add kludgey implementation of pci_map_rom.


(riastradh)
diff -r1.1.2.13 -r1.1.2.14 src/sys/external/bsd/drm2/include/linux/pci.h
diff -r1.1.2.2 -r1.1.2.3 src/sys/external/bsd/drm2/pci/drm_pci.c

cvs diff -r1.1.2.13 -r1.1.2.14 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:24:03 1.1.2.13
+++ src/sys/external/bsd/drm2/include/linux/pci.h 2013/07/24 03:32:19 1.1.2.14
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pci.h,v 1.1.2.13 2013/07/24 03:24:03 riastradh Exp $ */ 1/* $NetBSD: pci.h,v 1.1.2.14 2013/07/24 03:32:19 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.
@@ -64,54 +64,61 @@ struct pci_device_id { @@ -64,54 +64,61 @@ struct pci_device_id {
64CTASSERT(PCI_CLASS_BRIDGE_ISA == 0x0601); 64CTASSERT(PCI_CLASS_BRIDGE_ISA == 0x0601);
65 65
66#define PCI_VENDOR_ID_INTEL PCI_VENDOR_INTEL 66#define PCI_VENDOR_ID_INTEL PCI_VENDOR_INTEL
67 67
68#define PCI_DEVFN(DEV, FN) \ 68#define PCI_DEVFN(DEV, FN) \
69 (__SHIFTIN((DEV), __BITS(3, 7)) | __SHIFTIN((FN), __BITS(0, 2))) 69 (__SHIFTIN((DEV), __BITS(3, 7)) | __SHIFTIN((FN), __BITS(0, 2)))
70#define PCI_SLOT(DEVFN) __SHIFTOUT((DEVFN), __BITS(3, 7)) 70#define PCI_SLOT(DEVFN) __SHIFTOUT((DEVFN), __BITS(3, 7))
71#define PCI_FUNC(DEVFN) __SHIFTOUT((DEVFN), __BITS(0, 2)) 71#define PCI_FUNC(DEVFN) __SHIFTOUT((DEVFN), __BITS(0, 2))
72 72
73#define PCI_CAP_ID_AGP PCI_CAP_AGP 73#define PCI_CAP_ID_AGP PCI_CAP_AGP
74 74
75struct pci_dev { 75struct pci_dev {
76 struct pci_attach_args pd_pa; 76 struct pci_attach_args pd_pa;
77 bool pd_kludged; /* XXX pci_kludgey_find_dev */ 77 int pd_kludges; /* Gotta lose 'em... */
 78#define NBPCI_KLUDGE_GET_MUMBLE 0x01
 79#define NBPCI_KLUDGE_MAP_ROM 0x02
 80 bus_space_tag_t pd_rom_bst;
 81 bus_space_handle_t pd_rom_bsh;
 82 bus_size_t pd_rom_size;
 83 void *pd_rom_vaddr;
78 device_t pd_dev; 84 device_t pd_dev;
79 struct pci_bus *bus; 85 struct pci_bus *bus;
80 uint32_t devfn; 86 uint32_t devfn;
81 uint16_t vendor; 87 uint16_t vendor;
82 uint16_t device; 88 uint16_t device;
83 uint16_t subsystem_vendor; 89 uint16_t subsystem_vendor;
84 uint16_t subsystem_device; 90 uint16_t subsystem_device;
85 uint8_t revision; 91 uint8_t revision;
86 uint32_t class; 92 uint32_t class;
87 bool msi_enabled; 93 bool msi_enabled;
88}; 94};
89 95
90static inline device_t 96static inline device_t
91pci_dev_dev(struct pci_dev *pdev) 97pci_dev_dev(struct pci_dev *pdev)
92{ 98{
93 return pdev->pd_dev; 99 return pdev->pd_dev;
94} 100}
95 101
96static inline void 102static inline void
97linux_pci_dev_init(struct pci_dev *pdev, device_t dev, 103linux_pci_dev_init(struct pci_dev *pdev, device_t dev,
98 const struct pci_attach_args *pa, bool kludged) 104 const struct pci_attach_args *pa, int kludges)
99{ 105{
100 const uint32_t subsystem_id = pci_conf_read(pa->pa_pc, pa->pa_tag, 106 const uint32_t subsystem_id = pci_conf_read(pa->pa_pc, pa->pa_tag,
101 PCI_SUBSYS_ID_REG); 107 PCI_SUBSYS_ID_REG);
102 108
103 pdev->pd_pa = *pa; 109 pdev->pd_pa = *pa;
104 pdev->pd_kludged = kludged; 110 pdev->pd_kludges = kludges;
 111 pdev->pd_rom_vaddr = NULL;
105 pdev->pd_dev = dev; 112 pdev->pd_dev = dev;
106 pdev->bus = NULL; /* XXX struct pci_dev::bus */ 113 pdev->bus = NULL; /* XXX struct pci_dev::bus */
107 pdev->devfn = PCI_DEVFN(pa->pa_device, pa->pa_function); 114 pdev->devfn = PCI_DEVFN(pa->pa_device, pa->pa_function);
108 pdev->vendor = PCI_VENDOR(pa->pa_id); 115 pdev->vendor = PCI_VENDOR(pa->pa_id);
109 pdev->device = PCI_PRODUCT(pa->pa_id); 116 pdev->device = PCI_PRODUCT(pa->pa_id);
110 pdev->subsystem_vendor = PCI_SUBSYS_VENDOR(subsystem_id); 117 pdev->subsystem_vendor = PCI_SUBSYS_VENDOR(subsystem_id);
111 pdev->subsystem_device = PCI_SUBSYS_ID(subsystem_id); 118 pdev->subsystem_device = PCI_SUBSYS_ID(subsystem_id);
112 pdev->revision = PCI_REVISION(pa->pa_class); 119 pdev->revision = PCI_REVISION(pa->pa_class);
113 pdev->class = __SHIFTOUT(pa->pa_class, 0xffffff00UL); /* ? */ 120 pdev->class = __SHIFTOUT(pa->pa_class, 0xffffff00UL); /* ? */
114 pdev->msi_enabled = false; 121 pdev->msi_enabled = false;
115} 122}
116 123
117static inline int 124static inline int
@@ -276,27 +283,27 @@ pci_kludgey_match_bus0_dev0_func0(const  @@ -276,27 +283,27 @@ pci_kludgey_match_bus0_dev0_func0(const
276 283
277static inline struct pci_dev * 284static inline struct pci_dev *
278pci_get_bus_and_slot(int bus, int slot) 285pci_get_bus_and_slot(int bus, int slot)
279{ 286{
280 struct pci_attach_args pa; 287 struct pci_attach_args pa;
281 288
282 KASSERT(bus == 0); 289 KASSERT(bus == 0);
283 KASSERT(slot == PCI_DEVFN(0, 0)); 290 KASSERT(slot == PCI_DEVFN(0, 0));
284 291
285 if (!pci_find_device(&pa, &pci_kludgey_match_bus0_dev0_func0)) 292 if (!pci_find_device(&pa, &pci_kludgey_match_bus0_dev0_func0))
286 return NULL; 293 return NULL;
287 294
288 struct pci_dev *const pdev = kmem_zalloc(sizeof(*pdev), KM_SLEEP); 295 struct pci_dev *const pdev = kmem_zalloc(sizeof(*pdev), KM_SLEEP);
289 linux_pci_dev_init(pdev, NULL, &pa, true); 296 linux_pci_dev_init(pdev, NULL, &pa, NBPCI_KLUDGE_GET_MUMBLE);
290 297
291 return pdev; 298 return pdev;
292} 299}
293 300
294static inline int /* XXX inline? */ 301static inline int /* XXX inline? */
295pci_kludgey_match_isa_bridge(const struct pci_attach_args *pa) 302pci_kludgey_match_isa_bridge(const struct pci_attach_args *pa)
296{ 303{
297 304
298 if (PCI_CLASS(pa->pa_class) != PCI_CLASS_BRIDGE) 305 if (PCI_CLASS(pa->pa_class) != PCI_CLASS_BRIDGE)
299 return 0; 306 return 0;
300 if (PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_BRIDGE_ISA) 307 if (PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_BRIDGE_ISA)
301 return 0; 308 return 0;
302 309
@@ -306,27 +313,71 @@ pci_kludgey_match_isa_bridge(const struc @@ -306,27 +313,71 @@ pci_kludgey_match_isa_bridge(const struc
306static inline struct pci_dev * 313static inline struct pci_dev *
307pci_get_class(uint32_t class_subclass_shifted __unused, 314pci_get_class(uint32_t class_subclass_shifted __unused,
308 struct pci_dev *from __unused) 315 struct pci_dev *from __unused)
309{ 316{
310 struct pci_attach_args pa; 317 struct pci_attach_args pa;
311 318
312 KASSERT(class_subclass_shifted == (PCI_CLASS_BRIDGE_ISA << 8)); 319 KASSERT(class_subclass_shifted == (PCI_CLASS_BRIDGE_ISA << 8));
313 KASSERT(from == NULL); 320 KASSERT(from == NULL);
314 321
315 if (!pci_find_device(&pa, &pci_kludgey_match_isa_bridge)) 322 if (!pci_find_device(&pa, &pci_kludgey_match_isa_bridge))
316 return NULL; 323 return NULL;
317 324
318 struct pci_dev *const pdev = kmem_zalloc(sizeof(*pdev), KM_SLEEP); 325 struct pci_dev *const pdev = kmem_zalloc(sizeof(*pdev), KM_SLEEP);
319 linux_pci_dev_init(pdev, NULL, &pa, true); 326 linux_pci_dev_init(pdev, NULL, &pa, NBPCI_KLUDGE_GET_MUMBLE);
320 327
321 return pdev; 328 return pdev;
322} 329}
323 330
324static inline void 331static inline void
325pci_dev_put(struct pci_dev *pdev) 332pci_dev_put(struct pci_dev *pdev)
326{ 333{
327 334
328 KASSERT(pdev->pd_kludged); 335 KASSERT(ISSET(pdev->pd_kludges, NBPCI_KLUDGE_GET_MUMBLE));
329 kmem_free(pdev, sizeof(*pdev)); 336 kmem_free(pdev, sizeof(*pdev));
330} 337}
331 338
 339#define __pci_rom_iomem
 340
 341static inline void
 342pci_unmap_rom(struct pci_dev *pdev, void __pci_rom_iomem *vaddr __unused)
 343{
 344
 345 KASSERT(ISSET(pdev->pd_kludges, NBPCI_KLUDGE_MAP_ROM));
 346 KASSERT(vaddr == pdev->pd_rom_vaddr);
 347 bus_space_unmap(pdev->pd_rom_bst, pdev->pd_rom_bsh, pdev->pd_rom_size);
 348 pdev->pd_kludges &= ~NBPCI_KLUDGE_MAP_ROM;
 349 pdev->pd_rom_vaddr = NULL;
 350}
 351
 352static inline void __pci_rom_iomem *
 353pci_map_rom(struct pci_dev *pdev, size_t *sizep)
 354{
 355 bus_space_handle_t bsh;
 356 bus_size_t size;
 357
 358 KASSERT(!ISSET(pdev->pd_kludges, NBPCI_KLUDGE_MAP_ROM));
 359
 360 if (pci_mapreg_map(&pdev->pd_pa, PCI_MAPREG_ROM, PCI_MAPREG_TYPE_ROM,
 361 (BUS_SPACE_MAP_PREFETCHABLE | BUS_SPACE_MAP_LINEAR),
 362 &pdev->pd_rom_bst, &pdev->pd_rom_bsh, NULL, &pdev->pd_rom_size)
 363 != 0) {
 364 aprint_error_dev(pdev->pd_dev, "unable to map ROM\n");
 365 return NULL;
 366 }
 367 pdev->pd_kludges |= NBPCI_KLUDGE_MAP_ROM;
 368
 369 /* XXX This type is obviously wrong in general... */
 370 if (pci_find_rom(&pdev->pd_pa, pdev->pd_rom_bst, pdev->pd_rom_bsh,
 371 PCI_ROM_CODE_TYPE_X86, &bsh, &size)) {
 372 aprint_error_dev(pdev->pd_dev, "unable to find ROM\n");
 373 pci_unmap_rom(pdev, NULL);
 374 return NULL;
 375 }
 376
 377 KASSERT(size <= SIZE_T_MAX);
 378 *sizep = size;
 379 pdev->pd_rom_vaddr = bus_space_vaddr(pdev->pd_rom_bst, bsh);
 380 return pdev->pd_rom_vaddr;
 381}
 382
332#endif /* _LINUX_PCI_H_ */ 383#endif /* _LINUX_PCI_H_ */

cvs diff -r1.1.2.2 -r1.1.2.3 src/sys/external/bsd/drm2/pci/drm_pci.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/pci/drm_pci.c 2013/07/24 03:24:03 1.1.2.2
+++ src/sys/external/bsd/drm2/pci/drm_pci.c 2013/07/24 03:32:19 1.1.2.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: drm_pci.c,v 1.1.2.2 2013/07/24 03:24:03 riastradh Exp $ */ 1/* $NetBSD: drm_pci.c,v 1.1.2.3 2013/07/24 03:32:19 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.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
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#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.2 2013/07/24 03:24:03 riastradh Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.3 2013/07/24 03:32:19 riastradh Exp $");
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/errno.h> 36#include <sys/errno.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38 38
39#include <dev/pci/pcivar.h> 39#include <dev/pci/pcivar.h>
40 40
41#include <drm/drmP.h> 41#include <drm/drmP.h>
42 42
43static int drm_pci_get_irq(struct drm_device *); 43static int drm_pci_get_irq(struct drm_device *);
44static int drm_pci_irq_install(struct drm_device *, 44static int drm_pci_irq_install(struct drm_device *,
45 irqreturn_t (*)(void *), int, const char *, void *, 45 irqreturn_t (*)(void *), int, const char *, void *,
46 struct drm_bus_irq_cookie **); 46 struct drm_bus_irq_cookie **);
@@ -68,27 +68,27 @@ const struct drm_bus drm_pci_bus = { @@ -68,27 +68,27 @@ const struct drm_bus drm_pci_bus = {
68}; 68};
69 69
70static const struct pci_attach_args * 70static const struct pci_attach_args *
71drm_pci_attach_args(struct drm_device *dev) 71drm_pci_attach_args(struct drm_device *dev)
72{ 72{
73 return &dev->pdev->pd_pa; 73 return &dev->pdev->pd_pa;
74} 74}
75 75
76void 76void
77drm_pci_attach(device_t self, const struct pci_attach_args *pa, 77drm_pci_attach(device_t self, const struct pci_attach_args *pa,
78 struct pci_dev *pdev, struct drm_device *dev) 78 struct pci_dev *pdev, struct drm_device *dev)
79{ 79{
80 80
81 linux_pci_dev_init(pdev, self, pa, false); 81 linux_pci_dev_init(pdev, self, pa, 0);
82 82
83 dev->pdev = pdev; 83 dev->pdev = pdev;
84 dev->pci_vendor = pdev->vendor; 84 dev->pci_vendor = pdev->vendor;
85 dev->pci_device = pdev->device; 85 dev->pci_device = pdev->device;
86 86
87 /* XXX Set the power state to D0? */ 87 /* XXX Set the power state to D0? */
88} 88}
89 89
90int 90int
91drm_pci_detach(struct drm_device *dev __unused, int flags __unused) 91drm_pci_detach(struct drm_device *dev __unused, int flags __unused)
92{ 92{
93 93
94 /* XXX Disestablish irqs or anything? */ 94 /* XXX Disestablish irqs or anything? */