| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: pci_usrreq.c,v 1.20 2009/07/09 19:22:21 macallan Exp $ */ | | 1 | /* $NetBSD: pci_usrreq.c,v 1.21 2009/07/14 19:54:40 macallan Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright 2001 Wasabi Systems, Inc. | | 4 | * Copyright 2001 Wasabi Systems, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. | | 7 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -30,42 +30,43 @@ | | | @@ -30,42 +30,43 @@ |
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
35 | * POSSIBILITY OF SUCH DAMAGE. | | 35 | * POSSIBILITY OF SUCH DAMAGE. |
36 | */ | | 36 | */ |
37 | | | 37 | |
38 | /* | | 38 | /* |
39 | * User -> kernel interface for PCI bus access. | | 39 | * User -> kernel interface for PCI bus access. |
40 | */ | | 40 | */ |
41 | | | 41 | |
42 | #include <sys/cdefs.h> | | 42 | #include <sys/cdefs.h> |
43 | __KERNEL_RCSID(0, "$NetBSD: pci_usrreq.c,v 1.20 2009/07/09 19:22:21 macallan Exp $"); | | 43 | __KERNEL_RCSID(0, "$NetBSD: pci_usrreq.c,v 1.21 2009/07/14 19:54:40 macallan Exp $"); |
44 | | | 44 | |
45 | #include <sys/param.h> | | 45 | #include <sys/param.h> |
46 | #include <sys/conf.h> | | 46 | #include <sys/conf.h> |
47 | #include <sys/device.h> | | 47 | #include <sys/device.h> |
48 | #include <sys/ioctl.h> | | 48 | #include <sys/ioctl.h> |
49 | #include <sys/proc.h> | | 49 | #include <sys/proc.h> |
50 | #include <sys/systm.h> | | 50 | #include <sys/systm.h> |
51 | #include <sys/errno.h> | | 51 | #include <sys/errno.h> |
52 | #include <sys/fcntl.h> | | 52 | #include <sys/fcntl.h> |
53 | | | 53 | |
54 | #include <dev/pci/pcireg.h> | | 54 | #include <dev/pci/pcireg.h> |
55 | #include <dev/pci/pcivar.h> | | 55 | #include <dev/pci/pcivar.h> |
56 | #include <dev/pci/pciio.h> | | 56 | #include <dev/pci/pciio.h> |
57 | | | 57 | |
58 | #include "opt_pci.h" | | 58 | #include "opt_pci.h" |
| | | 59 | #include "opt_insecure.h" |
59 | | | 60 | |
60 | static int | | 61 | static int |
61 | pciopen(dev_t dev, int flags, int mode, struct lwp *l) | | 62 | pciopen(dev_t dev, int flags, int mode, struct lwp *l) |
62 | { | | 63 | { |
63 | device_t dv; | | 64 | device_t dv; |
64 | | | 65 | |
65 | dv = device_lookup(&pci_cd, minor(dev)); | | 66 | dv = device_lookup(&pci_cd, minor(dev)); |
66 | if (dv == NULL) | | 67 | if (dv == NULL) |
67 | return ENXIO; | | 68 | return ENXIO; |
68 | | | 69 | |
69 | return 0; | | 70 | return 0; |
70 | } | | 71 | } |
71 | | | 72 | |
| @@ -102,27 +103,27 @@ pciioctl(dev_t dev, u_long cmd, void *da | | | @@ -102,27 +103,27 @@ pciioctl(dev_t dev, u_long cmd, void *da |
102 | binfo = data; | | 103 | binfo = data; |
103 | binfo->busno = sc->sc_bus; | | 104 | binfo->busno = sc->sc_bus; |
104 | binfo->maxdevs = sc->sc_maxndevs; | | 105 | binfo->maxdevs = sc->sc_maxndevs; |
105 | return 0; | | 106 | return 0; |
106 | | | 107 | |
107 | default: | | 108 | default: |
108 | return ENOTTY; | | 109 | return ENOTTY; |
109 | } | | 110 | } |
110 | } | | 111 | } |
111 | | | 112 | |
112 | static paddr_t | | 113 | static paddr_t |
113 | pcimmap(dev_t dev, off_t offset, int prot) | | 114 | pcimmap(dev_t dev, off_t offset, int prot) |
114 | { | | 115 | { |
115 | #ifdef PCI_ALLOW_MMAP | | 116 | #ifdef INSECURE |
116 | struct pci_softc *sc = device_lookup_private(&pci_cd, minor(dev)); | | 117 | struct pci_softc *sc = device_lookup_private(&pci_cd, minor(dev)); |
117 | | | 118 | |
118 | /* | | 119 | /* |
119 | * Since we allow mapping of the entire bus, we | | 120 | * Since we allow mapping of the entire bus, we |
120 | * take the offset to be the address on the bus, | | 121 | * take the offset to be the address on the bus, |
121 | * and pass 0 as the offset into that range. | | 122 | * and pass 0 as the offset into that range. |
122 | * | | 123 | * |
123 | * XXX Need a way to deal with linear/prefetchable/etc. | | 124 | * XXX Need a way to deal with linear/prefetchable/etc. |
124 | * | | 125 | * |
125 | * XXX we rely on MD mmap() methods to enforce limits since these | | 126 | * XXX we rely on MD mmap() methods to enforce limits since these |
126 | * are hidden in *_tag_t structs if they exist at all | | 127 | * are hidden in *_tag_t structs if they exist at all |
127 | */ | | 128 | */ |
128 | | | 129 | |
| @@ -132,30 +133,29 @@ pcimmap(dev_t dev, off_t offset, int pro | | | @@ -132,30 +133,29 @@ pcimmap(dev_t dev, off_t offset, int pro |
132 | * XXX this assumes 64kB IO space even though some machines can have | | 133 | * XXX this assumes 64kB IO space even though some machines can have |
133 | * significantly more than that - macppc's bandit host bridge allows | | 134 | * significantly more than that - macppc's bandit host bridge allows |
134 | * 8MB IO space and sparc64 may have the entire 4GB available. The | | 135 | * 8MB IO space and sparc64 may have the entire 4GB available. The |
135 | * firmware on both tries to use the lower 64kB first though and | | 136 | * firmware on both tries to use the lower 64kB first though and |
136 | * exausting it is pretty difficult so we should be safe | | 137 | * exausting it is pretty difficult so we should be safe |
137 | */ | | 138 | */ |
138 | if ((offset >= PCI_MAGIC_IO_RANGE) && | | 139 | if ((offset >= PCI_MAGIC_IO_RANGE) && |
139 | (offset < (PCI_MAGIC_IO_RANGE + 0x10000))) { | | 140 | (offset < (PCI_MAGIC_IO_RANGE + 0x10000))) { |
140 | return bus_space_mmap(sc->sc_iot, offset - PCI_MAGIC_IO_RANGE, | | 141 | return bus_space_mmap(sc->sc_iot, offset - PCI_MAGIC_IO_RANGE, |
141 | 0, prot, 0); | | 142 | 0, prot, 0); |
142 | } | | 143 | } |
143 | #endif /* PCI_MAGIC_IO_RANGE */ | | 144 | #endif /* PCI_MAGIC_IO_RANGE */ |
144 | return bus_space_mmap(sc->sc_memt, offset, 0, prot, 0); | | 145 | return bus_space_mmap(sc->sc_memt, offset, 0, prot, 0); |
145 | #else | | 146 | #else /* INSECURE */ |
146 | /* XXX Consider this further. */ | | | |
147 | return -1; | | 147 | return -1; |
148 | #endif | | 148 | #endif /* INSECURE */ |
149 | } | | 149 | } |
150 | | | 150 | |
151 | const struct cdevsw pci_cdevsw = { | | 151 | const struct cdevsw pci_cdevsw = { |
152 | pciopen, nullclose, noread, nowrite, pciioctl, | | 152 | pciopen, nullclose, noread, nowrite, pciioctl, |
153 | nostop, notty, nopoll, pcimmap, nokqfilter, D_OTHER, | | 153 | nostop, notty, nopoll, pcimmap, nokqfilter, D_OTHER, |
154 | }; | | 154 | }; |
155 | | | 155 | |
156 | /* | | 156 | /* |
157 | * pci_devioctl: | | 157 | * pci_devioctl: |
158 | * | | 158 | * |
159 | * PCI ioctls that can be performed on devices directly. | | 159 | * PCI ioctls that can be performed on devices directly. |
160 | */ | | 160 | */ |
161 | int | | 161 | int |