Thu Mar 5 20:19:30 2015 UTC ()
properly include files so that modules work.


(christos)
diff -r1.2 -r1.3 src/sys/external/bsd/drm2/pci/drmfb_pci.c

cvs diff -r1.2 -r1.3 src/sys/external/bsd/drm2/pci/drmfb_pci.c (switch to unified diff)

--- src/sys/external/bsd/drm2/pci/drmfb_pci.c 2015/03/05 17:56:39 1.2
+++ src/sys/external/bsd/drm2/pci/drmfb_pci.c 2015/03/05 20:19:30 1.3
@@ -1,161 +1,161 @@ @@ -1,161 +1,161 @@
1/* $NetBSD: drmfb_pci.c,v 1.2 2015/03/05 17:56:39 riastradh Exp $ */ 1/* $NetBSD: drmfb_pci.c,v 1.3 2015/03/05 20:19:30 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 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.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
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/* 32/*
33 * drmfb_pci: drmfb hooks for PCI devices. 33 * drmfb_pci: drmfb hooks for PCI devices.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: drmfb_pci.c,v 1.2 2015/03/05 17:56:39 riastradh Exp $"); 37__KERNEL_RCSID(0, "$NetBSD: drmfb_pci.c,v 1.3 2015/03/05 20:19:30 christos Exp $");
38 38
39#ifdef _KERNEL_OPT 39#ifdef _KERNEL_OPT
40#include "vga.h" 40#include "vga.h"
41#endif 41#endif
42 42
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/device.h> 44#include <sys/device.h>
45#include <sys/errno.h> 45#include <sys/errno.h>
46#include <sys/systm.h> 46#include <sys/systm.h>
47 47
48#include <dev/pci/pciio.h> 48#include <dev/pci/pciio.h>
49#include <dev/pci/pcireg.h> 49#include <dev/pci/pcireg.h>
50#include <dev/pci/pcivar.h> 50#include <dev/pci/pcivar.h>
51#include <dev/pci/wsdisplay_pci.h> 51#include <dev/pci/wsdisplay_pci.h>
52 52
53#if NVGA > 0 53#if NVGA > 0
54/* 54/*
55 * XXX All we really need is vga_is_console from vgavar.h, but the 55 * XXX All we really need is vga_is_console from vgavar.h, but the
56 * header files are missing their own dependencies, so we need to 56 * header files are missing their own dependencies, so we need to
57 * explicitly drag in the other crap. 57 * explicitly drag in the other crap.
58 */ 58 */
59#include <dev/ic/mc6845reg.h> 59#include <dev/ic/mc6845reg.h>
60#include <dev/ic/pcdisplayvar.h> 60#include <dev/ic/pcdisplayvar.h>
61#include <dev/ic/vgareg.h> 61#include <dev/ic/vgareg.h>
62#include <dev/ic/vgavar.h> 62#include <dev/ic/vgavar.h>
63#endif 63#endif
64 64
65#include <drm/drmP.h> 65#include <drm/drmP.h>
66#include <drm/drm_fb_helper.h> 66#include <drm/drm_fb_helper.h>
67 67
68#include "drmfb.h" 68#include <drm/drmfb.h>
69#include "drmfb_pci.h" 69#include <drm/drmfb_pci.h>
70 70
71/* 71/*
72 * drmfb_pci_mmap: Implementation of drmfb_params::dp_mmap. Don't use 72 * drmfb_pci_mmap: Implementation of drmfb_params::dp_mmap. Don't use
73 * this for dp_mmapfb -- how to get at the framebuffer is device- 73 * this for dp_mmapfb -- how to get at the framebuffer is device-
74 * specific. 74 * specific.
75 */ 75 */
76paddr_t 76paddr_t
77drmfb_pci_mmap(struct drmfb_softc *sc, off_t offset, int prot) 77drmfb_pci_mmap(struct drmfb_softc *sc, off_t offset, int prot)
78{ 78{
79 struct drm_device *const dev = sc->sc_da.da_fb_helper->dev; 79 struct drm_device *const dev = sc->sc_da.da_fb_helper->dev;
80 const struct pci_attach_args *const pa = &dev->pdev->pd_pa; 80 const struct pci_attach_args *const pa = &dev->pdev->pd_pa;
81 unsigned i; 81 unsigned i;
82 82
83 for (i = 0; PCI_BAR(i) <= PCI_MAPREG_ROM; i++) { 83 for (i = 0; PCI_BAR(i) <= PCI_MAPREG_ROM; i++) {
84 pcireg_t type; 84 pcireg_t type;
85 bus_addr_t addr; 85 bus_addr_t addr;
86 bus_size_t size; 86 bus_size_t size;
87 int flags; 87 int flags;
88 88
89 /* Interrogate the BAR. */ 89 /* Interrogate the BAR. */
90 if (!pci_mapreg_probe(pa->pa_pc, pa->pa_tag, PCI_BAR(i), 90 if (!pci_mapreg_probe(pa->pa_pc, pa->pa_tag, PCI_BAR(i),
91 &type)) 91 &type))
92 continue; 92 continue;
93 if (PCI_MAPREG_TYPE(type) != PCI_MAPREG_TYPE_MEM) 93 if (PCI_MAPREG_TYPE(type) != PCI_MAPREG_TYPE_MEM)
94 continue; 94 continue;
95 if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, PCI_BAR(i), type, 95 if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, PCI_BAR(i), type,
96 &addr, &size, &flags)) 96 &addr, &size, &flags))
97 continue; 97 continue;
98 98
99 /* Try to map it if it's in range. */ 99 /* Try to map it if it's in range. */
100 if ((addr <= offset) && (offset < (addr + size))) 100 if ((addr <= offset) && (offset < (addr + size)))
101 return bus_space_mmap(pa->pa_memt, addr, 101 return bus_space_mmap(pa->pa_memt, addr,
102 (offset - addr), prot, flags); 102 (offset - addr), prot, flags);
103 103
104 /* Skip a slot if this was a 64-bit BAR. */ 104 /* Skip a slot if this was a 64-bit BAR. */
105 if ((PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_MEM) && 105 if ((PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_MEM) &&
106 (PCI_MAPREG_MEM_TYPE(type) == PCI_MAPREG_MEM_TYPE_64BIT)) 106 (PCI_MAPREG_MEM_TYPE(type) == PCI_MAPREG_MEM_TYPE_64BIT))
107 i += 1; 107 i += 1;
108 } 108 }
109 109
110 /* Failure! */ 110 /* Failure! */
111 return -1; 111 return -1;
112} 112}
113 113
114/* 114/*
115 * drmfb_pci_ioctl: Implementation of drmfb_params::dp_ioctl. Provides: 115 * drmfb_pci_ioctl: Implementation of drmfb_params::dp_ioctl. Provides:
116 * 116 *
117 * - WSDISPLAY_GET_BUSID 117 * - WSDISPLAY_GET_BUSID
118 * - WSDISPLAY_GTYPE 118 * - WSDISPLAY_GTYPE
119 * 119 *
120 * Additionally allows access to PCI registers. 120 * Additionally allows access to PCI registers.
121 * 121 *
122 * XXX Do we need to provide access to PCI registers? I can't find 122 * XXX Do we need to provide access to PCI registers? I can't find
123 * anything that uses this functionality, and as is it is very 123 * anything that uses this functionality, and as is it is very
124 * dangerous. 124 * dangerous.
125 */ 125 */
126int 126int
127drmfb_pci_ioctl(struct drmfb_softc *sc, unsigned long cmd, void *data, 127drmfb_pci_ioctl(struct drmfb_softc *sc, unsigned long cmd, void *data,
128 int flag, struct lwp *l) 128 int flag, struct lwp *l)
129{ 129{
130 struct drm_device *const dev = sc->sc_da.da_fb_helper->dev; 130 struct drm_device *const dev = sc->sc_da.da_fb_helper->dev;
131 struct pci_attach_args *const pa = &dev->pdev->pd_pa; 131 struct pci_attach_args *const pa = &dev->pdev->pd_pa;
132 132
133 switch (cmd) { 133 switch (cmd) {
134 /* PCI config read/write passthrough. */ 134 /* PCI config read/write passthrough. */
135 case PCI_IOC_CFGREAD: 135 case PCI_IOC_CFGREAD:
136 case PCI_IOC_CFGWRITE: 136 case PCI_IOC_CFGWRITE:
137 return pci_devioctl(pa->pa_pc, pa->pa_tag, cmd, data, flag, l); 137 return pci_devioctl(pa->pa_pc, pa->pa_tag, cmd, data, flag, l);
138 138
139 /* PCI-specific wsdisplay ioctls. */ 139 /* PCI-specific wsdisplay ioctls. */
140 case WSDISPLAYIO_GET_BUSID: 140 case WSDISPLAYIO_GET_BUSID:
141 return wsdisplayio_busid_pci(dev->dev, pa->pa_pc, pa->pa_tag, 141 return wsdisplayio_busid_pci(dev->dev, pa->pa_pc, pa->pa_tag,
142 data); 142 data);
143 case WSDISPLAYIO_GTYPE: 143 case WSDISPLAYIO_GTYPE:
144 *(unsigned int *)data = WSDISPLAY_TYPE_PCIVGA; 144 *(unsigned int *)data = WSDISPLAY_TYPE_PCIVGA;
145 return 0; 145 return 0;
146 146
147 default: 147 default:
148 return EPASSTHROUGH; 148 return EPASSTHROUGH;
149 } 149 }
150} 150}
151 151
152bool 152bool
153drmfb_pci_is_vga_console(struct drm_device *dev) 153drmfb_pci_is_vga_console(struct drm_device *dev)
154{ 154{
155 155
156#if NVGA > 0 156#if NVGA > 0
157 return vga_is_console(dev->pdev->pd_pa.pa_iot, -1); 157 return vga_is_console(dev->pdev->pd_pa.pa_iot, -1);
158#else 158#else
159 return false; 159 return false;
160#endif 160#endif
161} 161}