Print this page
5253 kmem_alloc/kmem_zalloc won't fail with KM_SLEEP
5254 getrbuf won't fail with KM_SLEEP
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/i86pc/io/gfx_private/gfxp_pci.c
+++ new/usr/src/uts/i86pc/io/gfx_private/gfxp_pci.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "%Z%%M% %I% %E% SMI"
28 -
29 27 #include <sys/debug.h>
30 28 #include <sys/types.h>
31 29 #include <sys/param.h>
32 30 #include <sys/time.h>
33 31 #include <sys/buf.h>
34 32 #include <sys/errno.h>
35 33 #include <sys/systm.h>
36 34 #include <sys/conf.h>
37 35 #include <sys/signal.h>
38 36 #include <sys/file.h>
39 37 #include <sys/uio.h>
40 38 #include <sys/ioctl.h>
41 39 #include <sys/map.h>
42 40 #include <sys/proc.h>
43 41 #include <sys/user.h>
44 42 #include <sys/mman.h>
45 43 #include <sys/cred.h>
46 44 #include <sys/open.h>
47 45 #include <sys/stat.h>
48 46 #include <sys/utsname.h>
49 47 #include <sys/kmem.h>
50 48 #include <sys/cmn_err.h>
51 49 #include <sys/vnode.h>
52 50 #include <vm/page.h>
53 51 #include <vm/as.h>
54 52 #include <vm/hat.h>
55 53 #include <vm/seg.h>
56 54 #include <sys/ddi.h>
57 55 #include <sys/devops.h>
58 56 #include <sys/sunddi.h>
59 57 #include <sys/ddi_impldefs.h>
60 58 #include <sys/fs/snode.h>
61 59 #include <sys/pci.h>
62 60 #include <sys/modctl.h>
63 61 #include <sys/uio.h>
64 62 #include <sys/visual_io.h>
65 63 #include <sys/fbio.h>
66 64 #include <sys/ddidmareq.h>
67 65 #include <sys/tnf_probe.h>
68 66 #include <sys/kstat.h>
69 67 #include <sys/callb.h>
70 68 #include <sys/pci_cfgspace.h>
71 69 #include "gfx_private.h"
72 70
73 71 typedef struct gfxp_pci_bsf {
74 72 uint16_t vendor;
75 73 uint16_t device;
76 74 uint8_t bus;
77 75 uint8_t slot;
78 76 uint8_t function;
79 77 uint8_t found;
80 78 dev_info_t *dip;
81 79 } gfxp_pci_bsf_t;
82 80
83 81 /* The use of pci_get?/put?_func() depends on misc/pci_autoconfig */
84 82
85 83 static int
86 84 gfxp_pci_get_bsf(dev_info_t *dip, uint8_t *bus, uint8_t *dev, uint8_t *func)
87 85 {
88 86 pci_regspec_t *pci_rp;
89 87 uint32_t length;
90 88 int rc;
91 89
92 90 /* get "reg" property */
93 91 rc = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
94 92 DDI_PROP_DONTPASS, "reg", (int **)&pci_rp,
95 93 (uint_t *)&length);
96 94 if ((rc != DDI_SUCCESS) || (length <
97 95 (sizeof (pci_regspec_t) / sizeof (int)))) {
98 96 return (DDI_FAILURE);
99 97 }
100 98
101 99 *bus = PCI_REG_BUS_G(pci_rp->pci_phys_hi);
102 100 *dev = PCI_REG_DEV_G(pci_rp->pci_phys_hi);
103 101 *func = PCI_REG_FUNC_G(pci_rp->pci_phys_hi);
104 102
105 103 /*
106 104 * free the memory allocated by ddi_prop_lookup_int_array().
107 105 */
108 106 ddi_prop_free(pci_rp);
109 107
110 108 return (DDI_SUCCESS);
111 109 }
112 110
113 111 static int
114 112 gfxp_pci_find_bsf(dev_info_t *dip, void *arg)
115 113 {
116 114 int rc;
117 115 uint8_t bus, dev, func;
118 116 gfxp_pci_bsf_t *pci_bsf;
119 117 int vendor_id, device_id, class_code;
120 118
121 119 /*
122 120 * Look for vendor-id, device-id, class-code to verify
123 121 * this is some type of PCI child node.
124 122 */
125 123 vendor_id = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
126 124 "vendor-id", -1);
127 125 device_id = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
128 126 "device-id", -1);
129 127 class_code = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
130 128 "class-code", -1);
131 129 if ((vendor_id == -1) || (device_id == -1) || (class_code == -1)) {
132 130 return (DDI_WALK_CONTINUE);
133 131 }
134 132
135 133 if (gfxp_pci_get_bsf(dip, &bus, &dev, &func) != DDI_SUCCESS)
136 134 return (DDI_WALK_TERMINATE);
137 135
138 136 pci_bsf = (gfxp_pci_bsf_t *)arg;
139 137
140 138 if ((bus == pci_bsf->bus) && (dev == pci_bsf->slot) &&
141 139 (func == pci_bsf->function)) {
142 140 pci_bsf->dip = dip;
143 141 pci_bsf->vendor = vendor_id;
144 142 pci_bsf->device = device_id;
145 143 pci_bsf->found = 1;
146 144 rc = DDI_WALK_TERMINATE;
147 145 } else {
148 146 rc = DDI_WALK_CONTINUE;
149 147 }
150 148
151 149 return (rc);
152 150 }
153 151
154 152 gfxp_acc_handle_t
155 153 gfxp_pci_init_handle(uint8_t bus, uint8_t slot, uint8_t function,
156 154 uint16_t *vendor, uint16_t *device)
↓ open down ↓ |
118 lines elided |
↑ open up ↑ |
157 155 {
158 156 dev_info_t *dip;
159 157 gfxp_pci_bsf_t *pci_bsf;
160 158
161 159 /*
162 160 * Find a PCI device based on its address, and return a unique handle
163 161 * to be used in subsequent calls to read from or write to the config
164 162 * space of this device.
165 163 */
166 164
167 - if ((pci_bsf = kmem_zalloc(sizeof (gfxp_pci_bsf_t), KM_SLEEP))
168 - == NULL) {
169 - return (NULL);
170 - }
165 + pci_bsf = kmem_zalloc(sizeof (gfxp_pci_bsf_t), KM_SLEEP);
171 166
172 167 pci_bsf->bus = bus;
173 168 pci_bsf->slot = slot;
174 169 pci_bsf->function = function;
175 170
176 171 ddi_walk_devs(ddi_root_node(), gfxp_pci_find_bsf, pci_bsf);
177 172
178 173 if (pci_bsf->found) {
179 174 dip = pci_bsf->dip;
180 175
181 176 if (vendor) *vendor = pci_bsf->vendor;
182 177 if (device) *device = pci_bsf->device;
183 178 } else {
184 179 dip = NULL;
185 180 if (vendor) *vendor = 0x0000;
186 181 if (device) *device = 0x0000;
187 182 }
188 183
189 184 kmem_free(pci_bsf, sizeof (gfxp_pci_bsf_t));
190 185
191 186 return ((gfxp_acc_handle_t)dip);
192 187 }
193 188
194 189 uint8_t
195 190 gfxp_pci_read_byte(gfxp_acc_handle_t handle, uint16_t offset)
196 191 {
197 192 dev_info_t *dip = (dev_info_t *)handle;
198 193 uint8_t val;
199 194 uint8_t bus, dev, func;
200 195
201 196 if (dip == NULL)
202 197 return ((uint8_t)~0);
203 198
204 199 if (gfxp_pci_get_bsf(dip, &bus, &dev, &func) != DDI_SUCCESS)
205 200 return ((uint8_t)~0);
206 201
207 202 val = (*pci_getb_func)(bus, dev, func, offset);
208 203 return (val);
209 204 }
210 205
211 206 uint16_t
212 207 gfxp_pci_read_word(gfxp_acc_handle_t handle, uint16_t offset)
213 208 {
214 209 dev_info_t *dip = (dev_info_t *)handle;
215 210 uint16_t val;
216 211 uint8_t bus, dev, func;
217 212
218 213 if (dip == NULL)
219 214 return ((uint16_t)~0);
220 215
221 216 if (gfxp_pci_get_bsf(dip, &bus, &dev, &func) != DDI_SUCCESS)
222 217 return ((uint16_t)~0);
223 218
224 219 val = (*pci_getw_func)(bus, dev, func, offset);
225 220 return (val);
226 221 }
227 222
228 223 uint32_t
229 224 gfxp_pci_read_dword(gfxp_acc_handle_t handle, uint16_t offset)
230 225 {
231 226 dev_info_t *dip = (dev_info_t *)handle;
232 227 uint32_t val;
233 228 uint8_t bus, dev, func;
234 229
235 230 if (dip == NULL)
236 231 return ((uint32_t)~0);
237 232
238 233 if (gfxp_pci_get_bsf(dip, &bus, &dev, &func) != DDI_SUCCESS)
239 234 return ((uint32_t)~0);
240 235
241 236 val = (*pci_getl_func)(bus, dev, func, offset);
242 237 return (val);
243 238 }
244 239
245 240 void
246 241 gfxp_pci_write_byte(gfxp_acc_handle_t handle, uint16_t offset, uint8_t value)
247 242 {
248 243 dev_info_t *dip = (dev_info_t *)handle;
249 244 uint8_t bus, dev, func;
250 245
251 246 if (dip == NULL)
252 247 return;
253 248
254 249 if (gfxp_pci_get_bsf(dip, &bus, &dev, &func) != DDI_SUCCESS)
255 250 return;
256 251
257 252 (*pci_putb_func)(bus, dev, func, offset, value);
258 253 }
259 254
260 255 void
261 256 gfxp_pci_write_word(gfxp_acc_handle_t handle, uint16_t offset, uint16_t value)
262 257 {
263 258 dev_info_t *dip = (dev_info_t *)handle;
264 259 uint8_t bus, dev, func;
265 260
266 261 if (dip == NULL)
267 262 return;
268 263
269 264 if (gfxp_pci_get_bsf(dip, &bus, &dev, &func) != DDI_SUCCESS)
270 265 return;
271 266
272 267 (*pci_putw_func)(bus, dev, func, offset, value);
273 268 }
274 269
275 270 void
276 271 gfxp_pci_write_dword(gfxp_acc_handle_t handle, uint16_t offset, uint32_t value)
277 272 {
278 273 dev_info_t *dip = (dev_info_t *)handle;
279 274 uint8_t bus, dev, func;
280 275
281 276 if (dip == NULL)
282 277 return;
283 278
284 279 if (gfxp_pci_get_bsf(dip, &bus, &dev, &func) != DDI_SUCCESS)
285 280 return;
286 281
287 282 (*pci_putl_func)(bus, dev, func, offset, value);
288 283 }
289 284
290 285 static int
291 286 gfxp_pci_find_vd(dev_info_t *dip, void *arg)
292 287 {
293 288 int rc;
294 289 gfxp_pci_bsf_t *pci_bsf;
295 290 int vendor_id, device_id, class_code;
296 291
297 292 /*
298 293 * Look for vendor-id, device-id, class-code to verify
299 294 * this is some type of PCI child node.
300 295 */
301 296 vendor_id = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
302 297 "vendor-id", -1);
303 298 device_id = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
304 299 "device-id", -1);
305 300 class_code = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
306 301 "class-code", -1);
307 302 if ((vendor_id == -1) || (device_id == -1) || (class_code == -1)) {
308 303 return (DDI_WALK_CONTINUE);
309 304 }
310 305
311 306 pci_bsf = (gfxp_pci_bsf_t *)arg;
312 307
313 308 if ((vendor_id == pci_bsf->vendor) && (device_id == pci_bsf->device)) {
314 309 pci_bsf->found = 1;
315 310 rc = DDI_WALK_TERMINATE;
316 311 } else {
317 312 rc = DDI_WALK_CONTINUE;
318 313 }
319 314
320 315 return (rc);
321 316 }
322 317
↓ open down ↓ |
142 lines elided |
↑ open up ↑ |
323 318 int
324 319 gfxp_pci_device_present(uint16_t vendor, uint16_t device)
325 320 {
326 321 gfxp_pci_bsf_t *pci_bsf;
327 322 int rv;
328 323
329 324 /*
330 325 * Find a PCI device based on its device and vendor id.
331 326 */
332 327
333 - if ((pci_bsf = kmem_zalloc(sizeof (gfxp_pci_bsf_t), KM_SLEEP)) == NULL)
334 - return (0);
328 + pci_bsf = kmem_zalloc(sizeof (gfxp_pci_bsf_t), KM_SLEEP);
335 329
336 330 pci_bsf->vendor = vendor;
337 331 pci_bsf->device = device;
338 332 ddi_walk_devs(ddi_root_node(), gfxp_pci_find_vd, pci_bsf);
339 333
340 334 if (pci_bsf->found) {
341 335 rv = 1;
342 336 } else {
343 337 rv = 0;
344 338 }
345 339
346 340 kmem_free(pci_bsf, sizeof (gfxp_pci_bsf_t));
347 341
348 342 return (rv);
349 343 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX