17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57aadd8d4Skini * Common Development and Distribution License (the "License"). 67aadd8d4Skini * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*89b42a21Sandrew.rutz@sun.com * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #ifndef _SYS_PX_LIB_H 267c478bd9Sstevel@tonic-gate #define _SYS_PX_LIB_H 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #ifdef __cplusplus 297c478bd9Sstevel@tonic-gate extern "C" { 307c478bd9Sstevel@tonic-gate #endif 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* 337c478bd9Sstevel@tonic-gate * Include all data structures and definitions in this file that are 347c478bd9Sstevel@tonic-gate * required between the common and hardware specific code. 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #define DIP_TO_HANDLE(dip) ((px_t *)DIP_TO_STATE(dip))->px_dev_hdl 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /* 407c478bd9Sstevel@tonic-gate * The following macros define the mmu page size and related operations. 417c478bd9Sstevel@tonic-gate */ 427c478bd9Sstevel@tonic-gate #define MMU_PAGE_SHIFT 13 437c478bd9Sstevel@tonic-gate #define MMU_PAGE_SIZE (1 << MMU_PAGE_SHIFT) 447c478bd9Sstevel@tonic-gate #define MMU_PAGE_MASK ~(MMU_PAGE_SIZE - 1) 457c478bd9Sstevel@tonic-gate #define MMU_PAGE_OFFSET (MMU_PAGE_SIZE - 1) 467c478bd9Sstevel@tonic-gate #define MMU_PTOB(x) (((uint64_t)(x)) << MMU_PAGE_SHIFT) 477c478bd9Sstevel@tonic-gate #define MMU_BTOP(x) ((x) >> MMU_PAGE_SHIFT) 487c478bd9Sstevel@tonic-gate #define MMU_BTOPR(x) MMU_BTOP((x) + MMU_PAGE_OFFSET) 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* MMU map flags */ 5144bb982bSgovinda #define MMU_MAP_PFN 1 5244bb982bSgovinda #define MMU_MAP_BUF 2 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate typedef struct px px_t; 557c478bd9Sstevel@tonic-gate typedef struct px_msiq px_msiq_t; 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate extern int px_lib_dev_init(dev_info_t *dip, devhandle_t *dev_hdl); 587c478bd9Sstevel@tonic-gate extern int px_lib_dev_fini(dev_info_t *dip); 597c478bd9Sstevel@tonic-gate extern int px_lib_map_vconfig(dev_info_t *dip, ddi_map_req_t *mp, 607c478bd9Sstevel@tonic-gate pci_config_offset_t off, pci_regspec_t *rp, caddr_t *addrp); 614fbb58f6Sjchu extern void px_lib_map_attr_check(ddi_map_req_t *mp); 6244bb982bSgovinda 637c478bd9Sstevel@tonic-gate extern int px_lib_intr_devino_to_sysino(dev_info_t *dip, devino_t devino, 647c478bd9Sstevel@tonic-gate sysino_t *sysino); 657c478bd9Sstevel@tonic-gate extern int px_lib_intr_getvalid(dev_info_t *dip, sysino_t sysino, 667c478bd9Sstevel@tonic-gate intr_valid_state_t *intr_valid_state); 677c478bd9Sstevel@tonic-gate extern int px_lib_intr_setvalid(dev_info_t *dip, sysino_t sysino, 687c478bd9Sstevel@tonic-gate intr_valid_state_t intr_valid_state); 697c478bd9Sstevel@tonic-gate extern int px_lib_intr_getstate(dev_info_t *dip, sysino_t sysino, 707c478bd9Sstevel@tonic-gate intr_state_t *intr_state); 717c478bd9Sstevel@tonic-gate extern int px_lib_intr_setstate(dev_info_t *dip, sysino_t sysino, 727c478bd9Sstevel@tonic-gate intr_state_t intr_state); 737c478bd9Sstevel@tonic-gate extern int px_lib_intr_gettarget(dev_info_t *dip, sysino_t sysino, 747c478bd9Sstevel@tonic-gate cpuid_t *cpuid); 757c478bd9Sstevel@tonic-gate extern int px_lib_intr_settarget(dev_info_t *dip, sysino_t sysino, 767c478bd9Sstevel@tonic-gate cpuid_t cpuid); 777c478bd9Sstevel@tonic-gate extern int px_lib_intr_reset(dev_info_t *dip); 787c478bd9Sstevel@tonic-gate 79f8d2de6bSjchu #ifdef FMA 80f8d2de6bSjchu extern void px_fill_rc_status(px_fault_t *px_fault_p, 81f8d2de6bSjchu pciex_rc_error_regs_t *rc_status); 82f8d2de6bSjchu #endif 83f8d2de6bSjchu 847c478bd9Sstevel@tonic-gate extern int px_lib_iommu_map(dev_info_t *dip, tsbid_t tsbid, pages_t pages, 8544bb982bSgovinda io_attributes_t attr, void *addr, size_t pfn_index, int flags); 867c478bd9Sstevel@tonic-gate extern int px_lib_iommu_demap(dev_info_t *dip, tsbid_t tsbid, pages_t pages); 877c478bd9Sstevel@tonic-gate extern int px_lib_iommu_getmap(dev_info_t *dip, tsbid_t tsbid, 8844bb982bSgovinda io_attributes_t *attr_p, r_addr_t *r_addr_p); 8925cf1a30Sjl139090 extern int px_lib_dma_bypass_rngchk(dev_info_t *dip, ddi_dma_attr_t *attr_p, 9025cf1a30Sjl139090 uint64_t *lo_p, uint64_t *hi_p); 917c478bd9Sstevel@tonic-gate extern int px_lib_iommu_getbypass(dev_info_t *dip, r_addr_t ra, 9244bb982bSgovinda io_attributes_t attr, io_addr_t *io_addr_p); 93*89b42a21Sandrew.rutz@sun.com extern int px_lib_iommu_detach(px_t *px_p); 94a616a11eSLida.Horn extern uint64_t px_lib_ro_bypass(dev_info_t *dip, io_attributes_t attr, 95a616a11eSLida.Horn uint64_t io_addr); 967c478bd9Sstevel@tonic-gate extern int px_lib_dma_sync(dev_info_t *dip, dev_info_t *rdip, 977c478bd9Sstevel@tonic-gate ddi_dma_handle_t handle, off_t off, size_t len, uint_t cache_flags); 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate /* 1007c478bd9Sstevel@tonic-gate * MSIQ Functions: 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate extern int px_lib_msiq_init(dev_info_t *dip); 1037c478bd9Sstevel@tonic-gate extern int px_lib_msiq_fini(dev_info_t *dip); 1047c478bd9Sstevel@tonic-gate extern int px_lib_msiq_info(dev_info_t *dip, msiqid_t msiq_id, 1057c478bd9Sstevel@tonic-gate r_addr_t *ra_p, uint_t *msiq_rec_cnt_p); 1067c478bd9Sstevel@tonic-gate extern int px_lib_msiq_getvalid(dev_info_t *dip, msiqid_t msiq_id, 1077c478bd9Sstevel@tonic-gate pci_msiq_valid_state_t *msiq_valid_state); 1087c478bd9Sstevel@tonic-gate extern int px_lib_msiq_setvalid(dev_info_t *dip, msiqid_t msiq_id, 1097c478bd9Sstevel@tonic-gate pci_msiq_valid_state_t msiq_valid_state); 1107c478bd9Sstevel@tonic-gate extern int px_lib_msiq_getstate(dev_info_t *dip, msiqid_t msiq_id, 1117c478bd9Sstevel@tonic-gate pci_msiq_state_t *msiq_state); 1127c478bd9Sstevel@tonic-gate extern int px_lib_msiq_setstate(dev_info_t *dip, msiqid_t msiq_id, 1137c478bd9Sstevel@tonic-gate pci_msiq_state_t msiq_state); 1147c478bd9Sstevel@tonic-gate extern int px_lib_msiq_gethead(dev_info_t *dip, msiqid_t msiq_id, 1157c478bd9Sstevel@tonic-gate msiqhead_t *msiq_head); 1167c478bd9Sstevel@tonic-gate extern int px_lib_msiq_sethead(dev_info_t *dip, msiqid_t msiq_id, 1177c478bd9Sstevel@tonic-gate msiqhead_t msiq_head); 1187c478bd9Sstevel@tonic-gate extern int px_lib_msiq_gettail(dev_info_t *dip, msiqid_t msiq_id, 1197c478bd9Sstevel@tonic-gate msiqtail_t *msiq_tail); 120023ccc1eSegillett extern void px_lib_get_msiq_rec(dev_info_t *dip, msiqhead_t *msiq_head_p, 1217c478bd9Sstevel@tonic-gate msiq_rec_t *msiq_rec_p); 122b0fc0e77Sgovinda extern void px_lib_clr_msiq_rec(dev_info_t *dip, msiqhead_t *msiq_head_p); 123b0fc0e77Sgovinda 1247c478bd9Sstevel@tonic-gate /* 1257c478bd9Sstevel@tonic-gate * MSI Functions: 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate extern int px_lib_msi_init(dev_info_t *dip); 1287c478bd9Sstevel@tonic-gate extern int px_lib_msi_getmsiq(dev_info_t *dip, msinum_t msi_num, 1297c478bd9Sstevel@tonic-gate msiqid_t *msiq_id); 1307c478bd9Sstevel@tonic-gate extern int px_lib_msi_setmsiq(dev_info_t *dip, msinum_t msi_num, 1317c478bd9Sstevel@tonic-gate msiqid_t msiq_id, msi_type_t msitype); 1327c478bd9Sstevel@tonic-gate extern int px_lib_msi_getvalid(dev_info_t *dip, msinum_t msi_num, 1337c478bd9Sstevel@tonic-gate pci_msi_valid_state_t *msi_valid_state); 1347c478bd9Sstevel@tonic-gate extern int px_lib_msi_setvalid(dev_info_t *dip, msinum_t msi_num, 1357c478bd9Sstevel@tonic-gate pci_msi_valid_state_t msi_valid_state); 1367c478bd9Sstevel@tonic-gate extern int px_lib_msi_getstate(dev_info_t *dip, msinum_t msi_num, 1377c478bd9Sstevel@tonic-gate pci_msi_state_t *msi_state); 1387c478bd9Sstevel@tonic-gate extern int px_lib_msi_setstate(dev_info_t *dip, msinum_t msi_num, 1397c478bd9Sstevel@tonic-gate pci_msi_state_t msi_state); 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate /* 1427c478bd9Sstevel@tonic-gate * MSG Functions: 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate extern int px_lib_msg_getmsiq(dev_info_t *dip, pcie_msg_type_t msg_type, 1457c478bd9Sstevel@tonic-gate msiqid_t *msiq_id); 1467c478bd9Sstevel@tonic-gate extern int px_lib_msg_setmsiq(dev_info_t *dip, pcie_msg_type_t msg_type, 1477c478bd9Sstevel@tonic-gate msiqid_t msiq_id); 1487c478bd9Sstevel@tonic-gate extern int px_lib_msg_getvalid(dev_info_t *dip, pcie_msg_type_t msg_type, 1497c478bd9Sstevel@tonic-gate pcie_msg_valid_state_t *msg_valid_state); 1507c478bd9Sstevel@tonic-gate extern int px_lib_msg_setvalid(dev_info_t *dip, pcie_msg_type_t msg_type, 1517c478bd9Sstevel@tonic-gate pcie_msg_valid_state_t msg_valid_state); 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate /* 15401689544Sjchu * PM/CPR Functions: 1557c478bd9Sstevel@tonic-gate */ 1567c478bd9Sstevel@tonic-gate extern int px_lib_suspend(dev_info_t *dip); 1577c478bd9Sstevel@tonic-gate extern void px_lib_resume(dev_info_t *dip); 15801689544Sjchu extern void px_cpr_add_callb(px_t *); 15901689544Sjchu extern void px_cpr_rem_callb(px_t *); 16001689544Sjchu extern int px_lib_pmctl(int cmd, px_t *px_p); 16101689544Sjchu extern uint_t px_pmeq_intr(caddr_t arg); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* 164d3533785Sschwartz * Common range property functions and definitions. 1657c478bd9Sstevel@tonic-gate */ 166d3533785Sschwartz #define PX_RANGE_PROP_MASK 0x7ff 167d3533785Sschwartz extern uint64_t px_get_rng_parent_hi_mask(px_t *px_p); 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate /* 1707c478bd9Sstevel@tonic-gate * Peek and poke access ddi_ctlops helper functions 1717c478bd9Sstevel@tonic-gate */ 1727c478bd9Sstevel@tonic-gate extern int px_lib_ctlops_poke(dev_info_t *dip, dev_info_t *rdip, 1737c478bd9Sstevel@tonic-gate peekpoke_ctlops_t *in_args); 1747c478bd9Sstevel@tonic-gate extern int px_lib_ctlops_peek(dev_info_t *dip, dev_info_t *rdip, 1757c478bd9Sstevel@tonic-gate peekpoke_ctlops_t *in_args, void *result); 1767c478bd9Sstevel@tonic-gate 177f8d2de6bSjchu /* 178f8d2de6bSjchu * Error handling functions 179f8d2de6bSjchu */ 180f8d2de6bSjchu #define PX_INTR_PAYLOAD_SIZE 8 /* 64 bit words */ 181f8d2de6bSjchu typedef struct px_fault { 182f8d2de6bSjchu dev_info_t *px_fh_dip; 183f8d2de6bSjchu sysino_t px_fh_sysino; 184f8d2de6bSjchu uint_t (*px_err_func)(caddr_t px_fault); 185f8d2de6bSjchu devino_t px_intr_ino; 186f8d2de6bSjchu uint64_t px_intr_payload[PX_INTR_PAYLOAD_SIZE]; 187f8d2de6bSjchu } px_fault_t; 188f8d2de6bSjchu 189f8d2de6bSjchu extern int px_err_add_intr(px_fault_t *px_fault_p); 190f8d2de6bSjchu extern void px_err_rem_intr(px_fault_t *px_fault_p); 19101689544Sjchu extern int px_cb_add_intr(px_fault_t *); 19201689544Sjchu extern void px_cb_rem_intr(px_fault_t *); 193fc256490SJason Beloro extern void px_panic_domain(px_t *px_p, pcie_req_id_t bdf); 194f8d2de6bSjchu 195817a6df8Sjchu /* 196817a6df8Sjchu * CPR callback 197817a6df8Sjchu */ 198817a6df8Sjchu extern void px_cpr_add_callb(px_t *); 199817a6df8Sjchu extern void px_cpr_rem_callb(px_t *); 200817a6df8Sjchu 201b65731f1Skini /* 202b65731f1Skini * Hotplug functions 203b65731f1Skini */ 204b65731f1Skini extern int px_lib_hotplug_init(dev_info_t *dip, void *regops); 205b65731f1Skini extern void px_lib_hotplug_uninit(dev_info_t *dip); 206ab4471cdSscarter extern void px_hp_intr_redist(px_t *px_p); 207b65731f1Skini 208d60bae31Sdwoods extern boolean_t px_lib_is_in_drain_state(px_t *px_p); 2097ea9b230Set142600 extern pcie_req_id_t px_lib_get_bdf(px_t *px_p); 210d60bae31Sdwoods 2110114761dSAlan Adamson, SD OSSD extern int px_lib_get_root_complex_mps(px_t *px_p, dev_info_t *dip, int *mps); 2120114761dSAlan Adamson, SD OSSD extern int px_lib_set_root_complex_mps(px_t *px_p, dev_info_t *dip, int mps); 2130114761dSAlan Adamson, SD OSSD 214c0da6274SZhi-Jun Robin Fu /* 215c0da6274SZhi-Jun Robin Fu * Config space access 216c0da6274SZhi-Jun Robin Fu */ 217c0da6274SZhi-Jun Robin Fu extern uint64_t px_lib_get_cfgacc_base(dev_info_t *dip); 218c0da6274SZhi-Jun Robin Fu 219fc256490SJason Beloro /* 220fc256490SJason Beloro * PCI IOV SDIO functions 221fc256490SJason Beloro */ 222fc256490SJason Beloro extern int px_lib_fabric_sync(dev_info_t *dip); 223fc256490SJason Beloro 2247c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate #endif 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate #endif /* _SYS_PX_LIB_H */ 229