1 /* $OpenBSD: pci_machdep.h,v 1.32 2013/11/05 10:12:35 mpi Exp $ */ 2 /* $NetBSD: pci_machdep.h,v 1.7 2001/07/20 00:07:14 eeh Exp $ */ 3 4 /* 5 * Copyright (c) 1999 Matthew R. Green 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 #ifndef _MACHINE_PCI_MACHDEP_H_ 33 #define _MACHINE_PCI_MACHDEP_H_ 34 35 /* 36 * Forward declarations. 37 */ 38 struct pci_attach_args; 39 40 /* 41 * define some bits used to glue into the common PCI code. 42 */ 43 44 typedef struct sparc_pci_chipset *pci_chipset_tag_t; 45 46 #define PCI_INTR_MSI 0x80000000 47 typedef u_int pci_intr_handle_t; 48 49 /* 50 * The stuuuuuuupid allegedly MI PCI code expects pcitag_t to be a 51 * scalar type. But we really need to store both the OFW node and 52 * the bus/device/function info in it. (We'd like to store more, 53 * like all the ofw properties, but we don't need to.) Luckily, 54 * both are 32-bit values, so we can squeeze them into a u_int64_t 55 * with a little help from some macros. 56 */ 57 58 #define PCITAG_NODE(x) (int)(((x)>>32)&0xffffffff) 59 #define PCITAG_OFFSET(x) ((x)&0xffffffff) 60 #define PCITAG_BUS(t) ((PCITAG_OFFSET(t)>>16)&0xff) 61 #define PCITAG_DEV(t) ((PCITAG_OFFSET(t)>>11)&0x1f) 62 #define PCITAG_FUN(t) ((PCITAG_OFFSET(t)>>8)&0x7) 63 #define PCITAG_CREATE(n,b,d,f) (((u_int64_t)(n)<<32)|((b)<<16)|((d)<<11)|((f)<<8)) 64 #define PCITAG_SETNODE(t,n) ((t)&0xffffffff)|(((n)<<32) 65 typedef u_int64_t pcitag_t; 66 67 struct sparc_pci_chipset { 68 void *cookie; 69 bus_space_tag_t bustag; 70 bus_space_handle_t bushandle; 71 int rootnode; /* PCI controller */ 72 int busnode[256]; 73 int (*conf_size)(pci_chipset_tag_t, pcitag_t); 74 pcireg_t (*conf_read)(pci_chipset_tag_t, pcitag_t, int); 75 void (*conf_write)(pci_chipset_tag_t, pcitag_t, int, pcireg_t); 76 int (*intr_map)(struct pci_attach_args *, pci_intr_handle_t *); 77 }; 78 79 void pci_attach_hook(struct device *, struct device *, 80 struct pcibus_attach_args *); 81 int pci_bus_maxdevs(pci_chipset_tag_t, int); 82 pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int); 83 void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, int *, int *, 84 int *); 85 int pci_conf_size(pci_chipset_tag_t, pcitag_t); 86 pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); 87 void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, 88 pcireg_t); 89 int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); 90 int pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); 91 int pci_intr_line(pci_chipset_tag_t, pci_intr_handle_t); 92 const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); 93 void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, 94 int, int (*)(void *), void *, const char *); 95 void pci_intr_disestablish(pci_chipset_tag_t, void *); 96 97 void pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, int); 98 99 int sparc64_pci_enumerate_bus(struct pci_softc *, 100 int (*match)(struct pci_attach_args *), 101 struct pci_attach_args *); 102 103 #define PCI_MACHDEP_ENUMERATE_BUS sparc64_pci_enumerate_bus 104 105 #define pci_probe_device_hook(c, a) (0) 106 107 #define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) 108 #define pci_set_powerstate_md(c, t, s, p) 109 110 #define pciide_machdep_compat_intr_establish(a, b, c, d, e) (NULL) 111 #define pciide_machdep_compat_intr_disestablish(a, b) do { } while (0) 112 113 #define pci_dev_postattach(a, b) 114 115 #endif /* _MACHINE_PCI_MACHDEP_H_ */ 116