Wed Jul 24 03:10:37 2013 UTC ()
Add 16-bit (RMW) pci_{read,write}_config_word to <linux/pci.h>.


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

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

--- src/sys/external/bsd/drm2/include/linux/pci.h 2013/07/24 03:04:18 1.1.2.8
+++ src/sys/external/bsd/drm2/include/linux/pci.h 2013/07/24 03:10:37 1.1.2.9
@@ -1,188 +1,212 @@ @@ -1,188 +1,212 @@
1/* $NetBSD: pci.h,v 1.1.2.8 2013/07/24 03:04:18 riastradh Exp $ */ 1/* $NetBSD: pci.h,v 1.1.2.9 2013/07/24 03:10:37 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.
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#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/kmem.h>
38#include <sys/systm.h> 38#include <sys/systm.h>
39 39
40#include <dev/pci/pcivar.h> 40#include <dev/pci/pcivar.h>
41 41
42#include <linux/ioport.h> 42#include <linux/ioport.h>
43 43
44struct pci_bus; 44struct pci_bus;
45struct pci_device_id; 45struct pci_device_id;
46 46
47struct pci_dev { 47struct pci_dev {
48 struct pci_bus *bus; 48 struct pci_bus *bus;
49 unsigned int device; 49 unsigned int device;
50 struct pci_attach_args pd_pa; 50 struct pci_attach_args pd_pa;
51 bool pd_kludged; /* XXX pci_kludgey_find_dev hack */ 51 bool pd_kludged; /* XXX pci_kludgey_find_dev hack */
52 bool msi_enabled; 52 bool msi_enabled;
53}; 53};
54 54
55#define PCI_CAP_ID_AGP PCI_CAP_AGP 55#define PCI_CAP_ID_AGP PCI_CAP_AGP
56 56
57static inline int 57static inline int
58pci_find_capability(struct pci_dev *pdev, int cap) 58pci_find_capability(struct pci_dev *pdev, int cap)
59{ 59{
60 return pci_get_capability(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, cap, 60 return pci_get_capability(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, cap,
61 NULL, NULL); 61 NULL, NULL);
62} 62}
63 63
64static inline void 64static inline void
65pci_read_config_dword(struct pci_dev *pdev, int reg, uint32_t *valuep) 65pci_read_config_dword(struct pci_dev *pdev, int reg, uint32_t *valuep)
66{ 66{
 67 KASSERT(!ISSET(reg, 3));
67 *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg); 68 *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg);
68} 69}
69 70
70static inline void 71static inline void
71pci_write_config_dword(struct pci_dev *pdev, int reg, uint32_t value) 72pci_write_config_dword(struct pci_dev *pdev, int reg, uint32_t value)
72{ 73{
 74 KASSERT(!ISSET(reg, 3));
73 pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg, value); 75 pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg, value);
74} 76}
75 77
 78static inline void
 79pci_read_config_word(struct pci_dev *pdev, int reg, uint16_t *valuep)
 80{
 81 KASSERT(!ISSET(reg, 1));
 82 *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
 83 (reg &~ 3)) >> (ISSET(reg, 3)? 16 : 0);
 84}
 85
 86static inline void
 87pci_write_config_word(struct pci_dev *pdev, int reg, uint16_t value)
 88{
 89 const int reg32 = (reg &~ 3);
 90 const unsigned int shift = (ISSET(reg, 3)? 16 : 0);
 91 uint32_t value32;
 92
 93 KASSERT(!ISSET(reg, 1));
 94 pci_read_config_dword(pdev, reg32, &value32);
 95 value32 &=~ (0xffffUL << shift);
 96 value32 |= (value << shift);
 97 pci_write_config_dword(pdev, reg32, value32);
 98}
 99
76/* 100/*
77 * XXX pci msi 101 * XXX pci msi
78 */ 102 */
79static inline void 103static inline void
80pci_enable_msi(struct pci_dev *pdev) 104pci_enable_msi(struct pci_dev *pdev)
81{ 105{
82 KASSERT(!pdev->msi_enabled); 106 KASSERT(!pdev->msi_enabled);
83 pdev->msi_enabled = true; 107 pdev->msi_enabled = true;
84} 108}
85 109
86static inline void 110static inline void
87pci_disable_msi(struct pci_dev *pdev) 111pci_disable_msi(struct pci_dev *pdev)
88{ 112{
89 KASSERT(pdev->msi_enabled); 113 KASSERT(pdev->msi_enabled);
90 pdev->msi_enabled = false; 114 pdev->msi_enabled = false;
91} 115}
92 116
93static inline void 117static inline void
94pci_set_master(struct pci_dev *pdev) 118pci_set_master(struct pci_dev *pdev)
95{ 119{
96 pcireg_t csr; 120 pcireg_t csr;
97 121
98 csr = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, 122 csr = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
99 PCI_COMMAND_STATUS_REG); 123 PCI_COMMAND_STATUS_REG);
100 csr |= PCI_COMMAND_MASTER_ENABLE; 124 csr |= PCI_COMMAND_MASTER_ENABLE;
101 pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, 125 pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
102 PCI_COMMAND_STATUS_REG, csr); 126 PCI_COMMAND_STATUS_REG, csr);
103} 127}
104 128
105#define PCIBIOS_MIN_MEM 0 /* XXX bogus x86 kludge bollocks */ 129#define PCIBIOS_MIN_MEM 0 /* XXX bogus x86 kludge bollocks */
106 130
107static inline bus_addr_t 131static inline bus_addr_t
108pcibios_align_resource(void *p, const struct resource *resource, 132pcibios_align_resource(void *p, const struct resource *resource,
109 bus_addr_t addr, bus_size_t size) 133 bus_addr_t addr, bus_size_t size)
110{ 134{
111 panic("pcibios_align_resource has accessed unaligned neurons!"); 135 panic("pcibios_align_resource has accessed unaligned neurons!");
112} 136}
113 137
114static inline int 138static inline int
115pci_bus_alloc_resource(struct pci_bus *bus, struct resource *resource, 139pci_bus_alloc_resource(struct pci_bus *bus, struct resource *resource,
116 bus_size_t size, bus_size_t align, bus_addr_t start, int type __unused, 140 bus_size_t size, bus_size_t align, bus_addr_t start, int type __unused,
117 bus_addr_t (*align_fn)(void *, const struct resource *, bus_addr_t, 141 bus_addr_t (*align_fn)(void *, const struct resource *, bus_addr_t,
118 bus_size_t) __unused, 142 bus_size_t) __unused,
119 struct pci_dev *pdev) 143 struct pci_dev *pdev)
120{ 144{
121 const struct pci_attach_args *const pa = &pdev->pd_pa; 145 const struct pci_attach_args *const pa = &pdev->pd_pa;
122 bus_space_tag_t bst; 146 bus_space_tag_t bst;
123 int error; 147 int error;
124 148
125 switch (resource->flags) { 149 switch (resource->flags) {
126 case IORESOURCE_MEM: 150 case IORESOURCE_MEM:
127 bst = pa->pa_memt; 151 bst = pa->pa_memt;
128 break; 152 break;
129 153
130 case IORESOURCE_IO: 154 case IORESOURCE_IO:
131 bst = pa->pa_iot; 155 bst = pa->pa_iot;
132 break; 156 break;
133 157
134 default: 158 default:
135 panic("I don't know what kind of resource you want!"); 159 panic("I don't know what kind of resource you want!");
136 } 160 }
137 161
138 resource->r_bst = bst; 162 resource->r_bst = bst;
139 error = bus_space_alloc(bst, start, 0xffffffffffffffffULL /* XXX */, 163 error = bus_space_alloc(bst, start, 0xffffffffffffffffULL /* XXX */,
140 size, align, 0, 0, &resource->start, &resource->r_bsh); 164 size, align, 0, 0, &resource->start, &resource->r_bsh);
141 if (error) 165 if (error)
142 return error; 166 return error;
143 167
144 resource->size = size; 168 resource->size = size;
145 return 0; 169 return 0;
146} 170}
147 171
148/* 172/*
149 * XXX Mega-kludgerific! 173 * XXX Mega-kludgerific!
150 * 174 *
151 * XXX Doesn't check whether any such device actually exists. 175 * XXX Doesn't check whether any such device actually exists.
152 */ 176 */
153 177
154static inline struct pci_dev * 178static inline struct pci_dev *
155pci_kludgey_find_dev(struct pci_dev *pdev, int bus, int dev, int func) 179pci_kludgey_find_dev(struct pci_dev *pdev, int bus, int dev, int func)
156{ 180{
157 struct pci_dev *const otherdev = kmem_zalloc(sizeof(*otherdev), 181 struct pci_dev *const otherdev = kmem_zalloc(sizeof(*otherdev),
158 KM_SLEEP); 182 KM_SLEEP);
159 183
160#ifdef DIAGNOSTIC 184#ifdef DIAGNOSTIC
161 { 185 {
162 int obus, odev, ofunc; 186 int obus, odev, ofunc;
163 187
164 pci_decompose_tag(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, &obus, 188 pci_decompose_tag(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, &obus,
165 &odev, &ofunc); 189 &odev, &ofunc);
166 KASSERT(obus == bus); 190 KASSERT(obus == bus);
167 } 191 }
168#endif 192#endif
169 193
170 otherdev->bus = NULL; /* XXX struct pci_dev::bus */ 194 otherdev->bus = NULL; /* XXX struct pci_dev::bus */
171 otherdev->device = dev; 195 otherdev->device = dev;
172 otherdev->pd_pa = pdev->pd_pa; 196 otherdev->pd_pa = pdev->pd_pa;
173 otherdev->pd_pa.pa_tag = pci_make_tag(otherdev->pd_pa.pa_pc, 197 otherdev->pd_pa.pa_tag = pci_make_tag(otherdev->pd_pa.pa_pc,
174 bus, dev, func); 198 bus, dev, func);
175 otherdev->pd_kludged = true; 199 otherdev->pd_kludged = true;
176 200
177 return otherdev; 201 return otherdev;
178} 202}
179 203
180static inline void 204static inline void
181pci_dev_put(struct pci_dev *pdev) 205pci_dev_put(struct pci_dev *pdev)
182{ 206{
183 207
184 KASSERT(pdev->pd_kludged); 208 KASSERT(pdev->pd_kludged);
185 kmem_free(pdev, sizeof(*pdev)); 209 kmem_free(pdev, sizeof(*pdev));
186} 210}
187 211
188#endif /* _LINUX_PCI_H_ */ 212#endif /* _LINUX_PCI_H_ */