1*1d9e937eSjmatthew /* $OpenBSD: pci_machdep.h,v 1.38 2020/06/23 01:21:29 jmatthew Exp $ */ 2284584b0Sjason /* $NetBSD: pci_machdep.h,v 1.7 2001/07/20 00:07:14 eeh Exp $ */ 3284584b0Sjason 4284584b0Sjason /* 5284584b0Sjason * Copyright (c) 1999 Matthew R. Green 6284584b0Sjason * All rights reserved. 7284584b0Sjason * 8284584b0Sjason * Redistribution and use in source and binary forms, with or without 9284584b0Sjason * modification, are permitted provided that the following conditions 10284584b0Sjason * are met: 11284584b0Sjason * 1. Redistributions of source code must retain the above copyright 12284584b0Sjason * notice, this list of conditions and the following disclaimer. 13284584b0Sjason * 2. Redistributions in binary form must reproduce the above copyright 14284584b0Sjason * notice, this list of conditions and the following disclaimer in the 15284584b0Sjason * documentation and/or other materials provided with the distribution. 16284584b0Sjason * 17284584b0Sjason * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18284584b0Sjason * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19284584b0Sjason * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20284584b0Sjason * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21284584b0Sjason * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 22284584b0Sjason * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23284584b0Sjason * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 24284584b0Sjason * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25284584b0Sjason * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26284584b0Sjason * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27284584b0Sjason * SUCH DAMAGE. 28284584b0Sjason */ 29284584b0Sjason 30284584b0Sjason #ifndef _MACHINE_PCI_MACHDEP_H_ 31284584b0Sjason #define _MACHINE_PCI_MACHDEP_H_ 32284584b0Sjason 33284584b0Sjason /* 34284584b0Sjason * Forward declarations. 35284584b0Sjason */ 36284584b0Sjason struct pci_attach_args; 37284584b0Sjason 38284584b0Sjason /* 39284584b0Sjason * define some bits used to glue into the common PCI code. 40284584b0Sjason */ 41284584b0Sjason 425d528514Sdlg #define __HAVE_PCI_MSIX 435d528514Sdlg 44284584b0Sjason typedef struct sparc_pci_chipset *pci_chipset_tag_t; 45660a900dSkettenis 462762bfbcSdlg #define PCI_INTR_INTX 0x00000000 47660a900dSkettenis #define PCI_INTR_MSI 0x80000000 482762bfbcSdlg #define PCI_INTR_MSIX 0x40000000 492762bfbcSdlg #define PCI_INTR_TYPE_MASK 0xc0000000 502762bfbcSdlg #define PCI_INTR_TYPE(_ih) ((_ih) & PCI_INTR_TYPE_MASK) 512762bfbcSdlg 522762bfbcSdlg #define PCI_INTR_TAG_MASK 0x00ffff00 532762bfbcSdlg #define PCI_INTR_TAG(_ih) ((_ih) & PCI_INTR_TAG_MASK) 542762bfbcSdlg 552762bfbcSdlg #define PCI_INTR_VEC_MASK 0x000000ff 562762bfbcSdlg #define PCI_INTR_VEC(_ih) ((_ih) & PCI_INTR_VEC_MASK) 57284584b0Sjason typedef u_int pci_intr_handle_t; 58284584b0Sjason 59284584b0Sjason /* 60284584b0Sjason * The stuuuuuuupid allegedly MI PCI code expects pcitag_t to be a 61284584b0Sjason * scalar type. But we really need to store both the OFW node and 62284584b0Sjason * the bus/device/function info in it. (We'd like to store more, 63284584b0Sjason * like all the ofw properties, but we don't need to.) Luckily, 64284584b0Sjason * both are 32-bit values, so we can squeeze them into a u_int64_t 65284584b0Sjason * with a little help from some macros. 66284584b0Sjason */ 67284584b0Sjason 68284584b0Sjason #define PCITAG_NODE(x) (int)(((x)>>32)&0xffffffff) 69284584b0Sjason #define PCITAG_OFFSET(x) ((x)&0xffffffff) 705878c5d1Sbrad #define PCITAG_BUS(t) ((PCITAG_OFFSET(t)>>16)&0xff) 715878c5d1Sbrad #define PCITAG_DEV(t) ((PCITAG_OFFSET(t)>>11)&0x1f) 725878c5d1Sbrad #define PCITAG_FUN(t) ((PCITAG_OFFSET(t)>>8)&0x7) 73284584b0Sjason #define PCITAG_CREATE(n,b,d,f) (((u_int64_t)(n)<<32)|((b)<<16)|((d)<<11)|((f)<<8)) 74c2a5732fSjason #define PCITAG_SETNODE(t,n) ((t)&0xffffffff)|(((n)<<32) 75284584b0Sjason typedef u_int64_t pcitag_t; 76284584b0Sjason 777c86621aSjason struct sparc_pci_chipset { 78af6c180eSkettenis void *cookie; 79eb79e960Shenric bus_space_tag_t bustag; 80eb79e960Shenric bus_space_handle_t bushandle; 817c86621aSjason int rootnode; /* PCI controller */ 82da61497cSkettenis int busnode[256]; 83b1926db3Smiod int (*conf_size)(pci_chipset_tag_t, pcitag_t); 84ec0fe246Skettenis pcireg_t (*conf_read)(pci_chipset_tag_t, pcitag_t, int); 85ec0fe246Skettenis void (*conf_write)(pci_chipset_tag_t, pcitag_t, int, pcireg_t); 8640113d06Shenric int (*intr_map)(struct pci_attach_args *, pci_intr_handle_t *); 87630edadfSdlg int (*probe_device_hook)(void *, struct pci_attach_args *); 887c86621aSjason }; 89284584b0Sjason 90284584b0Sjason void pci_attach_hook(struct device *, struct device *, 91284584b0Sjason struct pcibus_attach_args *); 92630edadfSdlg int pci_probe_device_hook(pci_chipset_tag_t, 93630edadfSdlg struct pci_attach_args *); 94284584b0Sjason int pci_bus_maxdevs(pci_chipset_tag_t, int); 95284584b0Sjason pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int); 965878c5d1Sbrad void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, int *, int *, 975878c5d1Sbrad int *); 98b1926db3Smiod int pci_conf_size(pci_chipset_tag_t, pcitag_t); 99284584b0Sjason pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); 100284584b0Sjason void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, 101284584b0Sjason pcireg_t); 102fd725315Sart int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); 103660a900dSkettenis int pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); 1042762bfbcSdlg int pci_intr_map_msix(struct pci_attach_args *, int, 1052762bfbcSdlg pci_intr_handle_t *); 1061242d4e7Smiod int pci_intr_line(pci_chipset_tag_t, pci_intr_handle_t); 107284584b0Sjason const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); 108284584b0Sjason void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, 109c03b1b92Smk int, int (*)(void *), void *, const char *); 110*1d9e937eSjmatthew void *pci_intr_establish_cpu(pci_chipset_tag_t, pci_intr_handle_t, 111*1d9e937eSjmatthew int, struct cpu_info *, 112*1d9e937eSjmatthew int (*)(void *), void *, const char *); 113284584b0Sjason void pci_intr_disestablish(pci_chipset_tag_t, void *); 114284584b0Sjason 1152f32ec67Skettenis void pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, int); 1162762bfbcSdlg void pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t, 1172762bfbcSdlg int, bus_addr_t, uint32_t); 1185d528514Sdlg int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, 1195d528514Sdlg bus_space_tag_t, bus_space_handle_t *); 1205d528514Sdlg void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, 1215d528514Sdlg bus_space_tag_t, bus_space_handle_t); 1222f32ec67Skettenis 123ae08a99dSbrad int sparc64_pci_enumerate_bus(struct pci_softc *, 124ae08a99dSbrad int (*match)(struct pci_attach_args *), 125ae08a99dSbrad struct pci_attach_args *); 126ae08a99dSbrad 127ae08a99dSbrad #define PCI_MACHDEP_ENUMERATE_BUS sparc64_pci_enumerate_bus 128ae08a99dSbrad 1298800c0adSkettenis #define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) 13025b7ac45Smpi #define pci_set_powerstate_md(c, t, s, p) 1318800c0adSkettenis 13295740af1Sart #define pciide_machdep_compat_intr_establish(a, b, c, d, e) (NULL) 13395740af1Sart #define pciide_machdep_compat_intr_disestablish(a, b) do { } while (0) 13495740af1Sart 135ea14b1d7Sjordan #define pci_dev_postattach(a, b) 136ea14b1d7Sjordan 137284584b0Sjason #endif /* _MACHINE_PCI_MACHDEP_H_ */ 138