xref: /titanic_50/usr/src/uts/sun4v/io/px/px_lib4v.c (revision afd1ac7b1c9a8cdf273c865aa5e9a14620341443)
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 #include <sys/types.h>
30 #include <sys/sysmacros.h>
31 #include <sys/ddi.h>
32 #include <sys/async.h>
33 #include <sys/sunddi.h>
34 #include <sys/ddifm.h>
35 #include <sys/fm/protocol.h>
36 #include <sys/vmem.h>
37 #include <sys/intr.h>
38 #include <sys/ivintr.h>
39 #include <sys/errno.h>
40 #include <sys/hypervisor_api.h>
41 #include <px_obj.h>
42 #include <sys/machsystm.h>
43 #include "px_lib4v.h"
44 #include "px_err.h"
45 
46 /* mask for the ranges property in calculating the real PFN range */
47 uint_t px_ranges_phi_mask = ((1 << 28) -1);
48 
49 int
50 px_lib_dev_init(dev_info_t *dip, devhandle_t *dev_hdl)
51 {
52 	px_nexus_regspec_t	*rp;
53 	uint_t			reglen;
54 	int			ret;
55 
56 	DBG(DBG_ATTACH, dip, "px_lib_dev_init: dip 0x%p\n", dip);
57 
58 	ret = ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
59 	    "reg", (uchar_t **)&rp, &reglen);
60 	if (ret != DDI_PROP_SUCCESS) {
61 		DBG(DBG_ATTACH, dip, "px_lib_dev_init failed ret=%d\n", ret);
62 		return (DDI_FAILURE);
63 	}
64 
65 	/*
66 	 * Initilize device handle. The device handle uniquely identifies
67 	 * a SUN4V device. It consists of the lower 28-bits of the hi-cell
68 	 * of the first entry of the SUN4V device's "reg" property as
69 	 * defined by the SUN4V Bus Binding to Open Firmware.
70 	 */
71 	*dev_hdl = (devhandle_t)((rp->phys_addr >> 32) & DEVHDLE_MASK);
72 
73 	ddi_prop_free(rp);
74 
75 	DBG(DBG_ATTACH, dip, "px_lib_dev_init: dev_hdl 0x%llx\n", *dev_hdl);
76 
77 	return (DDI_SUCCESS);
78 }
79 
80 /*ARGSUSED*/
81 int
82 px_lib_dev_fini(dev_info_t *dip)
83 {
84 	DBG(DBG_DETACH, dip, "px_lib_dev_fini: dip 0x%p\n", dip);
85 
86 	return (DDI_SUCCESS);
87 }
88 
89 /*ARGSUSED*/
90 int
91 px_lib_intr_devino_to_sysino(dev_info_t *dip, devino_t devino,
92     sysino_t *sysino)
93 {
94 	uint64_t	ret;
95 
96 	DBG(DBG_LIB_INT, dip, "px_lib_intr_devino_to_sysino: dip 0x%p "
97 	    "devino 0x%x\n", dip, devino);
98 
99 	if ((ret = hvio_intr_devino_to_sysino(DIP_TO_HANDLE(dip),
100 	    devino, sysino)) != H_EOK) {
101 		DBG(DBG_LIB_INT, dip,
102 		    "hvio_intr_devino_to_sysino failed, ret 0x%lx\n", ret);
103 		return (DDI_FAILURE);
104 	}
105 
106 	DBG(DBG_LIB_INT, dip, "px_lib_intr_devino_to_sysino: sysino 0x%llx\n",
107 	    *sysino);
108 
109 	return (DDI_SUCCESS);
110 }
111 
112 /*ARGSUSED*/
113 int
114 px_lib_intr_getvalid(dev_info_t *dip, sysino_t sysino,
115     intr_valid_state_t *intr_valid_state)
116 {
117 	uint64_t	ret;
118 
119 	DBG(DBG_LIB_INT, dip, "px_lib_intr_getvalid: dip 0x%p sysino 0x%llx\n",
120 	    dip, sysino);
121 
122 	if ((ret = hvio_intr_getvalid(sysino,
123 	    (int *)intr_valid_state)) != H_EOK) {
124 		DBG(DBG_LIB_INT, dip, "hvio_intr_getvalid failed, ret 0x%lx\n",
125 		    ret);
126 		return (DDI_FAILURE);
127 	}
128 
129 	DBG(DBG_LIB_INT, dip, "px_lib_intr_getvalid: intr_valid_state 0x%x\n",
130 	    *intr_valid_state);
131 
132 	return (DDI_SUCCESS);
133 }
134 
135 /*ARGSUSED*/
136 int
137 px_lib_intr_setvalid(dev_info_t *dip, sysino_t sysino,
138     intr_valid_state_t intr_valid_state)
139 {
140 	uint64_t	ret;
141 
142 	DBG(DBG_LIB_INT, dip, "px_lib_intr_setvalid: dip 0x%p sysino 0x%llx "
143 	    "intr_valid_state 0x%x\n", dip, sysino, intr_valid_state);
144 
145 	if ((ret = hvio_intr_setvalid(sysino, intr_valid_state)) != H_EOK) {
146 		DBG(DBG_LIB_INT, dip, "hvio_intr_setvalid failed, ret 0x%lx\n",
147 		    ret);
148 		return (DDI_FAILURE);
149 	}
150 
151 	return (DDI_SUCCESS);
152 }
153 
154 /*ARGSUSED*/
155 int
156 px_lib_intr_getstate(dev_info_t *dip, sysino_t sysino,
157     intr_state_t *intr_state)
158 {
159 	uint64_t	ret;
160 
161 	DBG(DBG_LIB_INT, dip, "px_lib_intr_getstate: dip 0x%p sysino 0x%llx\n",
162 	    dip, sysino);
163 
164 	if ((ret = hvio_intr_getstate(sysino, (int *)intr_state)) != H_EOK) {
165 		DBG(DBG_LIB_INT, dip, "hvio_intr_getstate failed, ret 0x%lx\n",
166 		    ret);
167 		return (DDI_FAILURE);
168 	}
169 
170 	DBG(DBG_LIB_INT, dip, "px_lib_intr_getstate: intr_state 0x%x\n",
171 	    *intr_state);
172 
173 	return (DDI_SUCCESS);
174 }
175 
176 /*ARGSUSED*/
177 int
178 px_lib_intr_setstate(dev_info_t *dip, sysino_t sysino,
179     intr_state_t intr_state)
180 {
181 	uint64_t	ret;
182 
183 	DBG(DBG_LIB_INT, dip, "px_lib_intr_setstate: dip 0x%p sysino 0x%llx "
184 	    "intr_state 0x%x\n", dip, sysino, intr_state);
185 
186 	if ((ret = hvio_intr_setstate(sysino, intr_state)) != H_EOK) {
187 		DBG(DBG_LIB_INT, dip, "hvio_intr_setstate failed, ret 0x%lx\n",
188 		    ret);
189 		return (DDI_FAILURE);
190 	}
191 
192 	return (DDI_SUCCESS);
193 }
194 
195 /*ARGSUSED*/
196 int
197 px_lib_intr_gettarget(dev_info_t *dip, sysino_t sysino, cpuid_t *cpuid)
198 {
199 	uint64_t	ret;
200 
201 	DBG(DBG_LIB_INT, dip, "px_lib_intr_gettarget: dip 0x%p sysino 0x%llx\n",
202 	    dip, sysino);
203 
204 	if ((ret = hvio_intr_gettarget(sysino, cpuid)) != H_EOK) {
205 		DBG(DBG_LIB_INT, dip,
206 		    "hvio_intr_gettarget failed, ret 0x%lx\n", ret);
207 		return (DDI_FAILURE);
208 	}
209 
210 	DBG(DBG_LIB_INT, dip, "px_lib_intr_gettarget: cpuid 0x%x\n", cpuid);
211 
212 	return (DDI_SUCCESS);
213 }
214 
215 /*ARGSUSED*/
216 int
217 px_lib_intr_settarget(dev_info_t *dip, sysino_t sysino, cpuid_t cpuid)
218 {
219 	uint64_t	ret;
220 
221 	DBG(DBG_LIB_INT, dip, "px_lib_intr_settarget: dip 0x%p sysino 0x%llx "
222 	    "cpuid 0x%x\n", dip, sysino, cpuid);
223 
224 	if ((ret = hvio_intr_settarget(sysino, cpuid)) != H_EOK) {
225 		DBG(DBG_LIB_INT, dip,
226 		    "hvio_intr_settarget failed, ret 0x%lx\n", ret);
227 		return (DDI_FAILURE);
228 	}
229 
230 	return (DDI_SUCCESS);
231 }
232 
233 /*ARGSUSED*/
234 int
235 px_lib_intr_reset(dev_info_t *dip)
236 {
237 	px_t			*px_p = DIP_TO_STATE(dip);
238 	px_ib_t			*ib_p = px_p->px_ib_p;
239 	px_ib_ino_info_t	*ino_p;
240 
241 	DBG(DBG_LIB_INT, dip, "px_lib_intr_reset: dip 0x%p\n", dip);
242 
243 	mutex_enter(&ib_p->ib_ino_lst_mutex);
244 
245 	/* Reset all Interrupts */
246 	for (ino_p = ib_p->ib_ino_lst; ino_p; ino_p = ino_p->ino_next) {
247 		if (px_lib_intr_setstate(dip, ino_p->ino_sysino,
248 		    INTR_IDLE_STATE) != DDI_SUCCESS)
249 			return (BF_FATAL);
250 	}
251 
252 	mutex_exit(&ib_p->ib_ino_lst_mutex);
253 
254 	return (BF_NONE);
255 }
256 
257 /*ARGSUSED*/
258 int
259 px_lib_iommu_map(dev_info_t *dip, tsbid_t tsbid, pages_t pages,
260     io_attributes_t io_attributes, void *addr, size_t pfn_index,
261     int flag)
262 {
263 	pages_t		pgs_mapped = 0, pgs_cnt = 0;
264 	pages_t		pgs = pages;
265 	tsbnum_t	tsb_num = PCI_TSBID_TO_TSBNUM(tsbid);
266 	tsbindex_t	tsbindex = PCI_TSBID_TO_TSBINDEX(tsbid);
267 	io_page_list_t	*io_page_list_p, *ptr;
268 	int		i, err = DDI_SUCCESS;
269 	uint64_t	ret;
270 
271 	DBG(DBG_LIB_DMA, dip, "px_lib_iommu_map: dip 0x%p tsbid 0x%llx "
272 	    "pages 0x%x atrr 0x%x addr 0x%p pfn_index 0x%llx, flag 0x%x\n",
273 	    dip, tsbid, pages, io_attributes, addr, pfn_index, flag);
274 
275 	if ((ptr = kmem_zalloc((pages * sizeof (io_page_list_t)),
276 	    KM_NOSLEEP)) == NULL) {
277 		DBG(DBG_LIB_DMA, dip, "px_lib_iommu_map: kmem_zalloc failed\n");
278 		return (DDI_FAILURE);
279 	}
280 
281 	io_page_list_p = (io_page_list_t *)ptr;
282 
283 	if (flag == MMU_MAP_MP) {
284 		ddi_dma_impl_t	*mp = (ddi_dma_impl_t *)addr;
285 
286 		for (i = 0; i < pages; i++, pfn_index++) {
287 			px_iopfn_t pfn = PX_GET_MP_PFN(mp, pfn_index);
288 			io_page_list_p[i] = MMU_PTOB(pfn);
289 		}
290 	} else {
291 		caddr_t	a = (caddr_t)addr;
292 
293 		for (i = 0; i < pages; i++, a += MMU_PAGE_SIZE) {
294 			px_iopfn_t pfn = hat_getpfnum(kas.a_hat, a);
295 			io_page_list_p[i] = MMU_PTOB(pfn);
296 		}
297 	}
298 
299 	io_page_list_p = (io_page_list_t *)va_to_pa(ptr);
300 	pgs_mapped = 0;
301 
302 	while (pgs) {
303 		if ((ret = hvio_iommu_map(DIP_TO_HANDLE(dip),
304 		    PCI_TSBID(tsb_num, tsbindex), pgs, io_attributes,
305 		    io_page_list_p, &pgs_cnt)) != H_EOK) {
306 			DBG(DBG_LIB_DMA, dip,
307 			    "hvio_iommu_map failed, ret 0x%lx\n", ret);
308 			err = DDI_FAILURE;
309 			break;
310 		}
311 
312 		pgs_mapped += pgs_cnt;
313 		pgs -= pgs_cnt;
314 		tsbindex += pgs_cnt;
315 		io_page_list_p += pgs_cnt;
316 		pgs_cnt = 0;
317 	}
318 
319 	if ((err == DDI_FAILURE) && (pgs_mapped))
320 		(void) px_lib_iommu_demap(dip, tsbid, pgs_mapped);
321 
322 	kmem_free(ptr, (pages * sizeof (io_page_list_t)));
323 
324 	return (err);
325 }
326 
327 /*ARGSUSED*/
328 int
329 px_lib_iommu_demap(dev_info_t *dip, tsbid_t tsbid, pages_t pages)
330 {
331 	tsbnum_t	tsb_num = PCI_TSBID_TO_TSBNUM(tsbid);
332 	tsbindex_t	tsbindex = PCI_TSBID_TO_TSBINDEX(tsbid);
333 	pages_t		pgs_cnt = 0;
334 	uint64_t	ret;
335 
336 	DBG(DBG_LIB_DMA, dip, "px_lib_iommu_demap: dip 0x%p tsbid 0x%llx "
337 	    "pages 0x%x\n", dip, tsbid, pages);
338 
339 	while (pages) {
340 		if ((ret = hvio_iommu_demap(DIP_TO_HANDLE(dip),
341 		    PCI_TSBID(tsb_num, tsbindex), pages,
342 		    &pgs_cnt)) != H_EOK) {
343 			DBG(DBG_LIB_DMA, dip,
344 			    "hvio_iommu_demap failed, ret 0x%lx\n", ret);
345 			return (DDI_FAILURE);
346 		}
347 
348 		pages -= pgs_cnt;
349 		tsbindex += pgs_cnt;
350 		pgs_cnt = 0;
351 	}
352 
353 	return (DDI_SUCCESS);
354 }
355 
356 /*ARGSUSED*/
357 int
358 px_lib_iommu_getmap(dev_info_t *dip, tsbid_t tsbid,
359     io_attributes_t *attributes_p, r_addr_t *r_addr_p)
360 {
361 	uint64_t	ret;
362 
363 	DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getmap: dip 0x%p tsbid 0x%llx\n",
364 	    dip, tsbid);
365 
366 	if ((ret = hvio_iommu_getmap(DIP_TO_HANDLE(dip), tsbid,
367 	    attributes_p, r_addr_p)) != H_EOK) {
368 		DBG(DBG_LIB_DMA, dip,
369 		    "hvio_iommu_getmap failed, ret 0x%lx\n", ret);
370 
371 		return ((ret == H_ENOMAP) ? DDI_DMA_NOMAPPING:DDI_FAILURE);
372 	}
373 
374 	DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getmap: attr 0x%x r_addr 0x%llx\n",
375 	    *attributes_p, *r_addr_p);
376 
377 	return (DDI_SUCCESS);
378 }
379 
380 
381 /*
382  * Checks dma attributes against system bypass ranges
383  * A sun4v device must be capable of generating the entire 64-bit
384  * address in order to perform bypass DMA.
385  */
386 /*ARGSUSED*/
387 int
388 px_lib_dma_bypass_rngchk(ddi_dma_attr_t *attrp, uint64_t *lo_p, uint64_t *hi_p)
389 {
390 	if ((attrp->dma_attr_addr_lo != 0ull) ||
391 	    (attrp->dma_attr_addr_hi != UINT64_MAX)) {
392 
393 		return (DDI_DMA_BADATTR);
394 	}
395 
396 	*lo_p = 0ull;
397 	*hi_p = UINT64_MAX;
398 
399 	return (DDI_SUCCESS);
400 }
401 
402 
403 /*ARGSUSED*/
404 int
405 px_lib_iommu_getbypass(dev_info_t *dip, r_addr_t ra,
406     io_attributes_t io_attributes, io_addr_t *io_addr_p)
407 {
408 	uint64_t	ret;
409 
410 	DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getbypass: dip 0x%p ra 0x%llx "
411 	    "attr 0x%x\n", dip, ra, io_attributes);
412 
413 	if ((ret = hvio_iommu_getbypass(DIP_TO_HANDLE(dip), ra,
414 	    io_attributes, io_addr_p)) != H_EOK) {
415 		DBG(DBG_LIB_DMA, dip,
416 		    "hvio_iommu_getbypass failed, ret 0x%lx\n", ret);
417 		return (ret == H_ENOTSUPPORTED ? DDI_ENOTSUP : DDI_FAILURE);
418 	}
419 
420 	DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getbypass: io_addr 0x%llx\n",
421 	    *io_addr_p);
422 
423 	return (DDI_SUCCESS);
424 }
425 
426 /*ARGSUSED*/
427 int
428 px_lib_dma_sync(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle,
429 	off_t off, size_t len, uint_t cache_flags)
430 {
431 	ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
432 	uint64_t sync_dir;
433 	px_dvma_addr_t dvma_addr, pg_off;
434 	size_t num_sync;
435 	uint64_t status = H_EOK;
436 
437 	DBG(DBG_LIB_DMA, dip, "px_lib_dma_sync: dip 0x%p rdip 0x%p "
438 	    "handle 0x%llx off 0x%x len 0x%x flags 0x%x\n",
439 	    dip, rdip, handle, off, len, cache_flags);
440 
441 	if (!(mp->dmai_flags & PX_DMAI_FLAGS_INUSE)) {
442 		cmn_err(CE_WARN, "%s%d: Unbound dma handle %p.",
443 		    ddi_driver_name(rdip), ddi_get_instance(rdip), (void *)mp);
444 		return (DDI_FAILURE);
445 	}
446 
447 	if (mp->dmai_flags & PX_DMAI_FLAGS_NOSYNC)
448 		return (DDI_SUCCESS);
449 
450 	if (!len)
451 		len = mp->dmai_size;
452 
453 	pg_off = mp->dmai_offset;			/* start min */
454 	dvma_addr = MAX(off, pg_off);			/* lo */
455 	pg_off += mp->dmai_size;			/* end max */
456 	pg_off = MIN(off + len, pg_off);		/* hi */
457 	if (dvma_addr >= pg_off) {			/* lo >= hi ? */
458 		cmn_err(CE_WARN, "%s%d: %lx + %lx out of window [%lx,%lx]",
459 		    ddi_driver_name(rdip), ddi_get_instance(rdip),
460 		    off, len, mp->dmai_offset,
461 		    mp->dmai_offset + mp->dmai_size);
462 		return (DDI_FAILURE);
463 	}
464 
465 	len = pg_off - dvma_addr;			/* sz = hi - lo */
466 	dvma_addr += mp->dmai_mapping;			/* start addr */
467 
468 	if (mp->dmai_rflags & DDI_DMA_READ)
469 		sync_dir = HVIO_DMA_SYNC_DIR_FROM_DEV;
470 	else
471 		sync_dir = HVIO_DMA_SYNC_DIR_TO_DEV;
472 
473 	for (; ((len > 0) && (status == H_EOK)); len -= num_sync) {
474 		status = hvio_dma_sync(DIP_TO_HANDLE(dip), dvma_addr, len,
475 		    sync_dir, &num_sync);
476 		dvma_addr += num_sync;
477 	}
478 
479 	return ((status == H_EOK) ? DDI_SUCCESS : DDI_FAILURE);
480 }
481 
482 
483 /*
484  * MSIQ Functions:
485  */
486 
487 /*ARGSUSED*/
488 int
489 px_lib_msiq_init(dev_info_t *dip)
490 {
491 	px_t		*px_p = DIP_TO_STATE(dip);
492 	px_msiq_state_t	*msiq_state_p = &px_p->px_ib_p->ib_msiq_state;
493 	uint64_t	*msiq_addr, ra;
494 	size_t		msiq_size;
495 	uint_t		rec_cnt;
496 	int		i, err = DDI_SUCCESS;
497 	uint64_t	ret;
498 
499 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_init: dip 0x%p\n", dip);
500 
501 	msiq_addr = (uint64_t *)(((uint64_t)msiq_state_p->msiq_buf_p +
502 	    (MMU_PAGE_SIZE - 1)) >> MMU_PAGE_SHIFT << MMU_PAGE_SHIFT);
503 
504 	msiq_size = msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t);
505 
506 	for (i = 0; i < msiq_state_p->msiq_cnt; i++) {
507 		ra = (r_addr_t)va_to_pa((caddr_t)msiq_addr + (i * msiq_size));
508 
509 		if ((ret = hvio_msiq_conf(DIP_TO_HANDLE(dip),
510 		    (i + msiq_state_p->msiq_1st_msiq_id),
511 		    ra, msiq_state_p->msiq_rec_cnt)) != H_EOK) {
512 			DBG(DBG_LIB_MSIQ, dip,
513 			    "hvio_msiq_conf failed, ret 0x%lx\n", ret);
514 			err = DDI_FAILURE;
515 			break;
516 		}
517 
518 		if ((err = px_lib_msiq_info(dip,
519 		    (i + msiq_state_p->msiq_1st_msiq_id),
520 		    &ra, &rec_cnt)) != DDI_SUCCESS) {
521 			DBG(DBG_LIB_MSIQ, dip,
522 			    "px_lib_msiq_info failed, ret 0x%x\n", err);
523 			err = DDI_FAILURE;
524 			break;
525 		}
526 
527 		DBG(DBG_LIB_MSIQ, dip,
528 		    "px_lib_msiq_init: ra 0x%p rec_cnt 0x%x\n", ra, rec_cnt);
529 	}
530 
531 	return (err);
532 }
533 
534 /*ARGSUSED*/
535 int
536 px_lib_msiq_fini(dev_info_t *dip)
537 {
538 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_fini: dip 0x%p\n", dip);
539 
540 	return (DDI_SUCCESS);
541 }
542 
543 /*ARGSUSED*/
544 int
545 px_lib_msiq_info(dev_info_t *dip, msiqid_t msiq_id, r_addr_t *ra_p,
546     uint_t *msiq_rec_cnt_p)
547 {
548 	uint64_t	ret;
549 
550 	DBG(DBG_LIB_MSIQ, dip, "px_msiq_info: dip 0x%p msiq_id 0x%x\n",
551 	    dip, msiq_id);
552 
553 	if ((ret = hvio_msiq_info(DIP_TO_HANDLE(dip),
554 	    msiq_id, ra_p, msiq_rec_cnt_p)) != H_EOK) {
555 		DBG(DBG_LIB_MSIQ, dip,
556 		    "hvio_msiq_info failed, ret 0x%lx\n", ret);
557 		return (DDI_FAILURE);
558 	}
559 
560 	DBG(DBG_LIB_MSIQ, dip, "px_msiq_info: ra_p 0x%p msiq_rec_cnt 0x%x\n",
561 	    ra_p, *msiq_rec_cnt_p);
562 
563 	return (DDI_SUCCESS);
564 }
565 
566 /*ARGSUSED*/
567 int
568 px_lib_msiq_getvalid(dev_info_t *dip, msiqid_t msiq_id,
569     pci_msiq_valid_state_t *msiq_valid_state)
570 {
571 	uint64_t	ret;
572 
573 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getvalid: dip 0x%p msiq_id 0x%x\n",
574 	    dip, msiq_id);
575 
576 	if ((ret = hvio_msiq_getvalid(DIP_TO_HANDLE(dip),
577 	    msiq_id, msiq_valid_state)) != H_EOK) {
578 		DBG(DBG_LIB_MSIQ, dip,
579 		    "hvio_msiq_getvalid failed, ret 0x%lx\n", ret);
580 		return (DDI_FAILURE);
581 	}
582 
583 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getvalid: msiq_valid_state 0x%x\n",
584 	    *msiq_valid_state);
585 
586 	return (DDI_SUCCESS);
587 }
588 
589 /*ARGSUSED*/
590 int
591 px_lib_msiq_setvalid(dev_info_t *dip, msiqid_t msiq_id,
592     pci_msiq_valid_state_t msiq_valid_state)
593 {
594 	uint64_t	ret;
595 
596 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_setvalid: dip 0x%p msiq_id 0x%x "
597 	    "msiq_valid_state 0x%x\n", dip, msiq_id, msiq_valid_state);
598 
599 	if ((ret = hvio_msiq_setvalid(DIP_TO_HANDLE(dip),
600 	    msiq_id, msiq_valid_state)) != H_EOK) {
601 		DBG(DBG_LIB_MSIQ, dip,
602 		    "hvio_msiq_setvalid failed, ret 0x%lx\n", ret);
603 		return (DDI_FAILURE);
604 	}
605 
606 	return (DDI_SUCCESS);
607 }
608 
609 /*ARGSUSED*/
610 int
611 px_lib_msiq_getstate(dev_info_t *dip, msiqid_t msiq_id,
612     pci_msiq_state_t *msiq_state)
613 {
614 	uint64_t	ret;
615 
616 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getstate: dip 0x%p msiq_id 0x%x\n",
617 	    dip, msiq_id);
618 
619 	if ((ret = hvio_msiq_getstate(DIP_TO_HANDLE(dip),
620 	    msiq_id, msiq_state)) != H_EOK) {
621 		DBG(DBG_LIB_MSIQ, dip,
622 		    "hvio_msiq_getstate failed, ret 0x%lx\n", ret);
623 		return (DDI_FAILURE);
624 	}
625 
626 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getstate: msiq_state 0x%x\n",
627 	    *msiq_state);
628 
629 	return (DDI_SUCCESS);
630 }
631 
632 /*ARGSUSED*/
633 int
634 px_lib_msiq_setstate(dev_info_t *dip, msiqid_t msiq_id,
635     pci_msiq_state_t msiq_state)
636 {
637 	uint64_t	ret;
638 
639 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_setstate: dip 0x%p msiq_id 0x%x "
640 	    "msiq_state 0x%x\n", dip, msiq_id, msiq_state);
641 
642 	if ((ret = hvio_msiq_setstate(DIP_TO_HANDLE(dip),
643 	    msiq_id, msiq_state)) != H_EOK) {
644 		DBG(DBG_LIB_MSIQ, dip,
645 		    "hvio_msiq_setstate failed, ret 0x%lx\n", ret);
646 		return (DDI_FAILURE);
647 	}
648 
649 	return (DDI_SUCCESS);
650 }
651 
652 /*ARGSUSED*/
653 int
654 px_lib_msiq_gethead(dev_info_t *dip, msiqid_t msiq_id,
655     msiqhead_t *msiq_head_p)
656 {
657 	uint64_t	ret;
658 
659 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gethead: dip 0x%p msiq_id 0x%x\n",
660 	    dip, msiq_id);
661 
662 	if ((ret = hvio_msiq_gethead(DIP_TO_HANDLE(dip),
663 	    msiq_id, msiq_head_p)) != H_EOK) {
664 		DBG(DBG_LIB_MSIQ, dip,
665 		    "hvio_msiq_gethead failed, ret 0x%lx\n", ret);
666 		return (DDI_FAILURE);
667 	}
668 
669 	*msiq_head_p =  (*msiq_head_p / sizeof (msiq_rec_t));
670 
671 	DBG(DBG_LIB_MSIQ, dip, "px_msiq_gethead: msiq_head 0x%x\n",
672 	    *msiq_head_p);
673 
674 	return (DDI_SUCCESS);
675 }
676 
677 /*ARGSUSED*/
678 int
679 px_lib_msiq_sethead(dev_info_t *dip, msiqid_t msiq_id,
680     msiqhead_t msiq_head)
681 {
682 	uint64_t	ret;
683 
684 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_sethead: dip 0x%p msiq_id 0x%x "
685 	    "msiq_head 0x%x\n", dip, msiq_id, msiq_head);
686 
687 	if ((ret = hvio_msiq_sethead(DIP_TO_HANDLE(dip),
688 	    msiq_id, msiq_head * sizeof (msiq_rec_t))) != H_EOK) {
689 		DBG(DBG_LIB_MSIQ, dip,
690 		    "hvio_msiq_sethead failed, ret 0x%lx\n", ret);
691 		return (DDI_FAILURE);
692 	}
693 
694 	return (DDI_SUCCESS);
695 }
696 
697 /*ARGSUSED*/
698 int
699 px_lib_msiq_gettail(dev_info_t *dip, msiqid_t msiq_id,
700     msiqtail_t *msiq_tail_p)
701 {
702 	uint64_t	ret;
703 
704 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gettail: dip 0x%p msiq_id 0x%x\n",
705 	    dip, msiq_id);
706 
707 	if ((ret = hvio_msiq_gettail(DIP_TO_HANDLE(dip),
708 	    msiq_id, msiq_tail_p)) != H_EOK) {
709 		DBG(DBG_LIB_MSIQ, dip,
710 		    "hvio_msiq_gettail failed, ret 0x%lx\n", ret);
711 		return (DDI_FAILURE);
712 	}
713 
714 	*msiq_tail_p =  (*msiq_tail_p / sizeof (msiq_rec_t));
715 	DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gettail: msiq_tail 0x%x\n",
716 	    *msiq_tail_p);
717 
718 	return (DDI_SUCCESS);
719 }
720 
721 /*ARGSUSED*/
722 void
723 px_lib_get_msiq_rec(dev_info_t *dip, px_msiq_t *msiq_p, msiq_rec_t *msiq_rec_p)
724 {
725 	msiq_rec_t	*curr_msiq_rec_p = (msiq_rec_t *)msiq_p->msiq_curr;
726 
727 	DBG(DBG_LIB_MSIQ, dip, "px_lib_get_msiq_rec: dip 0x%p\n", dip);
728 
729 	if (!curr_msiq_rec_p->msiq_rec_type)
730 		return;
731 
732 	*msiq_rec_p = *curr_msiq_rec_p;
733 
734 	/* Zero out msiq_rec_type field */
735 	curr_msiq_rec_p->msiq_rec_type  = 0;
736 }
737 
738 /*
739  * MSI Functions:
740  */
741 
742 /*ARGSUSED*/
743 int
744 px_lib_msi_init(dev_info_t *dip)
745 {
746 	DBG(DBG_LIB_MSI, dip, "px_lib_msi_init: dip 0x%p\n", dip);
747 
748 	/* Noop */
749 	return (DDI_SUCCESS);
750 }
751 
752 /*ARGSUSED*/
753 int
754 px_lib_msi_getmsiq(dev_info_t *dip, msinum_t msi_num,
755     msiqid_t *msiq_id)
756 {
757 	uint64_t	ret;
758 
759 	DBG(DBG_LIB_MSI, dip, "px_lib_msi_getmsiq: dip 0x%p msi_num 0x%x\n",
760 	    dip, msi_num);
761 
762 	if ((ret = hvio_msi_getmsiq(DIP_TO_HANDLE(dip),
763 	    msi_num, msiq_id)) != H_EOK) {
764 		DBG(DBG_LIB_MSI, dip,
765 		    "hvio_msi_getmsiq failed, ret 0x%lx\n", ret);
766 		return (DDI_FAILURE);
767 	}
768 
769 	DBG(DBG_LIB_MSI, dip, "px_lib_msi_getmsiq: msiq_id 0x%x\n",
770 	    *msiq_id);
771 
772 	return (DDI_SUCCESS);
773 }
774 
775 /*ARGSUSED*/
776 int
777 px_lib_msi_setmsiq(dev_info_t *dip, msinum_t msi_num,
778     msiqid_t msiq_id, msi_type_t msitype)
779 {
780 	uint64_t	ret;
781 
782 	DBG(DBG_LIB_MSI, dip, "px_lib_msi_setmsiq: dip 0x%p msi_num 0x%x "
783 	    "msq_id 0x%x\n", dip, msi_num, msiq_id);
784 
785 	if ((ret = hvio_msi_setmsiq(DIP_TO_HANDLE(dip),
786 	    msi_num, msiq_id, msitype)) != H_EOK) {
787 		DBG(DBG_LIB_MSI, dip,
788 		    "hvio_msi_setmsiq failed, ret 0x%lx\n", ret);
789 		return (DDI_FAILURE);
790 	}
791 
792 	return (DDI_SUCCESS);
793 }
794 
795 /*ARGSUSED*/
796 int
797 px_lib_msi_getvalid(dev_info_t *dip, msinum_t msi_num,
798     pci_msi_valid_state_t *msi_valid_state)
799 {
800 	uint64_t	ret;
801 
802 	DBG(DBG_LIB_MSI, dip, "px_lib_msi_getvalid: dip 0x%p msi_num 0x%x\n",
803 	    dip, msi_num);
804 
805 	if ((ret = hvio_msi_getvalid(DIP_TO_HANDLE(dip),
806 	    msi_num, msi_valid_state)) != H_EOK) {
807 		DBG(DBG_LIB_MSI, dip,
808 		    "hvio_msi_getvalid failed, ret 0x%lx\n", ret);
809 		return (DDI_FAILURE);
810 	}
811 
812 	DBG(DBG_LIB_MSI, dip, "px_lib_msi_getvalid: msiq_id 0x%x\n",
813 	    *msi_valid_state);
814 
815 	return (DDI_SUCCESS);
816 }
817 
818 /*ARGSUSED*/
819 int
820 px_lib_msi_setvalid(dev_info_t *dip, msinum_t msi_num,
821     pci_msi_valid_state_t msi_valid_state)
822 {
823 	uint64_t	ret;
824 
825 	DBG(DBG_LIB_MSI, dip, "px_lib_msi_setvalid: dip 0x%p msi_num 0x%x "
826 	    "msi_valid_state 0x%x\n", dip, msi_num, msi_valid_state);
827 
828 	if ((ret = hvio_msi_setvalid(DIP_TO_HANDLE(dip),
829 	    msi_num, msi_valid_state)) != H_EOK) {
830 		DBG(DBG_LIB_MSI, dip,
831 		    "hvio_msi_setvalid failed, ret 0x%lx\n", ret);
832 		return (DDI_FAILURE);
833 	}
834 
835 	return (DDI_SUCCESS);
836 }
837 
838 /*ARGSUSED*/
839 int
840 px_lib_msi_getstate(dev_info_t *dip, msinum_t msi_num,
841     pci_msi_state_t *msi_state)
842 {
843 	uint64_t	ret;
844 
845 	DBG(DBG_LIB_MSI, dip, "px_lib_msi_getstate: dip 0x%p msi_num 0x%x\n",
846 	    dip, msi_num);
847 
848 	if ((ret = hvio_msi_getstate(DIP_TO_HANDLE(dip),
849 	    msi_num, msi_state)) != H_EOK) {
850 		DBG(DBG_LIB_MSI, dip,
851 		    "hvio_msi_getstate failed, ret 0x%lx\n", ret);
852 		return (DDI_FAILURE);
853 	}
854 
855 	DBG(DBG_LIB_MSI, dip, "px_lib_msi_getstate: msi_state 0x%x\n",
856 	    *msi_state);
857 
858 	return (DDI_SUCCESS);
859 }
860 
861 /*ARGSUSED*/
862 int
863 px_lib_msi_setstate(dev_info_t *dip, msinum_t msi_num,
864     pci_msi_state_t msi_state)
865 {
866 	uint64_t	ret;
867 
868 	DBG(DBG_LIB_MSI, dip, "px_lib_msi_setstate: dip 0x%p msi_num 0x%x "
869 	    "msi_state 0x%x\n", dip, msi_num, msi_state);
870 
871 	if ((ret = hvio_msi_setstate(DIP_TO_HANDLE(dip),
872 	    msi_num, msi_state)) != H_EOK) {
873 		DBG(DBG_LIB_MSI, dip,
874 		    "hvio_msi_setstate failed, ret 0x%lx\n", ret);
875 		return (DDI_FAILURE);
876 	}
877 
878 	return (DDI_SUCCESS);
879 }
880 
881 /*
882  * MSG Functions:
883  */
884 
885 /*ARGSUSED*/
886 int
887 px_lib_msg_getmsiq(dev_info_t *dip, pcie_msg_type_t msg_type,
888     msiqid_t *msiq_id)
889 {
890 	uint64_t	ret;
891 
892 	DBG(DBG_LIB_MSG, dip, "px_lib_msg_getmsiq: dip 0x%p msg_type 0x%x\n",
893 	    dip, msg_type);
894 
895 	if ((ret = hvio_msg_getmsiq(DIP_TO_HANDLE(dip),
896 	    msg_type, msiq_id)) != H_EOK) {
897 		DBG(DBG_LIB_MSG, dip,
898 		    "hvio_msg_getmsiq failed, ret 0x%lx\n", ret);
899 		return (DDI_FAILURE);
900 	}
901 
902 	DBG(DBG_LIB_MSI, dip, "px_lib_msg_getmsiq: msiq_id 0x%x\n",
903 	    *msiq_id);
904 
905 	return (DDI_SUCCESS);
906 }
907 
908 /*ARGSUSED*/
909 int
910 px_lib_msg_setmsiq(dev_info_t *dip, pcie_msg_type_t msg_type,
911     msiqid_t msiq_id)
912 {
913 	uint64_t	ret;
914 
915 	DBG(DBG_LIB_MSG, dip, "px_lib_msg_setmsiq: dip 0x%p msg_type 0x%x "
916 	    "msq_id 0x%x\n", dip, msg_type, msiq_id);
917 
918 	if ((ret = hvio_msg_setmsiq(DIP_TO_HANDLE(dip),
919 	    msg_type, msiq_id)) != H_EOK) {
920 		DBG(DBG_LIB_MSG, dip,
921 		    "hvio_msg_setmsiq failed, ret 0x%lx\n", ret);
922 		return (DDI_FAILURE);
923 	}
924 
925 	return (DDI_SUCCESS);
926 }
927 
928 /*ARGSUSED*/
929 int
930 px_lib_msg_getvalid(dev_info_t *dip, pcie_msg_type_t msg_type,
931     pcie_msg_valid_state_t *msg_valid_state)
932 {
933 	uint64_t	ret;
934 
935 	DBG(DBG_LIB_MSG, dip, "px_lib_msg_getvalid: dip 0x%p msg_type 0x%x\n",
936 	    dip, msg_type);
937 
938 	if ((ret = hvio_msg_getvalid(DIP_TO_HANDLE(dip), msg_type,
939 	    msg_valid_state)) != H_EOK) {
940 		DBG(DBG_LIB_MSG, dip,
941 		    "hvio_msg_getvalid failed, ret 0x%lx\n", ret);
942 		return (DDI_FAILURE);
943 	}
944 
945 	DBG(DBG_LIB_MSI, dip, "px_lib_msg_getvalid: msg_valid_state 0x%x\n",
946 	    *msg_valid_state);
947 
948 	return (DDI_SUCCESS);
949 }
950 
951 /*ARGSUSED*/
952 int
953 px_lib_msg_setvalid(dev_info_t *dip, pcie_msg_type_t msg_type,
954     pcie_msg_valid_state_t msg_valid_state)
955 {
956 	uint64_t	ret;
957 
958 	DBG(DBG_LIB_MSG, dip, "px_lib_msg_setvalid: dip 0x%p msg_type 0x%x "
959 	    "msg_valid_state 0x%x\n", dip, msg_type, msg_valid_state);
960 
961 	if ((ret = hvio_msg_setvalid(DIP_TO_HANDLE(dip), msg_type,
962 	    msg_valid_state)) != H_EOK) {
963 		DBG(DBG_LIB_MSG, dip,
964 		    "hvio_msg_setvalid failed, ret 0x%lx\n", ret);
965 		return (DDI_FAILURE);
966 	}
967 
968 	return (DDI_SUCCESS);
969 }
970 
971 /*
972  * Suspend/Resume Functions:
973  * Currently unsupported by hypervisor and all functions are noops.
974  */
975 /*ARGSUSED*/
976 int
977 px_lib_suspend(dev_info_t *dip)
978 {
979 	DBG(DBG_ATTACH, dip, "px_lib_suspend: Not supported\n");
980 
981 	/* Not supported */
982 	return (DDI_FAILURE);
983 }
984 
985 /*ARGSUSED*/
986 void
987 px_lib_resume(dev_info_t *dip)
988 {
989 	DBG(DBG_ATTACH, dip, "px_lib_resume: Not supported\n");
990 
991 	/* Noop */
992 }
993 
994 /*
995  * Misc Functions:
996  * Currently unsupported by hypervisor and all functions are noops.
997  */
998 /*ARGSUSED*/
999 uint64_t
1000 px_lib_get_cb(dev_info_t *dip)
1001 {
1002 	return (DDI_SUCCESS);
1003 }
1004 
1005 /*ARGSUSED*/
1006 void
1007 px_lib_set_cb(dev_info_t *dip, uint64_t val)
1008 {
1009 	/* Noop */
1010 }
1011 
1012 /*ARGSUSED*/
1013 static int
1014 px_lib_config_get(dev_info_t *dip, pci_device_t bdf, pci_config_offset_t off,
1015     uint8_t size, pci_cfg_data_t *data_p)
1016 {
1017 	uint64_t	ret;
1018 
1019 	DBG(DBG_LIB_CFG, dip, "px_lib_config_get: dip 0x%p, bdf 0x%llx "
1020 	    "off 0x%x size 0x%x\n", dip, bdf, off, size);
1021 
1022 	if ((ret = hvio_config_get(DIP_TO_HANDLE(dip), bdf, off,
1023 	    size, data_p)) != H_EOK) {
1024 		DBG(DBG_LIB_CFG, dip,
1025 		    "hvio_config_get failed, ret 0x%lx\n", ret);
1026 		return (DDI_FAILURE);
1027 	}
1028 	DBG(DBG_LIB_CFG, dip, "px_config_get: data 0x%x\n", data_p->dw);
1029 
1030 	return (DDI_SUCCESS);
1031 }
1032 
1033 /*ARGSUSED*/
1034 static int
1035 px_lib_config_put(dev_info_t *dip, pci_device_t bdf, pci_config_offset_t off,
1036     uint8_t size, pci_cfg_data_t data)
1037 {
1038 	uint64_t	ret;
1039 
1040 	DBG(DBG_LIB_CFG, dip, "px_lib_config_put: dip 0x%p, bdf 0x%llx "
1041 	    "off 0x%x size 0x%x data 0x%llx\n", dip, bdf, off, size, data.qw);
1042 
1043 	if ((ret = hvio_config_put(DIP_TO_HANDLE(dip), bdf, off,
1044 	    size, data)) != H_EOK) {
1045 		DBG(DBG_LIB_CFG, dip,
1046 		    "hvio_config_put failed, ret 0x%lx\n", ret);
1047 		return (DDI_FAILURE);
1048 	}
1049 
1050 	return (DDI_SUCCESS);
1051 }
1052 
1053 static uint32_t
1054 px_pci_config_get(ddi_acc_impl_t *handle, uint32_t *addr, int size)
1055 {
1056 	px_config_acc_pvt_t	*px_pvt = (px_config_acc_pvt_t *)
1057 					handle->ahi_common.ah_bus_private;
1058 	uint32_t pci_dev_addr = px_pvt->raddr;
1059 	uint32_t vaddr = px_pvt->vaddr;
1060 	uint16_t off = (uint16_t)(uintptr_t)(addr - vaddr) & 0xfff;
1061 	uint32_t rdata = 0;
1062 
1063 	if (px_lib_config_get(px_pvt->dip, pci_dev_addr, off,
1064 				size, (pci_cfg_data_t *)&rdata) != DDI_SUCCESS)
1065 		/* XXX update error kstats */
1066 		return (0xffffffff);
1067 	return (rdata);
1068 }
1069 
1070 static void
1071 px_pci_config_put(ddi_acc_impl_t *handle, uint32_t *addr,
1072 		int size, pci_cfg_data_t wdata)
1073 {
1074 	px_config_acc_pvt_t	*px_pvt = (px_config_acc_pvt_t *)
1075 					handle->ahi_common.ah_bus_private;
1076 	uint32_t pci_dev_addr = px_pvt->raddr;
1077 	uint32_t vaddr = px_pvt->vaddr;
1078 	uint16_t off = (uint16_t)(uintptr_t)(addr - vaddr) & 0xfff;
1079 
1080 	if (px_lib_config_put(px_pvt->dip, pci_dev_addr, off,
1081 				size, wdata) != DDI_SUCCESS) {
1082 		/*EMPTY*/
1083 		/* XXX update error kstats */
1084 	}
1085 }
1086 
1087 static uint8_t
1088 px_pci_config_get8(ddi_acc_impl_t *handle, uint8_t *addr)
1089 {
1090 	return ((uint8_t)px_pci_config_get(handle, (uint32_t *)addr, 1));
1091 }
1092 
1093 static uint16_t
1094 px_pci_config_get16(ddi_acc_impl_t *handle, uint16_t *addr)
1095 {
1096 	return ((uint16_t)px_pci_config_get(handle, (uint32_t *)addr, 2));
1097 }
1098 
1099 static uint32_t
1100 px_pci_config_get32(ddi_acc_impl_t *handle, uint32_t *addr)
1101 {
1102 	return ((uint32_t)px_pci_config_get(handle, (uint32_t *)addr, 4));
1103 }
1104 
1105 static uint64_t
1106 px_pci_config_get64(ddi_acc_impl_t *handle, uint64_t *addr)
1107 {
1108 	uint32_t rdatah, rdatal;
1109 
1110 	rdatal = (uint32_t)px_pci_config_get(handle, (uint32_t *)addr, 4);
1111 	rdatah = (uint32_t)px_pci_config_get(handle,
1112 				(uint32_t *)((char *)addr+4), 4);
1113 	return (((uint64_t)rdatah << 32) | rdatal);
1114 }
1115 
1116 static void
1117 px_pci_config_put8(ddi_acc_impl_t *handle, uint8_t *addr, uint8_t data)
1118 {
1119 	pci_cfg_data_t wdata = { 0 };
1120 
1121 	wdata.qw = (uint8_t)data;
1122 	px_pci_config_put(handle, (uint32_t *)addr, 1, wdata);
1123 }
1124 
1125 static void
1126 px_pci_config_put16(ddi_acc_impl_t *handle, uint16_t *addr, uint16_t data)
1127 {
1128 	pci_cfg_data_t wdata = { 0 };
1129 
1130 	wdata.qw = (uint16_t)data;
1131 	px_pci_config_put(handle, (uint32_t *)addr, 2, wdata);
1132 }
1133 
1134 static void
1135 px_pci_config_put32(ddi_acc_impl_t *handle, uint32_t *addr, uint32_t data)
1136 {
1137 	pci_cfg_data_t wdata = { 0 };
1138 
1139 	wdata.qw = (uint32_t)data;
1140 	px_pci_config_put(handle, (uint32_t *)addr, 4, wdata);
1141 }
1142 
1143 static void
1144 px_pci_config_put64(ddi_acc_impl_t *handle, uint64_t *addr, uint64_t data)
1145 {
1146 	pci_cfg_data_t wdata = { 0 };
1147 
1148 	wdata.qw = (uint32_t)(data & 0xffffffff);
1149 	px_pci_config_put(handle, (uint32_t *)addr, 4, wdata);
1150 	wdata.qw = (uint32_t)((data >> 32) & 0xffffffff);
1151 	px_pci_config_put(handle, (uint32_t *)((char *)addr+4), 4, wdata);
1152 }
1153 
1154 static void
1155 px_pci_config_rep_get8(ddi_acc_impl_t *handle, uint8_t *host_addr,
1156 			uint8_t *dev_addr, size_t repcount, uint_t flags)
1157 {
1158 	if (flags == DDI_DEV_AUTOINCR)
1159 		for (; repcount; repcount--)
1160 			*host_addr++ = px_pci_config_get8(handle, dev_addr++);
1161 	else
1162 		for (; repcount; repcount--)
1163 			*host_addr++ = px_pci_config_get8(handle, dev_addr);
1164 }
1165 
1166 /*
1167  * Function to rep read 16 bit data off the PCI configuration space behind
1168  * the 21554's host interface.
1169  */
1170 static void
1171 px_pci_config_rep_get16(ddi_acc_impl_t *handle, uint16_t *host_addr,
1172 			uint16_t *dev_addr, size_t repcount, uint_t flags)
1173 {
1174 	if (flags == DDI_DEV_AUTOINCR)
1175 		for (; repcount; repcount--)
1176 			*host_addr++ = px_pci_config_get16(handle, dev_addr++);
1177 	else
1178 		for (; repcount; repcount--)
1179 			*host_addr++ = px_pci_config_get16(handle, dev_addr);
1180 }
1181 
1182 /*
1183  * Function to rep read 32 bit data off the PCI configuration space behind
1184  * the 21554's host interface.
1185  */
1186 static void
1187 px_pci_config_rep_get32(ddi_acc_impl_t *handle, uint32_t *host_addr,
1188 			uint32_t *dev_addr, size_t repcount, uint_t flags)
1189 {
1190 	if (flags == DDI_DEV_AUTOINCR)
1191 		for (; repcount; repcount--)
1192 			*host_addr++ = px_pci_config_get32(handle, dev_addr++);
1193 	else
1194 		for (; repcount; repcount--)
1195 			*host_addr++ = px_pci_config_get32(handle, dev_addr);
1196 }
1197 
1198 /*
1199  * Function to rep read 64 bit data off the PCI configuration space behind
1200  * the 21554's host interface.
1201  */
1202 static void
1203 px_pci_config_rep_get64(ddi_acc_impl_t *handle, uint64_t *host_addr,
1204 			uint64_t *dev_addr, size_t repcount, uint_t flags)
1205 {
1206 	if (flags == DDI_DEV_AUTOINCR)
1207 		for (; repcount; repcount--)
1208 			*host_addr++ = px_pci_config_get64(handle, dev_addr++);
1209 	else
1210 		for (; repcount; repcount--)
1211 			*host_addr++ = px_pci_config_get64(handle, dev_addr);
1212 }
1213 
1214 /*
1215  * Function to rep write 8 bit data into the PCI configuration space behind
1216  * the 21554's host interface.
1217  */
1218 static void
1219 px_pci_config_rep_put8(ddi_acc_impl_t *handle, uint8_t *host_addr,
1220 			uint8_t *dev_addr, size_t repcount, uint_t flags)
1221 {
1222 	if (flags == DDI_DEV_AUTOINCR)
1223 		for (; repcount; repcount--)
1224 			px_pci_config_put8(handle, dev_addr++, *host_addr++);
1225 	else
1226 		for (; repcount; repcount--)
1227 			px_pci_config_put8(handle, dev_addr, *host_addr++);
1228 }
1229 
1230 /*
1231  * Function to rep write 16 bit data into the PCI configuration space behind
1232  * the 21554's host interface.
1233  */
1234 static void
1235 px_pci_config_rep_put16(ddi_acc_impl_t *handle, uint16_t *host_addr,
1236 			uint16_t *dev_addr, size_t repcount, uint_t flags)
1237 {
1238 	if (flags == DDI_DEV_AUTOINCR)
1239 		for (; repcount; repcount--)
1240 			px_pci_config_put16(handle, dev_addr++, *host_addr++);
1241 	else
1242 		for (; repcount; repcount--)
1243 			px_pci_config_put16(handle, dev_addr, *host_addr++);
1244 }
1245 
1246 /*
1247  * Function to rep write 32 bit data into the PCI configuration space behind
1248  * the 21554's host interface.
1249  */
1250 static void
1251 px_pci_config_rep_put32(ddi_acc_impl_t *handle, uint32_t *host_addr,
1252 			uint32_t *dev_addr, size_t repcount, uint_t flags)
1253 {
1254 	if (flags == DDI_DEV_AUTOINCR)
1255 		for (; repcount; repcount--)
1256 			px_pci_config_put32(handle, dev_addr++, *host_addr++);
1257 	else
1258 		for (; repcount; repcount--)
1259 			px_pci_config_put32(handle, dev_addr, *host_addr++);
1260 }
1261 
1262 /*
1263  * Function to rep write 64 bit data into the PCI configuration space behind
1264  * the 21554's host interface.
1265  */
1266 static void
1267 px_pci_config_rep_put64(ddi_acc_impl_t *handle, uint64_t *host_addr,
1268 			uint64_t *dev_addr, size_t repcount, uint_t flags)
1269 {
1270 	if (flags == DDI_DEV_AUTOINCR)
1271 		for (; repcount; repcount--)
1272 			px_pci_config_put64(handle, dev_addr++, *host_addr++);
1273 	else
1274 		for (; repcount; repcount--)
1275 			px_pci_config_put64(handle, dev_addr, *host_addr++);
1276 }
1277 
1278 /*
1279  * Provide a private access handle to route config access calls to Hypervisor.
1280  * Beware: Do all error checking for config space accesses before calling
1281  * this function. ie. do error checking from the calling function.
1282  * Due to a lack of meaningful error code in DDI, the gauranteed return of
1283  * DDI_SUCCESS from here makes the code organization readable/easier from
1284  * the generic code.
1285  */
1286 /*ARGSUSED*/
1287 int
1288 px_lib_map_vconfig(dev_info_t *dip,
1289 	ddi_map_req_t *mp, pci_config_offset_t off,
1290 	pci_regspec_t *rp, caddr_t *addrp)
1291 {
1292 	ddi_acc_hdl_t *hp;
1293 	ddi_acc_impl_t *ap;
1294 	uchar_t busnum;	/* bus number */
1295 	uchar_t devnum;	/* device number */
1296 	uchar_t funcnum; /* function number */
1297 	px_config_acc_pvt_t *px_pvt;
1298 
1299 	hp = (ddi_acc_hdl_t *)mp->map_handlep;
1300 	ap = (ddi_acc_impl_t *)hp->ah_platform_private;
1301 
1302 	/* Check for mapping teardown operation */
1303 	if ((mp->map_op == DDI_MO_UNMAP) ||
1304 			(mp->map_op == DDI_MO_UNLOCK)) {
1305 		/* free up memory allocated for the private access handle. */
1306 		px_pvt = (px_config_acc_pvt_t *)hp->ah_bus_private;
1307 		kmem_free((void *)px_pvt, sizeof (px_config_acc_pvt_t));
1308 
1309 		/* unmap operation of PCI IO/config space. */
1310 		return (DDI_SUCCESS);
1311 	}
1312 
1313 	ap->ahi_get8 = px_pci_config_get8;
1314 	ap->ahi_get16 = px_pci_config_get16;
1315 	ap->ahi_get32 = px_pci_config_get32;
1316 	ap->ahi_get64 = px_pci_config_get64;
1317 	ap->ahi_put8 = px_pci_config_put8;
1318 	ap->ahi_put16 = px_pci_config_put16;
1319 	ap->ahi_put32 = px_pci_config_put32;
1320 	ap->ahi_put64 = px_pci_config_put64;
1321 	ap->ahi_rep_get8 = px_pci_config_rep_get8;
1322 	ap->ahi_rep_get16 = px_pci_config_rep_get16;
1323 	ap->ahi_rep_get32 = px_pci_config_rep_get32;
1324 	ap->ahi_rep_get64 = px_pci_config_rep_get64;
1325 	ap->ahi_rep_put8 = px_pci_config_rep_put8;
1326 	ap->ahi_rep_put16 = px_pci_config_rep_put16;
1327 	ap->ahi_rep_put32 = px_pci_config_rep_put32;
1328 	ap->ahi_rep_put64 = px_pci_config_rep_put64;
1329 
1330 	/* Initialize to default check/notify functions */
1331 	ap->ahi_fault = 0;
1332 	ap->ahi_fault_check = i_ddi_acc_fault_check;
1333 	ap->ahi_fault_notify = i_ddi_acc_fault_notify;
1334 
1335 	/* allocate memory for our private handle */
1336 	px_pvt = (px_config_acc_pvt_t *)
1337 			kmem_zalloc(sizeof (px_config_acc_pvt_t), KM_SLEEP);
1338 	hp->ah_bus_private = (void *)px_pvt;
1339 
1340 	busnum = PCI_REG_BUS_G(rp->pci_phys_hi);
1341 	devnum = PCI_REG_DEV_G(rp->pci_phys_hi);
1342 	funcnum = PCI_REG_FUNC_G(rp->pci_phys_hi);
1343 
1344 	/* set up private data for use during IO routines */
1345 
1346 	/* addr needed by the HV APIs */
1347 	px_pvt->raddr = busnum << 16 | devnum << 11 | funcnum << 8;
1348 	/*
1349 	 * Address that specifies the actual offset into the 256MB
1350 	 * memory mapped configuration space, 4K per device.
1351 	 * First 12bits form the offset into 4K config space.
1352 	 * This address is only used during the IO routines to calculate
1353 	 * the offset at which the transaction must be performed.
1354 	 * Drivers bypassing DDI functions to access PCI config space will
1355 	 * panic the system since the following is a bogus virtual address.
1356 	 */
1357 	px_pvt->vaddr = busnum << 20 | devnum << 15 | funcnum << 12 | off;
1358 	px_pvt->dip = dip;
1359 
1360 	DBG(DBG_LIB_CFG, dip, "px_config_setup: raddr 0x%x, vaddr 0x%x\n",
1361 				px_pvt->raddr, px_pvt->vaddr);
1362 	*addrp = (caddr_t)(uintptr_t)px_pvt->vaddr;
1363 	return (DDI_SUCCESS);
1364 }
1365 
1366 /*ARGSUSED*/
1367 void
1368 px_lib_map_attr_check(ddi_map_req_t *mp)
1369 {
1370 }
1371 
1372 /*
1373  * px_lib_log_safeacc_err:
1374  * Imitate a cpu/mem trap call when a peek/poke fails.
1375  * This will initiate something similar to px_fm_callback.
1376  */
1377 static void
1378 px_lib_log_safeacc_err(px_t *px_p, ddi_acc_handle_t handle, int fme_flag)
1379 {
1380 	ddi_acc_impl_t *hp = (ddi_acc_impl_t *)handle;
1381 	px_cb_t	*cb_p = px_p->px_cb_p;
1382 	ddi_fm_error_t derr;
1383 
1384 	derr.fme_status = DDI_FM_NONFATAL;
1385 	derr.fme_version = DDI_FME_VERSION;
1386 	derr.fme_flag = fme_flag;
1387 	derr.fme_ena = fm_ena_generate(0, FM_ENA_FMT1);
1388 	derr.fme_acc_handle = handle;
1389 	if (hp)
1390 		hp->ahi_err->err_expected = DDI_FM_ERR_EXPECTED;
1391 
1392 	mutex_enter(&cb_p->xbc_fm_mutex);
1393 
1394 	(void) ndi_fm_handler_dispatch(px_p->px_dip, NULL, &derr);
1395 
1396 	mutex_exit(&cb_p->xbc_fm_mutex);
1397 }
1398 
1399 
1400 #ifdef  DEBUG
1401 int	px_peekfault_cnt = 0;
1402 int	px_pokefault_cnt = 0;
1403 #endif  /* DEBUG */
1404 
1405 static int
1406 px_lib_bdf_from_dip(dev_info_t *rdip, uint32_t *bdf)
1407 {
1408 	/* Start with an array of 8 reg spaces for now to cover most devices. */
1409 	pci_regspec_t regspec_array[8];
1410 	pci_regspec_t *regspec = regspec_array;
1411 	int buflen = sizeof (regspec_array);
1412 	boolean_t kmalloced = B_FALSE;
1413 	int status;
1414 
1415 	status = ddi_getlongprop_buf(DDI_DEV_T_ANY, rdip,
1416 	    DDI_PROP_DONTPASS, "reg", (caddr_t)regspec, &buflen);
1417 
1418 	/* If need more space, fallback to kmem_alloc. */
1419 	if (status == DDI_PROP_BUF_TOO_SMALL) {
1420 		regspec = kmem_alloc(buflen, KM_SLEEP);
1421 
1422 		status = ddi_getlongprop_buf(DDI_DEV_T_ANY, rdip,
1423 		    DDI_PROP_DONTPASS, "reg", (caddr_t)regspec, &buflen);
1424 
1425 		kmalloced = B_TRUE;
1426 	}
1427 
1428 	/* Get phys_hi from first element.  All have same bdf. */
1429 	if (status == DDI_PROP_SUCCESS)
1430 		*bdf = regspec->pci_phys_hi & (PCI_REG_BDFR_M ^ PCI_REG_REG_M);
1431 
1432 	if (kmalloced)
1433 		kmem_free(regspec, buflen);
1434 
1435 	return ((status == DDI_PROP_SUCCESS) ? DDI_SUCCESS : DDI_FAILURE);
1436 }
1437 
1438 /*
1439  * Do a safe write to a device.
1440  *
1441  * When this function is given a handle (cautious access), all errors are
1442  * suppressed.
1443  *
1444  * When this function is not given a handle (poke), only Unsupported Request
1445  * and Completer Abort errors are suppressed.
1446  *
1447  * In all cases, all errors are returned in the function return status.
1448  */
1449 
1450 int
1451 px_lib_ctlops_poke(dev_info_t *dip, dev_info_t *rdip,
1452     peekpoke_ctlops_t *in_args)
1453 {
1454 	px_t *px_p = DIP_TO_STATE(dip);
1455 	px_pec_t *pec_p = px_p->px_pec_p;
1456 	ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle;
1457 
1458 	size_t repcount = in_args->repcount;
1459 	size_t size = in_args->size;
1460 	uintptr_t dev_addr = in_args->dev_addr;
1461 	uintptr_t host_addr = in_args->host_addr;
1462 
1463 	int err	= DDI_SUCCESS;
1464 	uint64_t hvio_poke_status;
1465 	uint32_t bdf;
1466 	uint32_t wrt_stat;
1467 
1468 	r_addr_t ra;
1469 	uint64_t pokeval;
1470 
1471 	/*
1472 	 * Used only to notify error handling peek/poke is occuring
1473 	 * One scenario is when a fabric err as a result of peek/poke.
1474 	 * However there is no way to guarantee that the fabric error
1475 	 * handler will occur in the window where otd is set.
1476 	 */
1477 	on_trap_data_t otd;
1478 
1479 	if (px_lib_bdf_from_dip(rdip, &bdf) != DDI_SUCCESS) {
1480 		DBG(DBG_LIB_DMA, px_p->px_dip,
1481 		    "poke: px_lib_bdf_from_dip failed\n");
1482 		err = DDI_FAILURE;
1483 		goto done;
1484 	}
1485 
1486 	ra = (r_addr_t)va_to_pa((void *)dev_addr);
1487 	for (; repcount; repcount--) {
1488 
1489 		switch (size) {
1490 		case sizeof (uint8_t):
1491 			pokeval = *(uint8_t *)host_addr;
1492 			break;
1493 		case sizeof (uint16_t):
1494 			pokeval = *(uint16_t *)host_addr;
1495 			break;
1496 		case sizeof (uint32_t):
1497 			pokeval = *(uint32_t *)host_addr;
1498 			break;
1499 		case sizeof (uint64_t):
1500 			pokeval = *(uint64_t *)host_addr;
1501 			break;
1502 		default:
1503 			DBG(DBG_MAP, px_p->px_dip,
1504 			    "poke: invalid size %d passed\n", size);
1505 			err = DDI_FAILURE;
1506 			goto done;
1507 		}
1508 
1509 		/*
1510 		 * Grab pokefault mutex since hypervisor does not guarantee
1511 		 * poke serialization.
1512 		 */
1513 		if (hp) {
1514 			i_ndi_busop_access_enter(hp->ahi_common.ah_dip,
1515 			    (ddi_acc_handle_t)hp);
1516 			pec_p->pec_safeacc_type = DDI_FM_ERR_EXPECTED;
1517 		} else {
1518 			mutex_enter(&pec_p->pec_pokefault_mutex);
1519 			pec_p->pec_safeacc_type = DDI_FM_ERR_POKE;
1520 		}
1521 		pec_p->pec_ontrap_data = &otd;
1522 
1523 		hvio_poke_status = hvio_poke(px_p->px_dev_hdl, ra, size,
1524 			    pokeval, bdf, &wrt_stat);
1525 
1526 		if (otd.ot_trap & OT_DATA_ACCESS)
1527 			err = DDI_FAILURE;
1528 
1529 		if ((hvio_poke_status != H_EOK) || (wrt_stat != H_EOK)) {
1530 			err = DDI_FAILURE;
1531 #ifdef  DEBUG
1532 			px_pokefault_cnt++;
1533 #endif
1534 			/*
1535 			 * For CAUTIOUS and POKE access, notify FMA to
1536 			 * cleanup.  Imitate a cpu/mem trap call like in sun4u.
1537 			 */
1538 			px_lib_log_safeacc_err(px_p, (ddi_acc_handle_t)hp,
1539 			    (hp ? DDI_FM_ERR_EXPECTED :
1540 			    DDI_FM_ERR_POKE));
1541 
1542 			pec_p->pec_ontrap_data = NULL;
1543 			pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED;
1544 			if (hp) {
1545 				i_ndi_busop_access_exit(hp->ahi_common.ah_dip,
1546 				    (ddi_acc_handle_t)hp);
1547 			} else {
1548 				mutex_exit(&pec_p->pec_pokefault_mutex);
1549 			}
1550 			goto done;
1551 		}
1552 
1553 		pec_p->pec_ontrap_data = NULL;
1554 		pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED;
1555 		if (hp) {
1556 			i_ndi_busop_access_exit(hp->ahi_common.ah_dip,
1557 			    (ddi_acc_handle_t)hp);
1558 		} else {
1559 			mutex_exit(&pec_p->pec_pokefault_mutex);
1560 		}
1561 
1562 		host_addr += size;
1563 
1564 		if (in_args->flags == DDI_DEV_AUTOINCR) {
1565 			dev_addr += size;
1566 			ra = (r_addr_t)va_to_pa((void *)dev_addr);
1567 		}
1568 	}
1569 
1570 done:
1571 	return (err);
1572 }
1573 
1574 
1575 /*ARGSUSED*/
1576 int
1577 px_lib_ctlops_peek(dev_info_t *dip, dev_info_t *rdip,
1578     peekpoke_ctlops_t *in_args, void *result)
1579 {
1580 	px_t *px_p = DIP_TO_STATE(dip);
1581 	px_pec_t *pec_p = px_p->px_pec_p;
1582 	ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle;
1583 
1584 	size_t repcount = in_args->repcount;
1585 	uintptr_t dev_addr = in_args->dev_addr;
1586 	uintptr_t host_addr = in_args->host_addr;
1587 
1588 	r_addr_t ra;
1589 	uint32_t read_status;
1590 	uint64_t hvio_peek_status;
1591 	uint64_t peekval;
1592 	int err = DDI_SUCCESS;
1593 
1594 	/*
1595 	 * Used only to notify error handling peek/poke is occuring
1596 	 * One scenario is when a fabric err as a result of peek/poke.
1597 	 * However there is no way to guarantee that the fabric error
1598 	 * handler will occur in the window where otd is set.
1599 	 */
1600 	on_trap_data_t otd;
1601 
1602 	result = (void *)in_args->host_addr;
1603 
1604 	ra = (r_addr_t)va_to_pa((void *)dev_addr);
1605 	for (; repcount; repcount--) {
1606 
1607 		/* Lock pokefault mutex so read doesn't mask a poke fault. */
1608 		if (hp) {
1609 			i_ndi_busop_access_enter(hp->ahi_common.ah_dip,
1610 			    (ddi_acc_handle_t)hp);
1611 			pec_p->pec_safeacc_type = DDI_FM_ERR_EXPECTED;
1612 		} else {
1613 			mutex_enter(&pec_p->pec_pokefault_mutex);
1614 			pec_p->pec_safeacc_type = DDI_FM_ERR_PEEK;
1615 		}
1616 		pec_p->pec_ontrap_data = &otd;
1617 
1618 		hvio_peek_status = hvio_peek(px_p->px_dev_hdl, ra,
1619 		    in_args->size, &read_status, &peekval);
1620 
1621 		if ((hvio_peek_status != H_EOK) || (read_status != H_EOK)) {
1622 			err = DDI_FAILURE;
1623 
1624 			/*
1625 			 * For CAUTIOUS and PEEK access, notify FMA to
1626 			 * cleanup.  Imitate a cpu/mem trap call like in sun4u.
1627 			 */
1628 			px_lib_log_safeacc_err(px_p, (ddi_acc_handle_t)hp,
1629 			    (hp ? DDI_FM_ERR_EXPECTED :
1630 			    DDI_FM_ERR_PEEK));
1631 
1632 			/* Stuff FFs in host addr if peek. */
1633 			if (hp == NULL) {
1634 				int i;
1635 				uint8_t *ff_addr = (uint8_t *)host_addr;
1636 				for (i = 0; i < in_args->size; i++)
1637 					*ff_addr++ = 0xff;
1638 			}
1639 #ifdef  DEBUG
1640 			px_peekfault_cnt++;
1641 #endif
1642 			pec_p->pec_ontrap_data = NULL;
1643 			pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED;
1644 			if (hp) {
1645 				i_ndi_busop_access_exit(hp->ahi_common.ah_dip,
1646 				    (ddi_acc_handle_t)hp);
1647 			} else {
1648 				mutex_exit(&pec_p->pec_pokefault_mutex);
1649 			}
1650 			goto done;
1651 
1652 		}
1653 		pec_p->pec_ontrap_data = NULL;
1654 		pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED;
1655 		if (hp) {
1656 			i_ndi_busop_access_exit(hp->ahi_common.ah_dip,
1657 			    (ddi_acc_handle_t)hp);
1658 		} else {
1659 			mutex_exit(&pec_p->pec_pokefault_mutex);
1660 		}
1661 
1662 		switch (in_args->size) {
1663 		case sizeof (uint8_t):
1664 			*(uint8_t *)host_addr = (uint8_t)peekval;
1665 			break;
1666 		case sizeof (uint16_t):
1667 			*(uint16_t *)host_addr = (uint16_t)peekval;
1668 			break;
1669 		case sizeof (uint32_t):
1670 			*(uint32_t *)host_addr = (uint32_t)peekval;
1671 			break;
1672 		case sizeof (uint64_t):
1673 			*(uint64_t *)host_addr = (uint64_t)peekval;
1674 			break;
1675 		default:
1676 			DBG(DBG_MAP, px_p->px_dip,
1677 			    "peek: invalid size %d passed\n",
1678 			    in_args->size);
1679 			err = DDI_FAILURE;
1680 			goto done;
1681 		}
1682 
1683 		host_addr += in_args->size;
1684 
1685 		if (in_args->flags == DDI_DEV_AUTOINCR) {
1686 			dev_addr += in_args->size;
1687 			ra = (r_addr_t)va_to_pa((void *)dev_addr);
1688 		}
1689 	}
1690 done:
1691 	return (err);
1692 }
1693 
1694 
1695 /* add interrupt vector */
1696 int
1697 px_err_add_intr(px_fault_t *px_fault_p)
1698 {
1699 	int	ret;
1700 	px_t	*px_p = DIP_TO_STATE(px_fault_p->px_fh_dip);
1701 
1702 	DBG(DBG_LIB_INT, px_p->px_dip,
1703 	    "px_err_add_intr: calling add_ivintr");
1704 	ret = add_ivintr(px_fault_p->px_fh_sysino, PX_ERR_PIL,
1705 	    px_fault_p->px_err_func, (caddr_t)px_fault_p,
1706 	    (caddr_t)&px_fault_p->px_intr_payload[0]);
1707 
1708 	if (ret != DDI_SUCCESS) {
1709 		DBG(DBG_LIB_INT, px_p->px_dip,
1710 		"add_ivintr returns %d, faultp: %p", ret, px_fault_p);
1711 
1712 		return (ret);
1713 	}
1714 	DBG(DBG_LIB_INT, px_p->px_dip,
1715 	    "px_err_add_intr: ib_intr_enable ");
1716 
1717 	px_ib_intr_enable(px_p, intr_dist_cpuid(), px_fault_p->px_intr_ino);
1718 
1719 	return (ret);
1720 }
1721 
1722 
1723 /* remove interrupt vector */
1724 void
1725 px_err_rem_intr(px_fault_t *px_fault_p)
1726 {
1727 	px_t	*px_p = DIP_TO_STATE(px_fault_p->px_fh_dip);
1728 
1729 	px_ib_intr_disable(px_p->px_ib_p, px_fault_p->px_intr_ino,
1730 	    IB_INTR_WAIT);
1731 
1732 	rem_ivintr(px_fault_p->px_fh_sysino, NULL);
1733 }
1734 
1735 
1736 #ifdef FMA
1737 void
1738 px_fill_rc_status(px_fault_t *px_fault_p, pciex_rc_error_regs_t *rc_status)
1739 {
1740 	px_pec_err_t	*err_pkt;
1741 
1742 	err_pkt = (px_pec_err_t *)px_fault_p->px_intr_payload;
1743 
1744 	/* initialise all the structure members */
1745 	rc_status->status_valid = 0;
1746 
1747 	if (err_pkt->pec_descr.P) {
1748 		/* PCI Status Register */
1749 		rc_status->pci_err_status = err_pkt->pci_err_status;
1750 		rc_status->status_valid |= PCI_ERR_STATUS_VALID;
1751 	}
1752 
1753 	if (err_pkt->pec_descr.E) {
1754 		/* PCIe Status Register */
1755 		rc_status->pcie_err_status = err_pkt->pcie_err_status;
1756 		rc_status->status_valid |= PCIE_ERR_STATUS_VALID;
1757 	}
1758 
1759 	if (err_pkt->pec_descr.U) {
1760 		rc_status->ue_status = err_pkt->ue_reg_status;
1761 		rc_status->status_valid |= UE_STATUS_VALID;
1762 	}
1763 
1764 	if (err_pkt->pec_descr.H) {
1765 		rc_status->ue_hdr1 = err_pkt->hdr[0];
1766 		rc_status->status_valid |= UE_HDR1_VALID;
1767 	}
1768 
1769 	if (err_pkt->pec_descr.I) {
1770 		rc_status->ue_hdr2 = err_pkt->hdr[1];
1771 		rc_status->status_valid |= UE_HDR2_VALID;
1772 	}
1773 
1774 	/* ue_fst_err_ptr - not available for sun4v?? */
1775 
1776 
1777 	if (err_pkt->pec_descr.S) {
1778 		rc_status->source_id = err_pkt->err_src_reg;
1779 		rc_status->status_valid |= SOURCE_ID_VALID;
1780 	}
1781 
1782 	if (err_pkt->pec_descr.R) {
1783 		rc_status->root_err_status = err_pkt->root_err_status;
1784 		rc_status->status_valid |= CE_STATUS_VALID;
1785 	}
1786 }
1787 #endif
1788 
1789 /*ARGSUSED*/
1790 int
1791 px_lib_pmctl(int cmd, px_t *px_p)
1792 {
1793 	return (DDI_FAILURE);
1794 }
1795 
1796 /*ARGSUSED*/
1797 uint_t
1798 px_lup_softintr(caddr_t arg)
1799 {
1800 	return (DDI_INTR_CLAIMED);
1801 }
1802 
1803 /*ARGSUSED*/
1804 uint_t
1805 px_pmeq_intr(caddr_t arg)
1806 {
1807 	return (DDI_INTR_CLAIMED);
1808 }
1809 
1810 /*
1811  * Unprotected raw reads/writes of fabric device's config space.
1812  * Only used for temporary PCI-E Fabric Error Handling.
1813  */
1814 uint32_t
1815 px_fab_get(px_t *px_p, pcie_req_id_t bdf, uint16_t offset) {
1816 	uint32_t 	data = 0;
1817 
1818 	(void) hvio_config_get(px_p->px_dev_hdl,
1819 	    (bdf << PX_RA_BDF_SHIFT), offset, 4,
1820 	    (pci_cfg_data_t *)&data);
1821 
1822 	return (data);
1823 }
1824 
1825 void
1826 px_fab_set(px_t *px_p, pcie_req_id_t bdf, uint16_t offset,
1827     uint32_t val) {
1828 	pci_cfg_data_t	wdata = { 0 };
1829 
1830 	wdata.qw = (uint32_t)val;
1831 	(void) hvio_config_put(px_p->px_dev_hdl,
1832 	    (bdf << PX_RA_BDF_SHIFT), offset, 4, wdata);
1833 }
1834 
1835 /* Dummy cpr add callback */
1836 /*ARGSUSED*/
1837 void
1838 px_cpr_add_callb(px_t *px_p)
1839 {
1840 }
1841 
1842 /* Dummy cpr rem callback */
1843 /*ARGSUSED*/
1844 void
1845 px_cpr_rem_callb(px_t *px_p)
1846 {
1847 }
1848