10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51540Skini * Common Development and Distribution License (the "License"). 61540Skini * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*12619Sandrew.rutz@sun.com * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _SYS_PX_LIB_H 260Sstevel@tonic-gate #define _SYS_PX_LIB_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate #ifdef __cplusplus 290Sstevel@tonic-gate extern "C" { 300Sstevel@tonic-gate #endif 310Sstevel@tonic-gate 320Sstevel@tonic-gate /* 330Sstevel@tonic-gate * Include all data structures and definitions in this file that are 340Sstevel@tonic-gate * required between the common and hardware specific code. 350Sstevel@tonic-gate */ 360Sstevel@tonic-gate 370Sstevel@tonic-gate #define DIP_TO_HANDLE(dip) ((px_t *)DIP_TO_STATE(dip))->px_dev_hdl 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* 400Sstevel@tonic-gate * The following macros define the mmu page size and related operations. 410Sstevel@tonic-gate */ 420Sstevel@tonic-gate #define MMU_PAGE_SHIFT 13 430Sstevel@tonic-gate #define MMU_PAGE_SIZE (1 << MMU_PAGE_SHIFT) 440Sstevel@tonic-gate #define MMU_PAGE_MASK ~(MMU_PAGE_SIZE - 1) 450Sstevel@tonic-gate #define MMU_PAGE_OFFSET (MMU_PAGE_SIZE - 1) 460Sstevel@tonic-gate #define MMU_PTOB(x) (((uint64_t)(x)) << MMU_PAGE_SHIFT) 470Sstevel@tonic-gate #define MMU_BTOP(x) ((x) >> MMU_PAGE_SHIFT) 480Sstevel@tonic-gate #define MMU_BTOPR(x) MMU_BTOP((x) + MMU_PAGE_OFFSET) 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* MMU map flags */ 511617Sgovinda #define MMU_MAP_PFN 1 521617Sgovinda #define MMU_MAP_BUF 2 530Sstevel@tonic-gate 540Sstevel@tonic-gate typedef struct px px_t; 550Sstevel@tonic-gate typedef struct px_msiq px_msiq_t; 560Sstevel@tonic-gate 570Sstevel@tonic-gate extern int px_lib_dev_init(dev_info_t *dip, devhandle_t *dev_hdl); 580Sstevel@tonic-gate extern int px_lib_dev_fini(dev_info_t *dip); 590Sstevel@tonic-gate extern int px_lib_map_vconfig(dev_info_t *dip, ddi_map_req_t *mp, 600Sstevel@tonic-gate pci_config_offset_t off, pci_regspec_t *rp, caddr_t *addrp); 61677Sjchu extern void px_lib_map_attr_check(ddi_map_req_t *mp); 621617Sgovinda 630Sstevel@tonic-gate extern int px_lib_intr_devino_to_sysino(dev_info_t *dip, devino_t devino, 640Sstevel@tonic-gate sysino_t *sysino); 650Sstevel@tonic-gate extern int px_lib_intr_getvalid(dev_info_t *dip, sysino_t sysino, 660Sstevel@tonic-gate intr_valid_state_t *intr_valid_state); 670Sstevel@tonic-gate extern int px_lib_intr_setvalid(dev_info_t *dip, sysino_t sysino, 680Sstevel@tonic-gate intr_valid_state_t intr_valid_state); 690Sstevel@tonic-gate extern int px_lib_intr_getstate(dev_info_t *dip, sysino_t sysino, 700Sstevel@tonic-gate intr_state_t *intr_state); 710Sstevel@tonic-gate extern int px_lib_intr_setstate(dev_info_t *dip, sysino_t sysino, 720Sstevel@tonic-gate intr_state_t intr_state); 730Sstevel@tonic-gate extern int px_lib_intr_gettarget(dev_info_t *dip, sysino_t sysino, 740Sstevel@tonic-gate cpuid_t *cpuid); 750Sstevel@tonic-gate extern int px_lib_intr_settarget(dev_info_t *dip, sysino_t sysino, 760Sstevel@tonic-gate cpuid_t cpuid); 770Sstevel@tonic-gate extern int px_lib_intr_reset(dev_info_t *dip); 780Sstevel@tonic-gate 7927Sjchu #ifdef FMA 8027Sjchu extern void px_fill_rc_status(px_fault_t *px_fault_p, 8127Sjchu pciex_rc_error_regs_t *rc_status); 8227Sjchu #endif 8327Sjchu 840Sstevel@tonic-gate extern int px_lib_iommu_map(dev_info_t *dip, tsbid_t tsbid, pages_t pages, 851617Sgovinda io_attributes_t attr, void *addr, size_t pfn_index, int flags); 860Sstevel@tonic-gate extern int px_lib_iommu_demap(dev_info_t *dip, tsbid_t tsbid, pages_t pages); 870Sstevel@tonic-gate extern int px_lib_iommu_getmap(dev_info_t *dip, tsbid_t tsbid, 881617Sgovinda io_attributes_t *attr_p, r_addr_t *r_addr_p); 891772Sjl139090 extern int px_lib_dma_bypass_rngchk(dev_info_t *dip, ddi_dma_attr_t *attr_p, 901772Sjl139090 uint64_t *lo_p, uint64_t *hi_p); 910Sstevel@tonic-gate extern int px_lib_iommu_getbypass(dev_info_t *dip, r_addr_t ra, 921617Sgovinda io_attributes_t attr, io_addr_t *io_addr_p); 93*12619Sandrew.rutz@sun.com extern int px_lib_iommu_detach(px_t *px_p); 948691SLida.Horn@Sun.COM extern uint64_t px_lib_ro_bypass(dev_info_t *dip, io_attributes_t attr, 958691SLida.Horn@Sun.COM uint64_t io_addr); 960Sstevel@tonic-gate extern int px_lib_dma_sync(dev_info_t *dip, dev_info_t *rdip, 970Sstevel@tonic-gate ddi_dma_handle_t handle, off_t off, size_t len, uint_t cache_flags); 980Sstevel@tonic-gate 990Sstevel@tonic-gate /* 1000Sstevel@tonic-gate * MSIQ Functions: 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate extern int px_lib_msiq_init(dev_info_t *dip); 1030Sstevel@tonic-gate extern int px_lib_msiq_fini(dev_info_t *dip); 1040Sstevel@tonic-gate extern int px_lib_msiq_info(dev_info_t *dip, msiqid_t msiq_id, 1050Sstevel@tonic-gate r_addr_t *ra_p, uint_t *msiq_rec_cnt_p); 1060Sstevel@tonic-gate extern int px_lib_msiq_getvalid(dev_info_t *dip, msiqid_t msiq_id, 1070Sstevel@tonic-gate pci_msiq_valid_state_t *msiq_valid_state); 1080Sstevel@tonic-gate extern int px_lib_msiq_setvalid(dev_info_t *dip, msiqid_t msiq_id, 1090Sstevel@tonic-gate pci_msiq_valid_state_t msiq_valid_state); 1100Sstevel@tonic-gate extern int px_lib_msiq_getstate(dev_info_t *dip, msiqid_t msiq_id, 1110Sstevel@tonic-gate pci_msiq_state_t *msiq_state); 1120Sstevel@tonic-gate extern int px_lib_msiq_setstate(dev_info_t *dip, msiqid_t msiq_id, 1130Sstevel@tonic-gate pci_msiq_state_t msiq_state); 1140Sstevel@tonic-gate extern int px_lib_msiq_gethead(dev_info_t *dip, msiqid_t msiq_id, 1150Sstevel@tonic-gate msiqhead_t *msiq_head); 1160Sstevel@tonic-gate extern int px_lib_msiq_sethead(dev_info_t *dip, msiqid_t msiq_id, 1170Sstevel@tonic-gate msiqhead_t msiq_head); 1180Sstevel@tonic-gate extern int px_lib_msiq_gettail(dev_info_t *dip, msiqid_t msiq_id, 1190Sstevel@tonic-gate msiqtail_t *msiq_tail); 1202588Segillett extern void px_lib_get_msiq_rec(dev_info_t *dip, msiqhead_t *msiq_head_p, 1210Sstevel@tonic-gate msiq_rec_t *msiq_rec_p); 1222973Sgovinda extern void px_lib_clr_msiq_rec(dev_info_t *dip, msiqhead_t *msiq_head_p); 1232973Sgovinda 1240Sstevel@tonic-gate /* 1250Sstevel@tonic-gate * MSI Functions: 1260Sstevel@tonic-gate */ 1270Sstevel@tonic-gate extern int px_lib_msi_init(dev_info_t *dip); 1280Sstevel@tonic-gate extern int px_lib_msi_getmsiq(dev_info_t *dip, msinum_t msi_num, 1290Sstevel@tonic-gate msiqid_t *msiq_id); 1300Sstevel@tonic-gate extern int px_lib_msi_setmsiq(dev_info_t *dip, msinum_t msi_num, 1310Sstevel@tonic-gate msiqid_t msiq_id, msi_type_t msitype); 1320Sstevel@tonic-gate extern int px_lib_msi_getvalid(dev_info_t *dip, msinum_t msi_num, 1330Sstevel@tonic-gate pci_msi_valid_state_t *msi_valid_state); 1340Sstevel@tonic-gate extern int px_lib_msi_setvalid(dev_info_t *dip, msinum_t msi_num, 1350Sstevel@tonic-gate pci_msi_valid_state_t msi_valid_state); 1360Sstevel@tonic-gate extern int px_lib_msi_getstate(dev_info_t *dip, msinum_t msi_num, 1370Sstevel@tonic-gate pci_msi_state_t *msi_state); 1380Sstevel@tonic-gate extern int px_lib_msi_setstate(dev_info_t *dip, msinum_t msi_num, 1390Sstevel@tonic-gate pci_msi_state_t msi_state); 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate /* 1420Sstevel@tonic-gate * MSG Functions: 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate extern int px_lib_msg_getmsiq(dev_info_t *dip, pcie_msg_type_t msg_type, 1450Sstevel@tonic-gate msiqid_t *msiq_id); 1460Sstevel@tonic-gate extern int px_lib_msg_setmsiq(dev_info_t *dip, pcie_msg_type_t msg_type, 1470Sstevel@tonic-gate msiqid_t msiq_id); 1480Sstevel@tonic-gate extern int px_lib_msg_getvalid(dev_info_t *dip, pcie_msg_type_t msg_type, 1490Sstevel@tonic-gate pcie_msg_valid_state_t *msg_valid_state); 1500Sstevel@tonic-gate extern int px_lib_msg_setvalid(dev_info_t *dip, pcie_msg_type_t msg_type, 1510Sstevel@tonic-gate pcie_msg_valid_state_t msg_valid_state); 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate /* 1541648Sjchu * PM/CPR Functions: 1550Sstevel@tonic-gate */ 1560Sstevel@tonic-gate extern int px_lib_suspend(dev_info_t *dip); 1570Sstevel@tonic-gate extern void px_lib_resume(dev_info_t *dip); 1581648Sjchu extern void px_cpr_add_callb(px_t *); 1591648Sjchu extern void px_cpr_rem_callb(px_t *); 1601648Sjchu extern int px_lib_pmctl(int cmd, px_t *px_p); 1611648Sjchu extern uint_t px_pmeq_intr(caddr_t arg); 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* 1642053Sschwartz * Common range property functions and definitions. 1650Sstevel@tonic-gate */ 1662053Sschwartz #define PX_RANGE_PROP_MASK 0x7ff 1672053Sschwartz extern uint64_t px_get_rng_parent_hi_mask(px_t *px_p); 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate /* 1700Sstevel@tonic-gate * Peek and poke access ddi_ctlops helper functions 1710Sstevel@tonic-gate */ 1720Sstevel@tonic-gate extern int px_lib_ctlops_poke(dev_info_t *dip, dev_info_t *rdip, 1730Sstevel@tonic-gate peekpoke_ctlops_t *in_args); 1740Sstevel@tonic-gate extern int px_lib_ctlops_peek(dev_info_t *dip, dev_info_t *rdip, 1750Sstevel@tonic-gate peekpoke_ctlops_t *in_args, void *result); 1760Sstevel@tonic-gate 17727Sjchu /* 17827Sjchu * Error handling functions 17927Sjchu */ 18027Sjchu #define PX_INTR_PAYLOAD_SIZE 8 /* 64 bit words */ 18127Sjchu typedef struct px_fault { 18227Sjchu dev_info_t *px_fh_dip; 18327Sjchu sysino_t px_fh_sysino; 18427Sjchu uint_t (*px_err_func)(caddr_t px_fault); 18527Sjchu devino_t px_intr_ino; 18627Sjchu uint64_t px_intr_payload[PX_INTR_PAYLOAD_SIZE]; 18727Sjchu } px_fault_t; 18827Sjchu 18927Sjchu extern int px_err_add_intr(px_fault_t *px_fault_p); 19027Sjchu extern void px_err_rem_intr(px_fault_t *px_fault_p); 1911648Sjchu extern int px_cb_add_intr(px_fault_t *); 1921648Sjchu extern void px_cb_rem_intr(px_fault_t *); 19311596SJason.Beloro@Sun.COM extern void px_panic_domain(px_t *px_p, pcie_req_id_t bdf); 19427Sjchu 195435Sjchu /* 196435Sjchu * CPR callback 197435Sjchu */ 198435Sjchu extern void px_cpr_add_callb(px_t *); 199435Sjchu extern void px_cpr_rem_callb(px_t *); 200435Sjchu 2011531Skini /* 2021531Skini * Hotplug functions 2031531Skini */ 2041531Skini extern int px_lib_hotplug_init(dev_info_t *dip, void *regops); 2051531Skini extern void px_lib_hotplug_uninit(dev_info_t *dip); 2063953Sscarter extern void px_hp_intr_redist(px_t *px_p); 2071531Skini 2082476Sdwoods extern boolean_t px_lib_is_in_drain_state(px_t *px_p); 2093613Set142600 extern pcie_req_id_t px_lib_get_bdf(px_t *px_p); 2102476Sdwoods 2117596SAlan.Adamson@Sun.COM extern int px_lib_get_root_complex_mps(px_t *px_p, dev_info_t *dip, int *mps); 2127596SAlan.Adamson@Sun.COM extern int px_lib_set_root_complex_mps(px_t *px_p, dev_info_t *dip, int mps); 2137596SAlan.Adamson@Sun.COM 21411245SZhijun.Fu@Sun.COM /* 21511245SZhijun.Fu@Sun.COM * Config space access 21611245SZhijun.Fu@Sun.COM */ 21711245SZhijun.Fu@Sun.COM extern uint64_t px_lib_get_cfgacc_base(dev_info_t *dip); 21811245SZhijun.Fu@Sun.COM 21911596SJason.Beloro@Sun.COM /* 22011596SJason.Beloro@Sun.COM * PCI IOV SDIO functions 22111596SJason.Beloro@Sun.COM */ 22211596SJason.Beloro@Sun.COM extern int px_lib_fabric_sync(dev_info_t *dip); 22311596SJason.Beloro@Sun.COM 2240Sstevel@tonic-gate #ifdef __cplusplus 2250Sstevel@tonic-gate } 2260Sstevel@tonic-gate #endif 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate #endif /* _SYS_PX_LIB_H */ 229