1*eb3d9e2dSkettenis /* $OpenBSD: pci_machdep.h,v 1.32 2025/01/23 11:24:34 kettenis Exp $ */ 2f5df1827Smickey /* $NetBSD: pci_machdep.h,v 1.1 2003/02/26 21:26:11 fvdl Exp $ */ 3f5df1827Smickey 4f5df1827Smickey /* 5f5df1827Smickey * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 6f5df1827Smickey * Copyright (c) 1994 Charles M. Hannum. All rights reserved. 7f5df1827Smickey * 8f5df1827Smickey * Redistribution and use in source and binary forms, with or without 9f5df1827Smickey * modification, are permitted provided that the following conditions 10f5df1827Smickey * are met: 11f5df1827Smickey * 1. Redistributions of source code must retain the above copyright 12f5df1827Smickey * notice, this list of conditions and the following disclaimer. 13f5df1827Smickey * 2. Redistributions in binary form must reproduce the above copyright 14f5df1827Smickey * notice, this list of conditions and the following disclaimer in the 15f5df1827Smickey * documentation and/or other materials provided with the distribution. 16f5df1827Smickey * 3. All advertising materials mentioning features or use of this software 17f5df1827Smickey * must display the following acknowledgement: 18f5df1827Smickey * This product includes software developed by Charles M. Hannum. 19f5df1827Smickey * 4. The name of the author may not be used to endorse or promote products 20f5df1827Smickey * derived from this software without specific prior written permission. 21f5df1827Smickey * 22f5df1827Smickey * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23f5df1827Smickey * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24f5df1827Smickey * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25f5df1827Smickey * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26f5df1827Smickey * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27f5df1827Smickey * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28f5df1827Smickey * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29f5df1827Smickey * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30f5df1827Smickey * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31f5df1827Smickey * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32f5df1827Smickey */ 33f5df1827Smickey 34f5df1827Smickey /* 35f5df1827Smickey * Machine-specific definitions for PCI autoconfiguration. 36f5df1827Smickey */ 37f5df1827Smickey 38f5df1827Smickey /* 39cdb1eb42Skettenis * amd64-specific PCI structure and type definitions. 40f5df1827Smickey * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. 41f5df1827Smickey */ 42f5df1827Smickey 4313fad3d0Soga extern struct bus_dma_tag pci_bus_dma_tag; 44f5df1827Smickey 45f5df1827Smickey /* 46f5df1827Smickey * Types provided to machine-independent PCI code 47f5df1827Smickey */ 48f5df1827Smickey typedef void *pci_chipset_tag_t; 49cdb1eb42Skettenis typedef u_int32_t pcitag_t; 50f5df1827Smickey 51adb2a0aeSkettenis typedef struct { 52adb2a0aeSkettenis pcitag_t tag; 53adb2a0aeSkettenis int line, pin; 54adb2a0aeSkettenis } pci_intr_handle_t; 55adb2a0aeSkettenis 561242d4e7Smiod #define pci_intr_line(pc,ih) ((ih.line) & 0xff) 5769803f82Stdeval 58f5df1827Smickey /* 59cdb1eb42Skettenis * amd64-specific PCI variables and functions. 60f5df1827Smickey * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. 61f5df1827Smickey */ 62f5df1827Smickey struct pci_attach_args; 63f5df1827Smickey 64ea9b3ec9Skettenis extern struct extent *pciio_ex; 65ea9b3ec9Skettenis extern struct extent *pcimem_ex; 660371ddceSkettenis extern struct extent *pcibus_ex; 67ea9b3ec9Skettenis void pci_init_extents(void); 68ea9b3ec9Skettenis 69f5df1827Smickey /* 70f5df1827Smickey * Functions provided to machine-independent PCI code. 71f5df1827Smickey */ 72f5df1827Smickey void pci_attach_hook(struct device *, struct device *, 73f5df1827Smickey struct pcibus_attach_args *); 74f5df1827Smickey int pci_bus_maxdevs(pci_chipset_tag_t, int); 75f5df1827Smickey pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int); 76f5df1827Smickey void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, 77f5df1827Smickey int *, int *, int *); 78b1926db3Smiod int pci_conf_size(pci_chipset_tag_t, pcitag_t); 79f5df1827Smickey pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); 80f5df1827Smickey void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, 81f5df1827Smickey pcireg_t); 82fb432fadSkettenis int pci_intr_enable_msivec(struct pci_attach_args *, int); 83058ea912Skettenis int pci_intr_map_msi(struct pci_attach_args *, 84058ea912Skettenis pci_intr_handle_t *); 85fb432fadSkettenis int pci_intr_map_msivec(struct pci_attach_args *, 86fb432fadSkettenis int, pci_intr_handle_t *); 87058ea912Skettenis int pci_intr_map_msix(struct pci_attach_args *, 88058ea912Skettenis int, pci_intr_handle_t *); 89f5df1827Smickey int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); 90f5df1827Smickey const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); 91992e7aa6Stedu void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, 92c03b1b92Smk int, int (*)(void *), void *, const char *); 9315db3095Sdlg void *pci_intr_establish_cpu(pci_chipset_tag_t, pci_intr_handle_t, 9415db3095Sdlg int, struct cpu_info *, 9515db3095Sdlg int (*)(void *), void *, const char *); 96f5df1827Smickey void pci_intr_disestablish(pci_chipset_tag_t, void *); 9796940271Sjordan int pci_probe_device_hook(pci_chipset_tag_t, 9896940271Sjordan struct pci_attach_args *); 99f5df1827Smickey 100ea14b1d7Sjordan void pci_dev_postattach(struct device *, struct pci_attach_args *); 101ea14b1d7Sjordan 1022d67ff8fSkettenis pcireg_t pci_min_powerstate(pci_chipset_tag_t, pcitag_t); 103b08441edSmpi void pci_set_powerstate_md(pci_chipset_tag_t, pcitag_t, int, int); 1042d67ff8fSkettenis 105d6a1c66eSkettenis void pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int); 106*eb3d9e2dSkettenis pci_chipset_tag_t pci_lookup_segment(int, int); 1072c626a9bSkettenis 1084211e504Skettenis #define __HAVE_PCI_MSIX 1094211e504Skettenis 1104211e504Skettenis int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, 1114211e504Skettenis bus_space_tag_t, bus_space_handle_t *); 1124211e504Skettenis void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, 1134211e504Skettenis bus_space_tag_t, bus_space_handle_t); 1144211e504Skettenis 115f5df1827Smickey /* 116f5df1827Smickey * ALL OF THE FOLLOWING ARE MACHINE-DEPENDENT, AND SHOULD NOT BE USED 117f5df1827Smickey * BY PORTABLE CODE. 118f5df1827Smickey */ 119f5df1827Smickey 120f5df1827Smickey /* 121f5df1827Smickey * Section 6.2.4, `Miscellaneous Functions' of the PCI Specification, 122f5df1827Smickey * says that 255 means `unknown' or `no connection' to the interrupt 123f5df1827Smickey * controller on a PC. 124f5df1827Smickey */ 125f5df1827Smickey #define X86_PCI_INTERRUPT_LINE_NO_CONNECTION 0xff 126098c780cSkettenis 127098c780cSkettenis /* 128098c780cSkettenis * PCI address space is shared with ISA, so avoid legacy ISA I/O 129098c780cSkettenis * registers. 130098c780cSkettenis */ 131098c780cSkettenis #define PCI_IO_START 0x400 132098c780cSkettenis #define PCI_IO_END 0xffff 133b39e9e2cSkettenis 134b39e9e2cSkettenis /* 135b39e9e2cSkettenis * Avoid the DOS Compatibility Memory area. 136b39e9e2cSkettenis */ 137b39e9e2cSkettenis #define PCI_MEM_START 0x100000 138