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 /* 221531Skini * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_PX_LIB_H 270Sstevel@tonic-gate #define _SYS_PX_LIB_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 350Sstevel@tonic-gate /* 360Sstevel@tonic-gate * Include all data structures and definitions in this file that are 370Sstevel@tonic-gate * required between the common and hardware specific code. 380Sstevel@tonic-gate */ 390Sstevel@tonic-gate 400Sstevel@tonic-gate #define DIP_TO_HANDLE(dip) ((px_t *)DIP_TO_STATE(dip))->px_dev_hdl 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * The following macros define the mmu page size and related operations. 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate #define MMU_PAGE_SHIFT 13 460Sstevel@tonic-gate #define MMU_PAGE_SIZE (1 << MMU_PAGE_SHIFT) 470Sstevel@tonic-gate #define MMU_PAGE_MASK ~(MMU_PAGE_SIZE - 1) 480Sstevel@tonic-gate #define MMU_PAGE_OFFSET (MMU_PAGE_SIZE - 1) 490Sstevel@tonic-gate #define MMU_PTOB(x) (((uint64_t)(x)) << MMU_PAGE_SHIFT) 500Sstevel@tonic-gate #define MMU_BTOP(x) ((x) >> MMU_PAGE_SHIFT) 510Sstevel@tonic-gate #define MMU_BTOPR(x) MMU_BTOP((x) + MMU_PAGE_OFFSET) 520Sstevel@tonic-gate 530Sstevel@tonic-gate /* MMU map flags */ 541617Sgovinda #define MMU_MAP_PFN 1 551617Sgovinda #define MMU_MAP_BUF 2 560Sstevel@tonic-gate 570Sstevel@tonic-gate typedef struct px px_t; 580Sstevel@tonic-gate typedef struct px_msiq px_msiq_t; 590Sstevel@tonic-gate 600Sstevel@tonic-gate extern int px_lib_dev_init(dev_info_t *dip, devhandle_t *dev_hdl); 610Sstevel@tonic-gate extern int px_lib_dev_fini(dev_info_t *dip); 620Sstevel@tonic-gate extern int px_lib_map_vconfig(dev_info_t *dip, ddi_map_req_t *mp, 630Sstevel@tonic-gate pci_config_offset_t off, pci_regspec_t *rp, caddr_t *addrp); 64677Sjchu extern void px_lib_map_attr_check(ddi_map_req_t *mp); 651617Sgovinda 660Sstevel@tonic-gate extern int px_lib_intr_devino_to_sysino(dev_info_t *dip, devino_t devino, 670Sstevel@tonic-gate sysino_t *sysino); 680Sstevel@tonic-gate extern int px_lib_intr_getvalid(dev_info_t *dip, sysino_t sysino, 690Sstevel@tonic-gate intr_valid_state_t *intr_valid_state); 700Sstevel@tonic-gate extern int px_lib_intr_setvalid(dev_info_t *dip, sysino_t sysino, 710Sstevel@tonic-gate intr_valid_state_t intr_valid_state); 720Sstevel@tonic-gate extern int px_lib_intr_getstate(dev_info_t *dip, sysino_t sysino, 730Sstevel@tonic-gate intr_state_t *intr_state); 740Sstevel@tonic-gate extern int px_lib_intr_setstate(dev_info_t *dip, sysino_t sysino, 750Sstevel@tonic-gate intr_state_t intr_state); 760Sstevel@tonic-gate extern int px_lib_intr_gettarget(dev_info_t *dip, sysino_t sysino, 770Sstevel@tonic-gate cpuid_t *cpuid); 780Sstevel@tonic-gate extern int px_lib_intr_settarget(dev_info_t *dip, sysino_t sysino, 790Sstevel@tonic-gate cpuid_t cpuid); 800Sstevel@tonic-gate extern int px_lib_intr_reset(dev_info_t *dip); 810Sstevel@tonic-gate 8227Sjchu #ifdef FMA 8327Sjchu extern void px_fill_rc_status(px_fault_t *px_fault_p, 8427Sjchu pciex_rc_error_regs_t *rc_status); 8527Sjchu #endif 8627Sjchu 870Sstevel@tonic-gate extern int px_lib_iommu_map(dev_info_t *dip, tsbid_t tsbid, pages_t pages, 881617Sgovinda io_attributes_t attr, void *addr, size_t pfn_index, int flags); 890Sstevel@tonic-gate extern int px_lib_iommu_demap(dev_info_t *dip, tsbid_t tsbid, pages_t pages); 900Sstevel@tonic-gate extern int px_lib_iommu_getmap(dev_info_t *dip, tsbid_t tsbid, 911617Sgovinda io_attributes_t *attr_p, r_addr_t *r_addr_p); 92*1772Sjl139090 extern int px_lib_dma_bypass_rngchk(dev_info_t *dip, ddi_dma_attr_t *attr_p, 93*1772Sjl139090 uint64_t *lo_p, uint64_t *hi_p); 940Sstevel@tonic-gate extern int px_lib_iommu_getbypass(dev_info_t *dip, r_addr_t ra, 951617Sgovinda io_attributes_t attr, io_addr_t *io_addr_p); 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); 1200Sstevel@tonic-gate extern void px_lib_get_msiq_rec(dev_info_t *dip, px_msiq_t *msiq_p, 1210Sstevel@tonic-gate msiq_rec_t *msiq_rec_p); 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate /* 1240Sstevel@tonic-gate * MSI Functions: 1250Sstevel@tonic-gate */ 1260Sstevel@tonic-gate extern int px_lib_msi_init(dev_info_t *dip); 1270Sstevel@tonic-gate extern int px_lib_msi_getmsiq(dev_info_t *dip, msinum_t msi_num, 1280Sstevel@tonic-gate msiqid_t *msiq_id); 1290Sstevel@tonic-gate extern int px_lib_msi_setmsiq(dev_info_t *dip, msinum_t msi_num, 1300Sstevel@tonic-gate msiqid_t msiq_id, msi_type_t msitype); 1310Sstevel@tonic-gate extern int px_lib_msi_getvalid(dev_info_t *dip, msinum_t msi_num, 1320Sstevel@tonic-gate pci_msi_valid_state_t *msi_valid_state); 1330Sstevel@tonic-gate extern int px_lib_msi_setvalid(dev_info_t *dip, msinum_t msi_num, 1340Sstevel@tonic-gate pci_msi_valid_state_t msi_valid_state); 1350Sstevel@tonic-gate extern int px_lib_msi_getstate(dev_info_t *dip, msinum_t msi_num, 1360Sstevel@tonic-gate pci_msi_state_t *msi_state); 1370Sstevel@tonic-gate extern int px_lib_msi_setstate(dev_info_t *dip, msinum_t msi_num, 1380Sstevel@tonic-gate pci_msi_state_t msi_state); 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* 1410Sstevel@tonic-gate * MSG Functions: 1420Sstevel@tonic-gate */ 1430Sstevel@tonic-gate extern int px_lib_msg_getmsiq(dev_info_t *dip, pcie_msg_type_t msg_type, 1440Sstevel@tonic-gate msiqid_t *msiq_id); 1450Sstevel@tonic-gate extern int px_lib_msg_setmsiq(dev_info_t *dip, pcie_msg_type_t msg_type, 1460Sstevel@tonic-gate msiqid_t msiq_id); 1470Sstevel@tonic-gate extern int px_lib_msg_getvalid(dev_info_t *dip, pcie_msg_type_t msg_type, 1480Sstevel@tonic-gate pcie_msg_valid_state_t *msg_valid_state); 1490Sstevel@tonic-gate extern int px_lib_msg_setvalid(dev_info_t *dip, pcie_msg_type_t msg_type, 1500Sstevel@tonic-gate pcie_msg_valid_state_t msg_valid_state); 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate /* 1531648Sjchu * PM/CPR Functions: 1540Sstevel@tonic-gate */ 1550Sstevel@tonic-gate extern int px_lib_suspend(dev_info_t *dip); 1560Sstevel@tonic-gate extern void px_lib_resume(dev_info_t *dip); 1571648Sjchu extern void px_cpr_add_callb(px_t *); 1581648Sjchu extern void px_cpr_rem_callb(px_t *); 1591648Sjchu extern int px_lib_pmctl(int cmd, px_t *px_p); 1601648Sjchu extern uint_t px_pmeq_intr(caddr_t arg); 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate /* 1630Sstevel@tonic-gate * PCI tool Functions: 1640Sstevel@tonic-gate */ 1650Sstevel@tonic-gate extern int px_lib_tools_dev_reg_ops(dev_info_t *dip, void *arg, 1660Sstevel@tonic-gate int cmd, int mode); 1670Sstevel@tonic-gate extern int px_lib_tools_bus_reg_ops(dev_info_t *dip, void *arg, int cmd, 1680Sstevel@tonic-gate int mode); 1690Sstevel@tonic-gate extern int px_lib_tools_intr_admn(dev_info_t *dip, void *arg, int cmd, 1700Sstevel@tonic-gate int mode); 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate /* 1730Sstevel@tonic-gate * Peek and poke access ddi_ctlops helper functions 1740Sstevel@tonic-gate */ 1750Sstevel@tonic-gate extern int px_lib_ctlops_poke(dev_info_t *dip, dev_info_t *rdip, 1760Sstevel@tonic-gate peekpoke_ctlops_t *in_args); 1770Sstevel@tonic-gate extern int px_lib_ctlops_peek(dev_info_t *dip, dev_info_t *rdip, 1780Sstevel@tonic-gate peekpoke_ctlops_t *in_args, void *result); 1790Sstevel@tonic-gate 18027Sjchu /* 18127Sjchu * Error handling functions 18227Sjchu */ 18327Sjchu #define PX_INTR_PAYLOAD_SIZE 8 /* 64 bit words */ 18427Sjchu typedef struct px_fault { 18527Sjchu dev_info_t *px_fh_dip; 18627Sjchu sysino_t px_fh_sysino; 18727Sjchu uint_t (*px_err_func)(caddr_t px_fault); 18827Sjchu devino_t px_intr_ino; 18927Sjchu uint64_t px_intr_payload[PX_INTR_PAYLOAD_SIZE]; 19027Sjchu } px_fault_t; 19127Sjchu 19227Sjchu extern int px_err_add_intr(px_fault_t *px_fault_p); 19327Sjchu extern void px_err_rem_intr(px_fault_t *px_fault_p); 1941648Sjchu extern int px_cb_add_intr(px_fault_t *); 1951648Sjchu extern void px_cb_rem_intr(px_fault_t *); 1961648Sjchu extern void px_cb_intr_redist(px_t *); 197383Set142600 extern uint32_t px_fab_get(px_t *px_p, pcie_req_id_t bdf, 198383Set142600 uint16_t offset); 199383Set142600 extern void px_fab_set(px_t *px_p, pcie_req_id_t bdf, uint16_t offset, 200383Set142600 uint32_t val); 20127Sjchu 202435Sjchu /* 203435Sjchu * CPR callback 204435Sjchu */ 205435Sjchu extern void px_cpr_add_callb(px_t *); 206435Sjchu extern void px_cpr_rem_callb(px_t *); 207435Sjchu 2081531Skini /* 2091531Skini * Hotplug functions 2101531Skini */ 2111531Skini extern int px_lib_hotplug_init(dev_info_t *dip, void *regops); 2121531Skini extern void px_lib_hotplug_uninit(dev_info_t *dip); 2131531Skini 2140Sstevel@tonic-gate #ifdef __cplusplus 2150Sstevel@tonic-gate } 2160Sstevel@tonic-gate #endif 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate #endif /* _SYS_PX_LIB_H */ 219