1 /* $OpenBSD: pci_machdep.h,v 1.2 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 extern struct powerpc_bus_dma_tag pci_bus_dma_tag; 36 37 /* 38 * Forward declarations. 39 */ 40 struct pci_attach_args; 41 42 /* 43 * define some bits used to glue into the common PCI code. 44 */ 45 46 typedef struct ppc_pci_chipset *pci_chipset_tag_t; 47 48 typedef unsigned long pci_intr_handle_t; 49 50 /* 51 * The stuuuuuuupid allegedly MI PCI code expects pcitag_t to be a 52 * scalar type. But we really need to store both the OFW node and 53 * the bus/device/function info in it. (We'd like to store more, 54 * like all the ofw properties, but we don't need to.) Luckily, 55 * both are 32-bit values, so we can squeeze them into a u_int64_t 56 * with a little help from some macros. 57 */ 58 59 #define PCITAG_NODE(x) (int)(((x)>>32)&0xffffffff) 60 #define PCITAG_OFFSET(x) ((x)&0xffffffff) 61 #define PCITAG_BUS(t) ((PCITAG_OFFSET(t)>>16)&0xff) 62 #define PCITAG_DEV(t) ((PCITAG_OFFSET(t)>>11)&0x1f) 63 #define PCITAG_FUN(t) ((PCITAG_OFFSET(t)>>8)&0x7) 64 #define PCITAG_CREATE(n,b,d,f) (((uint64_t)(n)<<32)|((b)<<16)|((d)<<11)|((f)<<8)) 65 typedef uint64_t pcitag_t; 66 67 struct ppc_pci_chipset { 68 void *pc_conf_v; 69 int pc_node; 70 int busnode[256]; 71 72 pcireg_t (*pc_conf_read)(void *, pcitag_t, int); 73 void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); 74 }; 75 76 77 void pci_attach_hook(struct device *, struct device *, 78 struct pcibus_attach_args *); 79 int pci_bus_maxdevs(pci_chipset_tag_t, int); 80 pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int); 81 void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, int *, int *, 82 int *); 83 int pci_conf_size(pci_chipset_tag_t, pcitag_t); 84 pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); 85 void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t); 86 int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); 87 int pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); 88 int pci_intr_line(pci_chipset_tag_t, pci_intr_handle_t); 89 const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); 90 void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, 91 int, int (*)(void *), void *, const char *); 92 void pci_intr_disestablish(pci_chipset_tag_t, void *); 93 int pci_ether_hw_addr(pci_chipset_tag_t, uint8_t *); 94 95 #define pci_probe_device_hook(c, a) (0) 96 97 #define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) 98 #define pci_set_powerstate_md(c, t, s, p) 99 100 #define pci_dev_postattach(a, b) 101 102 int ofw_intr_map(int, uint32_t *, uint32_t *); 103 int ofw_enumerate_pcibus(struct pci_softc *, 104 int (*match)(struct pci_attach_args *), 105 struct pci_attach_args *); 106 107 #define PCI_MACHDEP_ENUMERATE_BUS ofw_enumerate_pcibus 108 109 #endif /* _MACHINE_PCI_MACHDEP_H_ */ 110