155682Smarkm/* $OpenBSD: pci_machdep.h,v 1.5 2024/05/22 05:51:49 jsg Exp $ */ 290926Snectar 355682Smarkm/* 455682Smarkm * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) 555682Smarkm * 655682Smarkm * Redistribution and use in source and binary forms, with or without 755682Smarkm * modification, are permitted provided that the following conditions 855682Smarkm * are met: 955682Smarkm * 1. Redistributions of source code must retain the above copyright 1055682Smarkm * notice, this list of conditions and the following disclaimer. 1155682Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1255682Smarkm * notice, this list of conditions and the following disclaimer in the 1355682Smarkm * documentation and/or other materials provided with the distribution. 1455682Smarkm * 1555682Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 1655682Smarkm * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1755682Smarkm * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1855682Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 1955682Smarkm * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2055682Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2155682Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2255682Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2355682Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2455682Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2555682Smarkm * SUCH DAMAGE. 2655682Smarkm * 2755682Smarkm */ 2855682Smarkm 2955682Smarkmtypedef struct machine_pci_chipset *pci_chipset_tag_t; 3055682Smarkmtypedef uint64_t pcitag_t; 3155682Smarkm 3255682Smarkm#define PCITAG_NODE(x) ((x) >> 32) 3355682Smarkm#define PCITAG_OFFSET(x) ((x) & 0xffffffff) 3455682Smarkm 35102644Snectar/* Supported interrupt types. */ 3655682Smarkm#define PCI_NONE 0 37178825Sdfr#define PCI_INTX 1 3855682Smarkm#define PCI_MSI 2 3955682Smarkm#define PCI_MSIX 3 4055682Smarkm 4155682Smarkmtypedef struct { 4255682Smarkm pci_chipset_tag_t ih_pc; 4355682Smarkm pcitag_t ih_tag; 4455682Smarkm int ih_intrpin; 4555682Smarkm int ih_type; 4655682Smarkm bus_dma_tag_t ih_dmat; 4755682Smarkm} pci_intr_handle_t; 4855682Smarkm 4955682Smarkmstruct pci_attach_args; 5055682Smarkm 5155682Smarkm/* 5255682Smarkm * Machine-specific PCI structure and type definitions. 5355682Smarkm * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. 5455682Smarkm */ 5555682Smarkmstruct machine_pci_chipset { 5655682Smarkm void *pc_conf_v; 5755682Smarkm void (*pc_attach_hook)(struct device *, 5872445Sassar struct device *, struct pcibus_attach_args *); 5955682Smarkm int (*pc_bus_maxdevs)(void *, int); 6055682Smarkm pcitag_t (*pc_make_tag)(void *, int, int, int); 6155682Smarkm void (*pc_decompose_tag)(void *, pcitag_t, int *, 6255682Smarkm int *, int *); 6355682Smarkm int (*pc_conf_size)(void *, pcitag_t); 6455682Smarkm pcireg_t (*pc_conf_read)(void *, pcitag_t, int); 65107207Snectar void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); 66107207Snectar int (*pc_probe_device_hook)(void *, struct pci_attach_args *); 67107207Snectar 6855682Smarkm void *pc_intr_v; 6955682Smarkm int (*pc_intr_map)(struct pci_attach_args *, 7055682Smarkm pci_intr_handle_t *); 7155682Smarkm int (*pc_intr_map_msi)(struct pci_attach_args *, 7255682Smarkm pci_intr_handle_t *); 7355682Smarkm int (*pc_intr_map_msivec)(struct pci_attach_args *, 7455682Smarkm int, pci_intr_handle_t *); 7555682Smarkm int (*pc_intr_map_msix)(struct pci_attach_args *, 7655682Smarkm int, pci_intr_handle_t *); 7755682Smarkm const char *(*pc_intr_string)(void *, pci_intr_handle_t); 7855682Smarkm void *(*pc_intr_establish)(void *, pci_intr_handle_t, 7955682Smarkm int, struct cpu_info *, int (*)(void *), void *, 8055682Smarkm char *); 8155682Smarkm void (*pc_intr_disestablish)(void *, void *); 8255682Smarkm}; 8355682Smarkm 8455682Smarkm/* 8555682Smarkm * Functions provided to machine-independent PCI code. 8655682Smarkm */ 8755682Smarkm#define pci_attach_hook(p, s, pba) \ 8855682Smarkm (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) 8955682Smarkm#define pci_bus_maxdevs(c, b) \ 9055682Smarkm (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) 9155682Smarkm#define pci_make_tag(c, b, d, f) \ 9255682Smarkm (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) 9355682Smarkm#define pci_decompose_tag(c, t, bp, dp, fp) \ 9455682Smarkm (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) 9555682Smarkm#define pci_conf_size(c, t) \ 9655682Smarkm (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) 9755682Smarkm#define pci_conf_read(c, t, r) \ 9855682Smarkm (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) 9955682Smarkm#define pci_conf_write(c, t, r, v) \ 10055682Smarkm (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) 10155682Smarkm#define pci_probe_device_hook(c, a) \ 10255682Smarkm (*(c)->pc_probe_device_hook)((c)->pc_conf_v, (a)) 10355682Smarkm#define pci_intr_map(c, ihp) \ 10455682Smarkm (*(c)->pa_pc->pc_intr_map)((c), (ihp)) 10555682Smarkm#define pci_intr_map_msi(c, ihp) \ 10655682Smarkm (*(c)->pa_pc->pc_intr_map_msi)((c), (ihp)) 10755682Smarkm#define pci_intr_map_msix(c, vec, ihp) \ 10855682Smarkm (*(c)->pa_pc->pc_intr_map_msix)((c), (vec), (ihp)) 10955682Smarkm#define pci_intr_string(c, ih) \ 11090926Snectar (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) 11190926Snectar#define pci_intr_establish(c, ih, l, h, a, nm) \ 11290926Snectar (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), NULL, (h), (a),\ 11355682Smarkm (nm)) 11455682Smarkm#define pci_intr_establish_cpu(c, ih, l, ci, h, a, nm) \ 115178825Sdfr (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (ci), (h), (a),\ 11655682Smarkm (nm)) 11755682Smarkm#define pci_intr_disestablish(c, iv) \ 11855682Smarkm (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) 119178825Sdfr 120178825Sdfr#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) 12155682Smarkm#define pci_set_powerstate_md(c, t, s, p) 122178825Sdfr 123178825Sdfr#define pci_dev_postattach(a, b) 124178825Sdfr 125178825Sdfrvoid pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int); 12655682Smarkm 12755682Smarkmvoid pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, uint32_t); 128102644Snectarvoid pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t, 12955682Smarkm int, bus_addr_t, uint32_t); 13055682Smarkmint _pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); 131178825Sdfrint _pci_intr_map_msivec(struct pci_attach_args *, int, 132178825Sdfr pci_intr_handle_t *); 133178825Sdfrint _pci_intr_map_msix(struct pci_attach_args *, int, pci_intr_handle_t *); 134178825Sdfr 135178825Sdfr#define __HAVE_PCI_MSIX 13655682Smarkm 13755682Smarkmint pci_msix_table_map(pci_chipset_tag_t, pcitag_t, 13855682Smarkm bus_space_tag_t, bus_space_handle_t *); 13955682Smarkmvoid pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, 14055682Smarkm bus_space_tag_t, bus_space_handle_t); 14155682Smarkm