1 /* $NetBSD: pci_machdep.h,v 1.12 2017/04/19 12:58:59 jmcneill Exp $ */ 2 3 /* 4 * Modified for arm32 by Mark Brinicombe 5 * 6 * from: sys/arch/alpha/pci/pci_machdep.h 7 * 8 * Copyright (c) 1996 Carnegie-Mellon University. 9 * All rights reserved. 10 * 11 * Author: Chris G. Demetriou 12 * 13 * Permission to use, copy, modify and distribute this software and 14 * its documentation is hereby granted, provided that both the copyright 15 * notice and this permission notice appear in all copies of the 16 * software, derivative works or modified versions, and any portions 17 * thereof, and that both notices appear in supporting documentation. 18 * 19 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 20 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 21 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 22 * 23 * Carnegie Mellon requests users of this software to return to 24 * 25 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 26 * School of Computer Science 27 * Carnegie Mellon University 28 * Pittsburgh PA 15213-3890 29 * 30 * any improvements or extensions that they make and grant Carnegie the 31 * rights to redistribute these changes. 32 */ 33 34 #ifndef _ARM_PCI_MACHDEP_H_ 35 #define _ARM_PCI_MACHDEP_H_ 36 /* 37 * Machine-specific definitions for PCI autoconfiguration. 38 */ 39 40 #include <sys/errno.h> 41 42 /* 43 * Types provided to machine-independent PCI code 44 */ 45 typedef struct arm32_pci_chipset *pci_chipset_tag_t; 46 typedef u_long pcitag_t; 47 typedef u_long pci_intr_handle_t; 48 49 /* 50 * Forward declarations. 51 */ 52 struct pci_attach_args; 53 54 /* 55 * arm32-specific PCI structure and type definitions. 56 * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. 57 */ 58 struct arm32_pci_chipset { 59 void *pc_conf_v; 60 void (*pc_attach_hook)(device_t, device_t, 61 struct pcibus_attach_args *); 62 int (*pc_bus_maxdevs)(void *, int); 63 pcitag_t (*pc_make_tag)(void *, int, int, int); 64 void (*pc_decompose_tag)(void *, pcitag_t, int *, 65 int *, int *); 66 pcireg_t (*pc_conf_read)(void *, pcitag_t, int); 67 void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); 68 69 void *pc_intr_v; 70 int (*pc_intr_map)(const struct pci_attach_args *, 71 pci_intr_handle_t *); 72 const char *(*pc_intr_string)(void *, pci_intr_handle_t, 73 char *, size_t); 74 const struct evcnt *(*pc_intr_evcnt)(void *, pci_intr_handle_t); 75 int (*pc_intr_setattr)(void *, pci_intr_handle_t *, 76 int, uint64_t); 77 void *(*pc_intr_establish)(void *, pci_intr_handle_t, 78 int, int (*)(void *), void *); 79 void (*pc_intr_disestablish)(void *, void *); 80 81 #ifdef __HAVE_PCI_CONF_HOOK 82 int (*pc_conf_hook)(void *, int, int, int, pcireg_t); 83 #endif 84 void (*pc_conf_interrupt)(void *, int, int, int, int, int *); 85 86 uint32_t pc_cfg_cmd; 87 }; 88 89 /* 90 * Functions provided to machine-independent PCI code. 91 */ 92 #define pci_attach_hook(p, s, pba) \ 93 (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) 94 #define pci_bus_maxdevs(c, b) \ 95 (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) 96 #define pci_make_tag(c, b, d, f) \ 97 (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) 98 #define pci_decompose_tag(c, t, bp, dp, fp) \ 99 (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) 100 #define pci_conf_read(c, t, r) \ 101 (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) 102 #define pci_conf_write(c, t, r, v) \ 103 (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) 104 #define pci_intr_map(pa, ihp) \ 105 (*(pa)->pa_pc->pc_intr_map)((pa), (ihp)) 106 #define pci_intr_string(c, ih, buf, len) \ 107 (*(c)->pc_intr_string)((c)->pc_intr_v, (ih), (buf), (len)) 108 #define pci_intr_evcnt(c, ih) \ 109 (*(c)->pc_intr_evcnt)((c)->pc_intr_v, (ih)) 110 #define pci_intr_establish(c, ih, l, h, a) \ 111 (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a)) 112 #define pci_intr_disestablish(c, iv) \ 113 (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) 114 #ifdef __HAVE_PCI_CONF_HOOK 115 #define pci_conf_hook(c, b, d, f, id) \ 116 (*(c)->pc_conf_hook)((c)->pc_conf_v, (b), (d), (f), (id)) 117 #endif 118 #define pci_conf_interrupt(c, b, d, i, s, p) \ 119 (*(c)->pc_conf_interrupt)((c)->pc_conf_v, (b), (d), (i), (s), (p)) 120 121 static inline int 122 pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ihp, 123 int attr, uint64_t data) 124 { 125 if (!pc->pc_intr_setattr) 126 return ENODEV; 127 return pc->pc_intr_setattr(pc, ihp, attr, data); 128 } 129 130 #endif /* _ARM_PCI_MACHDEP_H_ */ 131