1 1.18 jmcneill /* $NetBSD: pci_machdep.h,v 1.18 2020/02/13 00:02:21 jmcneill Exp $ */ 2 1.1 reinoud 3 1.1 reinoud /* 4 1.1 reinoud * Modified for arm32 by Mark Brinicombe 5 1.1 reinoud * 6 1.1 reinoud * from: sys/arch/alpha/pci/pci_machdep.h 7 1.1 reinoud * 8 1.1 reinoud * Copyright (c) 1996 Carnegie-Mellon University. 9 1.1 reinoud * All rights reserved. 10 1.1 reinoud * 11 1.1 reinoud * Author: Chris G. Demetriou 12 1.1 reinoud * 13 1.1 reinoud * Permission to use, copy, modify and distribute this software and 14 1.1 reinoud * its documentation is hereby granted, provided that both the copyright 15 1.1 reinoud * notice and this permission notice appear in all copies of the 16 1.1 reinoud * software, derivative works or modified versions, and any portions 17 1.1 reinoud * thereof, and that both notices appear in supporting documentation. 18 1.1 reinoud * 19 1.1 reinoud * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 20 1.1 reinoud * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 21 1.1 reinoud * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 22 1.1 reinoud * 23 1.1 reinoud * Carnegie Mellon requests users of this software to return to 24 1.1 reinoud * 25 1.1 reinoud * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU 26 1.1 reinoud * School of Computer Science 27 1.1 reinoud * Carnegie Mellon University 28 1.1 reinoud * Pittsburgh PA 15213-3890 29 1.1 reinoud * 30 1.1 reinoud * any improvements or extensions that they make and grant Carnegie the 31 1.1 reinoud * rights to redistribute these changes. 32 1.1 reinoud */ 33 1.1 reinoud 34 1.5 kiyohara #ifndef _ARM_PCI_MACHDEP_H_ 35 1.5 kiyohara #define _ARM_PCI_MACHDEP_H_ 36 1.1 reinoud /* 37 1.1 reinoud * Machine-specific definitions for PCI autoconfiguration. 38 1.1 reinoud */ 39 1.1 reinoud 40 1.13 jmcneill #ifdef __aarch64__ 41 1.13 jmcneill #define _PCI_HAVE_DMA64 42 1.13 jmcneill #endif 43 1.13 jmcneill 44 1.15 jmcneill #define __HAVE_PCI_GET_SEGMENT 45 1.15 jmcneill 46 1.12 jmcneill #include <sys/errno.h> 47 1.12 jmcneill 48 1.1 reinoud /* 49 1.1 reinoud * Types provided to machine-independent PCI code 50 1.1 reinoud */ 51 1.1 reinoud typedef struct arm32_pci_chipset *pci_chipset_tag_t; 52 1.1 reinoud typedef u_long pcitag_t; 53 1.14 jmcneill typedef uint64_t pci_intr_handle_t; 54 1.14 jmcneill 55 1.14 jmcneill /* 56 1.14 jmcneill * pci_intr_handle_t fields 57 1.14 jmcneill */ 58 1.14 jmcneill #define ARM_PCI_INTR_MSI_VEC 0x000007ff00000000ULL 59 1.14 jmcneill #define ARM_PCI_INTR_MPSAFE 0x0000000080000000ULL 60 1.14 jmcneill #define ARM_PCI_INTR_MSIX 0x0000000040000000ULL 61 1.14 jmcneill #define ARM_PCI_INTR_MSI 0x0000000020000000ULL 62 1.14 jmcneill #define ARM_PCI_INTR_FRAME 0x0000000000ff0000ULL 63 1.14 jmcneill #define ARM_PCI_INTR_IRQ 0x000000000000ffffULL 64 1.14 jmcneill 65 1.14 jmcneill #ifdef __HAVE_PCI_MSI_MSIX 66 1.14 jmcneill /* 67 1.14 jmcneill * PCI MSI/MSI-X support 68 1.14 jmcneill */ 69 1.14 jmcneill typedef enum { 70 1.14 jmcneill PCI_INTR_TYPE_INTX = 0, 71 1.14 jmcneill PCI_INTR_TYPE_MSI, 72 1.14 jmcneill PCI_INTR_TYPE_MSIX, 73 1.14 jmcneill PCI_INTR_TYPE_SIZE, 74 1.14 jmcneill } pci_intr_type_t; 75 1.14 jmcneill #endif /* __HAVE_PCI_MSI_MSIX */ 76 1.1 reinoud 77 1.1 reinoud /* 78 1.1 reinoud * Forward declarations. 79 1.1 reinoud */ 80 1.1 reinoud struct pci_attach_args; 81 1.1 reinoud 82 1.1 reinoud /* 83 1.1 reinoud * arm32-specific PCI structure and type definitions. 84 1.1 reinoud * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. 85 1.1 reinoud */ 86 1.1 reinoud struct arm32_pci_chipset { 87 1.1 reinoud void *pc_conf_v; 88 1.8 matt void (*pc_attach_hook)(device_t, device_t, 89 1.8 matt struct pcibus_attach_args *); 90 1.1 reinoud int (*pc_bus_maxdevs)(void *, int); 91 1.1 reinoud pcitag_t (*pc_make_tag)(void *, int, int, int); 92 1.1 reinoud void (*pc_decompose_tag)(void *, pcitag_t, int *, 93 1.1 reinoud int *, int *); 94 1.15 jmcneill u_int (*pc_get_segment)(void *); 95 1.17 jmcneill uint32_t (*pc_get_devid)(void *, uint32_t); 96 1.18 jmcneill uint32_t (*pc_get_frameid)(void *, uint32_t); 97 1.1 reinoud pcireg_t (*pc_conf_read)(void *, pcitag_t, int); 98 1.1 reinoud void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); 99 1.1 reinoud 100 1.1 reinoud void *pc_intr_v; 101 1.7 dyoung int (*pc_intr_map)(const struct pci_attach_args *, 102 1.1 reinoud pci_intr_handle_t *); 103 1.10 christos const char *(*pc_intr_string)(void *, pci_intr_handle_t, 104 1.10 christos char *, size_t); 105 1.1 reinoud const struct evcnt *(*pc_intr_evcnt)(void *, pci_intr_handle_t); 106 1.11 jmcneill int (*pc_intr_setattr)(void *, pci_intr_handle_t *, 107 1.11 jmcneill int, uint64_t); 108 1.1 reinoud void *(*pc_intr_establish)(void *, pci_intr_handle_t, 109 1.16 jmcneill int, int (*)(void *), void *, const char *); 110 1.1 reinoud void (*pc_intr_disestablish)(void *, void *); 111 1.6 matt 112 1.6 matt #ifdef __HAVE_PCI_CONF_HOOK 113 1.9 matt int (*pc_conf_hook)(void *, int, int, int, pcireg_t); 114 1.6 matt #endif 115 1.9 matt void (*pc_conf_interrupt)(void *, int, int, int, int, int *); 116 1.6 matt 117 1.14 jmcneill #ifdef __HAVE_PCI_MSI_MSIX 118 1.14 jmcneill void *pc_msi_v; 119 1.14 jmcneill pci_intr_type_t (*pc_intr_type)(void *, pci_intr_handle_t); 120 1.14 jmcneill int (*pc_intr_alloc)(const struct pci_attach_args *, 121 1.14 jmcneill pci_intr_handle_t **, int *, pci_intr_type_t); 122 1.14 jmcneill void (*pc_intr_release)(void *, pci_intr_handle_t *, int); 123 1.14 jmcneill int (*pc_intx_alloc)(const struct pci_attach_args *, 124 1.14 jmcneill pci_intr_handle_t **); 125 1.14 jmcneill int (*pc_msi_alloc)(const struct pci_attach_args *, 126 1.14 jmcneill pci_intr_handle_t **, int *); 127 1.14 jmcneill int (*pc_msi_alloc_exact)(const struct pci_attach_args *, 128 1.14 jmcneill pci_intr_handle_t **, int); 129 1.14 jmcneill int (*pc_msix_alloc)(const struct pci_attach_args *, 130 1.14 jmcneill pci_intr_handle_t **, int *); 131 1.14 jmcneill int (*pc_msix_alloc_exact)(const struct pci_attach_args *, 132 1.14 jmcneill pci_intr_handle_t **, int); 133 1.14 jmcneill int (*pc_msix_alloc_map)(const struct pci_attach_args *, 134 1.14 jmcneill pci_intr_handle_t **, u_int *, int); 135 1.14 jmcneill #endif 136 1.14 jmcneill 137 1.6 matt uint32_t pc_cfg_cmd; 138 1.1 reinoud }; 139 1.1 reinoud 140 1.1 reinoud /* 141 1.1 reinoud * Functions provided to machine-independent PCI code. 142 1.1 reinoud */ 143 1.1 reinoud #define pci_attach_hook(p, s, pba) \ 144 1.1 reinoud (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) 145 1.1 reinoud #define pci_bus_maxdevs(c, b) \ 146 1.1 reinoud (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) 147 1.1 reinoud #define pci_make_tag(c, b, d, f) \ 148 1.1 reinoud (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) 149 1.1 reinoud #define pci_decompose_tag(c, t, bp, dp, fp) \ 150 1.1 reinoud (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) 151 1.15 jmcneill #define pci_get_segment(c) \ 152 1.15 jmcneill ((c)->pc_get_segment ? (*(c)->pc_get_segment)((c)->pc_conf_v) : 0) 153 1.17 jmcneill #define pci_get_devid(c, d) \ 154 1.17 jmcneill ((c)->pc_get_devid ? (*(c)->pc_get_devid)((c)->pc_conf_v, (d)) : (d)) 155 1.18 jmcneill #define pci_get_frameid(c, d) \ 156 1.18 jmcneill ((c)->pc_get_frameid ? (*(c)->pc_get_frameid)((c)->pc_conf_v, (d)) : 0) 157 1.1 reinoud #define pci_conf_read(c, t, r) \ 158 1.1 reinoud (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) 159 1.1 reinoud #define pci_conf_write(c, t, r, v) \ 160 1.1 reinoud (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) 161 1.1 reinoud #define pci_intr_map(pa, ihp) \ 162 1.1 reinoud (*(pa)->pa_pc->pc_intr_map)((pa), (ihp)) 163 1.10 christos #define pci_intr_string(c, ih, buf, len) \ 164 1.10 christos (*(c)->pc_intr_string)((c)->pc_intr_v, (ih), (buf), (len)) 165 1.1 reinoud #define pci_intr_evcnt(c, ih) \ 166 1.1 reinoud (*(c)->pc_intr_evcnt)((c)->pc_intr_v, (ih)) 167 1.1 reinoud #define pci_intr_establish(c, ih, l, h, a) \ 168 1.16 jmcneill (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a), NULL) 169 1.1 reinoud #define pci_intr_disestablish(c, iv) \ 170 1.1 reinoud (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) 171 1.6 matt #ifdef __HAVE_PCI_CONF_HOOK 172 1.6 matt #define pci_conf_hook(c, b, d, f, id) \ 173 1.9 matt (*(c)->pc_conf_hook)((c)->pc_conf_v, (b), (d), (f), (id)) 174 1.6 matt #endif 175 1.9 matt #define pci_conf_interrupt(c, b, d, i, s, p) \ 176 1.9 matt (*(c)->pc_conf_interrupt)((c)->pc_conf_v, (b), (d), (i), (s), (p)) 177 1.5 kiyohara 178 1.12 jmcneill static inline int 179 1.12 jmcneill pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ihp, 180 1.12 jmcneill int attr, uint64_t data) 181 1.12 jmcneill { 182 1.12 jmcneill if (!pc->pc_intr_setattr) 183 1.12 jmcneill return ENODEV; 184 1.12 jmcneill return pc->pc_intr_setattr(pc, ihp, attr, data); 185 1.12 jmcneill } 186 1.12 jmcneill 187 1.16 jmcneill static inline void * 188 1.16 jmcneill pci_intr_establish_xname(pci_chipset_tag_t pc, pci_intr_handle_t ih, 189 1.16 jmcneill int level, int (*func)(void *), void *arg, const char *xname) 190 1.16 jmcneill { 191 1.16 jmcneill return pc->pc_intr_establish(pc->pc_intr_v, ih, level, func, arg, xname); 192 1.16 jmcneill } 193 1.16 jmcneill 194 1.14 jmcneill #ifdef __HAVE_PCI_MSI_MSIX 195 1.14 jmcneill pci_intr_type_t pci_intr_type(pci_chipset_tag_t, pci_intr_handle_t); 196 1.14 jmcneill int pci_intr_alloc(const struct pci_attach_args *, pci_intr_handle_t **, 197 1.14 jmcneill int *, pci_intr_type_t); 198 1.14 jmcneill void pci_intr_release(pci_chipset_tag_t, pci_intr_handle_t *, int); 199 1.14 jmcneill int pci_intx_alloc(const struct pci_attach_args *, pci_intr_handle_t **); 200 1.14 jmcneill int pci_msi_alloc(const struct pci_attach_args *, pci_intr_handle_t **, 201 1.14 jmcneill int *); 202 1.14 jmcneill int pci_msi_alloc_exact(const struct pci_attach_args *, 203 1.14 jmcneill pci_intr_handle_t **, int); 204 1.14 jmcneill int pci_msix_alloc(const struct pci_attach_args *, pci_intr_handle_t **, 205 1.14 jmcneill int *); 206 1.14 jmcneill int pci_msix_alloc_exact(const struct pci_attach_args *, 207 1.14 jmcneill pci_intr_handle_t **, int); 208 1.14 jmcneill int pci_msix_alloc_map(const struct pci_attach_args *, pci_intr_handle_t **, 209 1.14 jmcneill u_int *, int); 210 1.14 jmcneill #endif /* __HAVE_PCI_MSI_MSIX */ 211 1.14 jmcneill 212 1.5 kiyohara #endif /* _ARM_PCI_MACHDEP_H_ */ 213