xref: /titanic_51/usr/src/uts/sun4/io/px/px_util.c (revision 1a7c1b724419d3cb5fa6eea75123c6b2060ba31b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * PCI nexus utility routines:
31  *	property and config routines for attach()
32  *	reg/intr/range/assigned-address property routines for bus_map()
33  *	init_child()
34  *	fault handling
35  */
36 
37 #include <sys/types.h>
38 #include <sys/kmem.h>
39 #include <sys/async.h>
40 #include <sys/sysmacros.h>
41 #include <sys/sunddi.h>
42 #include <sys/sunndi.h>
43 #include <sys/ddi_impldefs.h>
44 #include "px_obj.h"
45 #include "pcie_pwr.h"
46 
47 /*LINTLIBRARY*/
48 
49 /*
50  * px_get_props
51  *
52  * This function is called from the attach routine to get the key
53  * properties of the pci nodes.
54  *
55  * used by: px_attach()
56  *
57  * return value: DDI_FAILURE on failure
58  */
59 int
60 px_get_props(px_t *px_p, dev_info_t *dip)
61 {
62 	int i, no_of_intrs;
63 
64 	/*
65 	 * Get the bus-ranges property.
66 	 */
67 	i = sizeof (px_p->px_bus_range);
68 	if (ddi_getlongprop_buf(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
69 	    "bus-range", (caddr_t)&px_p->px_bus_range, &i) != DDI_SUCCESS) {
70 		cmn_err(CE_WARN, "%s%d: no bus-range property\n",
71 		    ddi_driver_name(dip), ddi_get_instance(dip));
72 		return (DDI_FAILURE);
73 	}
74 	DBG(DBG_ATTACH, dip, "get_px_properties: bus-range (%x,%x)\n",
75 		px_p->px_bus_range.lo, px_p->px_bus_range.hi);
76 
77 	/*
78 	 * Get the interrupts property.
79 	 */
80 	if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
81 		"interrupts", (caddr_t)&px_p->px_inos,
82 		&px_p->px_inos_len) != DDI_SUCCESS) {
83 
84 		cmn_err(CE_WARN, "%s%d: no interrupts property\n",
85 			ddi_driver_name(dip), ddi_get_instance(dip));
86 		return (DDI_FAILURE);
87 	}
88 
89 	/*
90 	 * figure out number of interrupts in the "interrupts" property
91 	 * and convert them all into ino.
92 	 */
93 	i = ddi_getprop(DDI_DEV_T_ANY, dip, 0, "#interrupt-cells", 1);
94 	i = CELLS_1275_TO_BYTES(i);
95 	no_of_intrs = px_p->px_inos_len / i;
96 	for (i = 0; i < no_of_intrs; i++)
97 		px_p->px_inos[i] = px_p->px_inos[i] & 0x3F;
98 
99 	/*
100 	 * Get the ranges property.
101 	 */
102 	if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "ranges",
103 		(caddr_t)&px_p->px_ranges_p, &px_p->px_ranges_length) !=
104 		DDI_SUCCESS) {
105 
106 		cmn_err(CE_WARN, "%s%d: no ranges property\n",
107 			ddi_driver_name(dip), ddi_get_instance(dip));
108 		kmem_free(px_p->px_inos, px_p->px_inos_len);
109 		return (DDI_FAILURE);
110 	}
111 
112 	px_p->px_thermal_interrupt =
113 		ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
114 				"thermal-interrupt", -1);
115 	DBG(DBG_ATTACH, dip, "get_px_properties: thermal_interrupt=%d\n",
116 	    px_p->px_thermal_interrupt);
117 	return (DDI_SUCCESS);
118 }
119 
120 /*
121  * px_free_props:
122  *
123  * This routine frees the memory used to cache the "interrupts"
124  * and "ranges" properties of the pci bus device node.
125  *
126  * used by: px_detach()
127  *
128  * return value: none
129  */
130 void
131 px_free_props(px_t *px_p)
132 {
133 	kmem_free(px_p->px_inos, px_p->px_inos_len);
134 	kmem_free(px_p->px_ranges_p, px_p->px_ranges_length);
135 }
136 
137 /*
138  * px_reloc_reg
139  *
140  * If the "reg" entry (*px_rp) is relocatable, lookup "assigned-addresses"
141  * property to fetch corresponding relocated address.
142  *
143  * used by: px_map()
144  *
145  * return value:
146  *
147  *	DDI_SUCCESS		- on success
148  *	DDI_ME_INVAL		- regspec is invalid
149  */
150 int
151 px_reloc_reg(dev_info_t *dip, dev_info_t *rdip, px_t *px_p,
152 	pci_regspec_t *rp)
153 {
154 	int assign_len, assign_entries, i;
155 	pci_regspec_t *assign_p;
156 	uint32_t phys_hi = rp->pci_phys_hi;
157 	uint32_t space_type = phys_hi & PCI_REG_ADDR_M;	/* 28-bit */
158 
159 	DBG(DBG_MAP | DBG_CONT, dip, "\tpx_reloc_reg fr: %x.%x.%x %x.%x\n",
160 		rp->pci_phys_hi, rp->pci_phys_mid, rp->pci_phys_low,
161 		rp->pci_size_hi, rp->pci_size_low);
162 
163 	if (space_type == PCI_ADDR_CONFIG || phys_hi & PCI_RELOCAT_B)
164 		return (DDI_SUCCESS);
165 
166 	/*
167 	 * Hot plug will be taken care of later
168 	 * if (px_p->hotplug_capable == B_FALSE)
169 	 */
170 	{
171 		uint32_t bus = PCI_REG_BUS_G(phys_hi);
172 		if (bus < px_p->px_bus_range.lo ||
173 		    bus > px_p->px_bus_range.hi) {
174 			DBG(DBG_MAP | DBG_CONT, dip, "bad bus# (%x)\n", bus);
175 			return (DDI_ME_INVAL);
176 		}
177 	}
178 
179 	i = ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
180 		"assigned-addresses", (caddr_t)&assign_p, &assign_len);
181 	if (i) {
182 		DBG(DBG_MAP | DBG_CONT, dip, "%s%d: assigned-addresses %d\n",
183 			ddi_driver_name(rdip), ddi_get_instance(rdip), i);
184 		return (DDI_ME_INVAL);
185 	}
186 
187 	assign_entries = assign_len / sizeof (pci_regspec_t);
188 	for (i = 0; i < assign_entries; i++, assign_p++) {
189 		uint32_t assign_type = assign_p->pci_phys_hi & PCI_REG_ADDR_M;
190 		uint32_t assign_addr = PCI_REG_BDFR_G(assign_p->pci_phys_hi);
191 
192 		if (PCI_REG_BDFR_G(phys_hi) != assign_addr)
193 			continue;
194 		if (space_type == assign_type) { /* exact match */
195 			rp->pci_phys_low += assign_p->pci_phys_low;
196 			break;
197 		}
198 		if (space_type == PCI_ADDR_MEM64 &&
199 			assign_type == PCI_ADDR_MEM32) {
200 			rp->pci_phys_low += assign_p->pci_phys_low;
201 			rp->pci_phys_hi ^= PCI_ADDR_MEM64 ^ PCI_ADDR_MEM32;
202 			break;
203 		}
204 	}
205 	kmem_free(assign_p - i, assign_len);
206 	DBG(DBG_MAP | DBG_CONT, dip, "\tpx_reloc_reg to: %x.%x.%x %x.%x <%d>\n",
207 		rp->pci_phys_hi, rp->pci_phys_mid, rp->pci_phys_low,
208 		rp->pci_size_hi, rp->pci_size_low, i);
209 	return (i < assign_entries ? DDI_SUCCESS : DDI_ME_INVAL);
210 }
211 
212 /*
213  * use "ranges" to translate relocated pci regspec into parent space
214  */
215 int
216 px_xlate_reg(px_t *px_p, pci_regspec_t *px_rp, struct regspec *new_rp)
217 {
218 	int n;
219 	px_ranges_t *rng_p = px_p->px_ranges_p;
220 	int rng_n = px_p->px_ranges_length / sizeof (px_ranges_t);
221 
222 	uint32_t space_type = PCI_REG_ADDR_G(px_rp->pci_phys_hi);
223 	uint32_t reg_end, reg_begin = px_rp->pci_phys_low;
224 	uint32_t sz = px_rp->pci_size_low;
225 
226 	uint32_t rng_begin, rng_end;
227 
228 	if (space_type == PCI_REG_ADDR_G(PCI_ADDR_CONFIG)) {
229 		if (reg_begin > PCI_CONF_HDR_SIZE)
230 			return (DDI_ME_INVAL);
231 		sz = sz ? MIN(sz, PCI_CONF_HDR_SIZE) : PCI_CONF_HDR_SIZE;
232 		reg_begin += px_rp->pci_phys_hi << 4;
233 	}
234 	reg_end = reg_begin + sz - 1;
235 
236 	for (n = 0; n < rng_n; n++, rng_p++) {
237 		if (space_type != PCI_REG_ADDR_G(rng_p->child_high))
238 			continue;	/* not the same space type */
239 
240 		rng_begin = rng_p->child_low;
241 		if (space_type == PCI_REG_ADDR_G(PCI_ADDR_CONFIG))
242 			rng_begin += rng_p->child_high;
243 
244 		rng_end = rng_begin + rng_p->size_low - 1;
245 		if (reg_begin >= rng_begin && reg_end <= rng_end)
246 			break;
247 	}
248 	if (n >= rng_n)
249 		return (DDI_ME_REGSPEC_RANGE);
250 
251 	new_rp->regspec_addr = reg_begin - rng_begin + rng_p->parent_low;
252 	new_rp->regspec_bustype = rng_p->parent_high;
253 	new_rp->regspec_size = sz;
254 	DBG(DBG_MAP | DBG_CONT, px_p->px_dip,
255 		"\tpx_xlate_reg: entry %d new_rp %x.%x %x\n",
256 		n, new_rp->regspec_bustype, new_rp->regspec_addr, sz);
257 
258 	return (DDI_SUCCESS);
259 }
260 
261 /*
262  * px_report_dev
263  *
264  * This function is called from our control ops routine on a
265  * DDI_CTLOPS_REPORTDEV request.
266  *
267  * The display format is
268  *
269  *	<name><inst> at <pname><pinst> device <dev> function <func>
270  *
271  * where
272  *
273  *	<name>		this device's name property
274  *	<inst>		this device's instance number
275  *	<name>		parent device's name property
276  *	<inst>		parent device's instance number
277  *	<dev>		this device's device number
278  *	<func>		this device's function number
279  */
280 int
281 px_report_dev(dev_info_t *dip)
282 {
283 	if (dip == (dev_info_t *)0)
284 		return (DDI_FAILURE);
285 	cmn_err(CE_CONT, "?PCI Express-device: %s@%s, %s%d\n",
286 	    ddi_node_name(dip), ddi_get_name_addr(dip),
287 	    ddi_driver_name(dip),
288 	    ddi_get_instance(dip));
289 	return (DDI_SUCCESS);
290 }
291 
292 
293 /*
294  * reg property for pcimem nodes that covers the entire address
295  * space for the node:  config, io, or memory.
296  */
297 pci_regspec_t pci_pcimem_reg[3] =
298 {
299 	{PCI_ADDR_CONFIG,			0, 0, 0, 0x800000	},
300 	{(uint_t)(PCI_ADDR_IO|PCI_RELOCAT_B),	0, 0, 0, PX_IO_SIZE	},
301 	{(uint_t)(PCI_ADDR_MEM32|PCI_RELOCAT_B), 0, 0, 0, PX_MEM_SIZE	}
302 };
303 
304 /*
305  * px_name_child
306  *
307  * This function is called from init_child to name a node. It is
308  * also passed as a callback for node merging functions.
309  *
310  * return value: DDI_SUCCESS, DDI_FAILURE
311  */
312 static int
313 px_name_child(dev_info_t *child, char *name, int namelen)
314 {
315 	pci_regspec_t *pci_rp;
316 	int reglen;
317 	uint_t func;
318 	char **unit_addr;
319 	uint_t n;
320 
321 	/*
322 	 * Set the address portion of the node name based on
323 	 * unit-address property, if it exists.
324 	 * The interpretation of the unit-address is DD[,F]
325 	 * where DD is the device id and F is the function.
326 	 */
327 	if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child,
328 	    DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) ==
329 	    DDI_PROP_SUCCESS) {
330 		if (n != 1 || *unit_addr == NULL || **unit_addr == 0) {
331 			cmn_err(CE_WARN, "unit-address property in %s.conf"
332 			    " not well-formed", ddi_driver_name(child));
333 			ddi_prop_free(unit_addr);
334 			return (DDI_FAILURE);
335 		}
336 		(void) snprintf(name, namelen, "%s", *unit_addr);
337 		ddi_prop_free(unit_addr);
338 		return (DDI_SUCCESS);
339 	}
340 
341 	/*
342 	 * The unit-address property is does not exist. Set the address
343 	 * portion of the node name based on the function and device number.
344 	 */
345 	if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
346 	    "reg", (int **)&pci_rp, (uint_t *)&reglen) == DDI_SUCCESS) {
347 		if (((reglen * sizeof (int)) % sizeof (pci_regspec_t)) != 0) {
348 			cmn_err(CE_WARN, "reg property not well-formed");
349 			return (DDI_FAILURE);
350 		}
351 
352 		func = PCI_REG_FUNC_G(pci_rp[0].pci_phys_hi);
353 		if (func != 0)
354 			(void) snprintf(name, namelen, "%x,%x",
355 				PCI_REG_DEV_G(pci_rp[0].pci_phys_hi), func);
356 		else
357 			(void) snprintf(name, namelen, "%x",
358 				PCI_REG_DEV_G(pci_rp[0].pci_phys_hi));
359 		ddi_prop_free(pci_rp);
360 		return (DDI_SUCCESS);
361 	}
362 
363 	cmn_err(CE_WARN, "cannot name pci child '%s'", ddi_node_name(child));
364 	return (DDI_FAILURE);
365 }
366 
367 int
368 px_uninit_child(px_t *px_p, dev_info_t *child)
369 {
370 	DBG(DBG_INIT_CLD, px_p->px_dip,
371 	    "DDI_CTLOPS_UNINITCHILD: arg=%s%d\n",
372 	    ddi_driver_name(child), ddi_get_instance(child));
373 
374 	ddi_set_name_addr(child, NULL);
375 	ddi_remove_minor_node(child, NULL);
376 	impl_rem_dev_props(child);
377 
378 	DBG(DBG_PWR, ddi_get_parent(child), "\n\n");
379 
380 	pcie_uninitchild(child);
381 
382 	return (DDI_SUCCESS);
383 }
384 
385 /*
386  * px_init_child
387  *
388  * This function is called from our control ops routine on a
389  * DDI_CTLOPS_INITCHILD request.  It builds and sets the device's
390  * parent private data area.
391  *
392  * used by: pci_ctlops()
393  *
394  * return value: none
395  */
396 int
397 px_init_child(px_t *px_p, dev_info_t *child)
398 {
399 	dev_info_t	*parent_dip = px_p->px_dip;
400 	pci_regspec_t	*pci_rp;
401 	char		name[10];
402 	int		i, no_config;
403 
404 	/*
405 	 * The following is a special case for pcimem nodes.
406 	 * For these nodes we create a reg property with a
407 	 * single entry that covers the entire address space
408 	 * for the node (config, io or memory).
409 	 */
410 	if (strcmp(ddi_driver_name(child), "pcimem") == 0) {
411 		(void) ddi_prop_create(DDI_DEV_T_NONE, child,
412 		    DDI_PROP_CANSLEEP, "reg", (caddr_t)pci_pcimem_reg,
413 		    sizeof (pci_pcimem_reg));
414 		ddi_set_name_addr(child, "0");
415 		ddi_set_parent_data(child, NULL);
416 		return (DDI_SUCCESS);
417 	}
418 
419 	/*
420 	 * Check whether the node has config space or is a hard decode
421 	 * node (possibly created by a driver.conf file).
422 	 */
423 	no_config = ddi_prop_get_int(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
424 	    "no-config", 0);
425 
426 	/*
427 	 * Pseudo nodes indicate a prototype node with per-instance
428 	 * properties to be merged into the real h/w device node.
429 	 * However, do not merge if the no-config property is set
430 	 * (see PSARC 2000/088).
431 	 */
432 	if ((ndi_dev_is_persistent_node(child) == 0) && (no_config == 0)) {
433 		extern int pci_allow_pseudo_children;
434 
435 		if (ddi_getlongprop(DDI_DEV_T_ANY, child,
436 		    DDI_PROP_DONTPASS, "reg", (caddr_t)&pci_rp, &i) ==
437 		    DDI_SUCCESS) {
438 			cmn_err(CE_WARN, "cannot merge prototype from %s.conf",
439 			    ddi_driver_name(child));
440 			kmem_free(pci_rp, i);
441 			return (DDI_NOT_WELL_FORMED);
442 		}
443 		/*
444 		 * Name the child
445 		 */
446 		if (px_name_child(child, name, 10) != DDI_SUCCESS)
447 			return (DDI_FAILURE);
448 
449 		ddi_set_name_addr(child, name);
450 		ddi_set_parent_data(child, NULL);
451 
452 		/*
453 		 * Try to merge the properties from this prototype
454 		 * node into real h/w nodes.
455 		 */
456 		if (ndi_merge_node(child, px_name_child) == DDI_SUCCESS) {
457 			/*
458 			 * Merged ok - return failure to remove the node.
459 			 */
460 			ddi_set_name_addr(child, NULL);
461 			return (DDI_FAILURE);
462 		}
463 
464 		/* workaround for ddivs to run under PCI */
465 		if (pci_allow_pseudo_children)
466 			return (DDI_SUCCESS);
467 
468 		cmn_err(CE_WARN, "!%s@%s: %s.conf properties not merged",
469 		    ddi_driver_name(child), ddi_get_name_addr(child),
470 		    ddi_driver_name(child));
471 		ddi_set_name_addr(child, NULL);
472 		return (DDI_NOT_WELL_FORMED);
473 	}
474 
475 	if (px_name_child(child, name, 10) != DDI_SUCCESS)
476 		return (DDI_FAILURE);
477 	ddi_set_name_addr(child, name);
478 
479 	if (no_config != 0) {
480 		/*
481 		 * There is no config space so there's nothing more to do.
482 		 */
483 		return (DDI_SUCCESS);
484 	}
485 
486 	if (pcie_pm_hold(parent_dip) != DDI_SUCCESS) {
487 		DBG(DBG_PWR, parent_dip,
488 		    "INITCHILD: px_pm_hold failed\n");
489 		return (DDI_FAILURE);
490 	}
491 	/* Any return of DDI_FAILURE after this must call px_pm_release */
492 
493 	/*
494 	 * If configuration registers were previously saved by
495 	 * child (before it went to D3), then let the child do the
496 	 * restore to set up the config regs as it'll first need to
497 	 * power the device out of D3.
498 	 */
499 	if (ddi_prop_exists(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
500 	    "config-regs-saved-by-child") == 1) {
501 		DBG(DBG_PWR, child,
502 		    "INITCHILD: config regs to be restored by child\n");
503 
504 		return (DDI_SUCCESS);
505 	}
506 
507 	DBG(DBG_PWR, parent_dip,
508 	    "INITCHILD: config regs setup for %s@%s\n",
509 	    ddi_node_name(child), ddi_get_name_addr(child));
510 
511 	pcie_initchild(child);
512 
513 	/*
514 	 * Handle chip specific init-child tasks.
515 	 */
516 	pcie_pm_release(parent_dip);
517 
518 	return (DDI_SUCCESS);
519 }
520 
521 /*
522  * px_get_reg_set_size
523  *
524  * Given a dev info pointer to a pci child and a register number, this
525  * routine returns the size element of that reg set property.
526  *
527  * used by: pci_ctlops() - DDI_CTLOPS_REGSIZE
528  *
529  * return value: size of reg set on success, 0 on error
530  */
531 off_t
532 px_get_reg_set_size(dev_info_t *child, int rnumber)
533 {
534 	pci_regspec_t *pci_rp;
535 	off_t size = 0;
536 	int i;
537 
538 	if (rnumber < 0)
539 		return (0);
540 
541 	/*
542 	 * Get the reg property for the device.
543 	 */
544 	if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, "reg",
545 	    (caddr_t)&pci_rp, &i) != DDI_SUCCESS)
546 		return (0);
547 
548 	if (rnumber >= (i / (int)sizeof (pci_regspec_t)))
549 		goto done;
550 
551 	size = pci_rp[rnumber].pci_size_low |
552 		((uint64_t)pci_rp[rnumber].pci_size_hi << 32);
553 done:
554 	kmem_free(pci_rp, i);
555 	return (size);
556 }
557 
558 
559 /*
560  * px_get_nreg_set
561  *
562  * Given a dev info pointer to a pci child, this routine returns the
563  * number of sets in its "reg" property.
564  *
565  * used by: pci_ctlops() - DDI_CTLOPS_NREGS
566  *
567  * return value: # of reg sets on success, zero on error
568  */
569 uint_t
570 px_get_nreg_set(dev_info_t *child)
571 {
572 	pci_regspec_t *pci_rp;
573 	int i, n;
574 
575 	/*
576 	 * Get the reg property for the device.
577 	 */
578 	if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, "reg",
579 	    (caddr_t)&pci_rp, &i) != DDI_SUCCESS)
580 		return (0);
581 
582 	n = i / (int)sizeof (pci_regspec_t);
583 	kmem_free(pci_rp, i);
584 	return (n);
585 }
586 
587 
588 /*
589  * px_get_nintr
590  *
591  * Given a dev info pointer to a pci child, this routine returns the
592  * number of items in its "interrupts" property.
593  *
594  * used by: pci_ctlops() - DDI_CTLOPS_NREGS
595  *
596  * return value: # of interrupts on success, zero on error
597  */
598 uint_t
599 px_get_nintr(dev_info_t *child)
600 {
601 	int *pci_ip;
602 	int i, n;
603 
604 	if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
605 	    "interrupts", (caddr_t)&pci_ip, &i) != DDI_SUCCESS)
606 		return (0);
607 
608 	n = i / (int)sizeof (uint_t);
609 	kmem_free(pci_ip, i);
610 	return (n);
611 }
612 
613 uint64_t
614 px_get_cfg_pabase(px_t *px_p)
615 {
616 	int i;
617 	px_ranges_t *rangep = px_p->px_ranges_p;
618 	int nrange = px_p->px_ranges_length / sizeof (px_ranges_t);
619 	uint32_t cfg_space_type = PCI_REG_ADDR_G(PCI_ADDR_CONFIG);
620 
621 	ASSERT(cfg_space_type == 0);
622 
623 	for (i = 0; i < nrange; i++, rangep++) {
624 		if (PCI_REG_ADDR_G(rangep->child_high) == cfg_space_type)
625 			break;
626 	}
627 
628 	if (i >= nrange)
629 		cmn_err(CE_PANIC, "no cfg space in px(%x) ranges prop.\n",
630 			(void *)px_p);
631 
632 	return (((uint64_t)rangep->parent_high << 32) | rangep->parent_low);
633 }
634 
635 /*
636  * decodes standard PCI config space 16bit error status reg
637  */
638 int
639 px_log_cfg_err(dev_info_t *dip, ushort_t status_reg, char *err_msg)
640 {
641 	int nerr = ddi_get_instance(dip); /* temp for instance */
642 	uint64_t perr_fatal = px_perr_fatal & (1 << nerr);
643 	uint64_t serr_fatal = px_serr_fatal & (1 << nerr);
644 	nerr = 0;
645 
646 	if ((status_reg & PCI_STAT_PERROR) && perr_fatal)
647 		nerr++;
648 	if ((status_reg & PCI_STAT_S_SYSERR) && serr_fatal)
649 		nerr++;
650 	if (status_reg & PCI_STAT_R_MAST_AB)
651 		nerr++;
652 	if ((status_reg & PCI_STAT_S_PERROR) && perr_fatal)
653 		nerr++;
654 
655 	cmn_err(CE_WARN, "%s%d: %sPCI Express config space CSR=0x%b",
656 	    ddi_driver_name(dip), ddi_get_instance(dip), err_msg,
657 	    (uint32_t)status_reg, PX_STATUS_BITS);
658 
659 	return (nerr);
660 }
661