1*8bc54e5bSmsaitoh /* $NetBSD: pci_machdep.h,v 1.12 2016/07/07 06:55:38 msaitoh Exp $ */ 2de47c087Suwe 3de47c087Suwe /* 4de47c087Suwe * Copyright (c) 1999 Matthew R. Green 5de47c087Suwe * All rights reserved. 6de47c087Suwe * 7de47c087Suwe * Redistribution and use in source and binary forms, with or without 8de47c087Suwe * modification, are permitted provided that the following conditions 9de47c087Suwe * are met: 10de47c087Suwe * 1. Redistributions of source code must retain the above copyright 11de47c087Suwe * notice, this list of conditions and the following disclaimer. 12de47c087Suwe * 2. Redistributions in binary form must reproduce the above copyright 13de47c087Suwe * notice, this list of conditions and the following disclaimer in the 14de47c087Suwe * documentation and/or other materials provided with the distribution. 15de47c087Suwe * 16de47c087Suwe * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17de47c087Suwe * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18de47c087Suwe * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19de47c087Suwe * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20de47c087Suwe * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21de47c087Suwe * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22de47c087Suwe * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23de47c087Suwe * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24de47c087Suwe * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25de47c087Suwe * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26de47c087Suwe * SUCH DAMAGE. 27de47c087Suwe */ 28de47c087Suwe 29de47c087Suwe #ifndef _SPARC_PCI_MACHDEP_H_ 30de47c087Suwe #define _SPARC_PCI_MACHDEP_H_ 31de47c087Suwe 32de47c087Suwe /* 33de47c087Suwe * Machine-specific definitions for PCI autoconfiguration. 34de47c087Suwe */ 35de47c087Suwe 36de47c087Suwe /* 37de47c087Suwe * Types provided to machine-independent PCI code 38de47c087Suwe */ 39de47c087Suwe typedef struct sparc_pci_chipset *pci_chipset_tag_t; 40de47c087Suwe typedef u_int pci_intr_handle_t; 416e4f5eb5Suwe typedef uint64_t pcitag_t; 42de47c087Suwe 43de47c087Suwe 44de47c087Suwe /* 45de47c087Suwe * Forward declarations. 46de47c087Suwe */ 47de47c087Suwe struct pci_attach_args; 48de47c087Suwe 49de47c087Suwe 50de47c087Suwe /* 51de47c087Suwe * sparc-specific PCI structure and type definitions. 52de47c087Suwe * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. 53de47c087Suwe */ 54de47c087Suwe struct sparc_pci_chipset { 55de47c087Suwe void *cookie; /* msiiep_softc, but sssh! */ 56de47c087Suwe }; 57de47c087Suwe 585b2f52ecSjdc #define IS_PCI_BRIDGE(class) \ 595b2f52ecSjdc (((class >> 16) & 0xff) == PCI_CLASS_BRIDGE && \ 605b2f52ecSjdc ((class >> 8) & 0xff) == PCI_SUBCLASS_BRIDGE_PCI) 615b2f52ecSjdc 62de47c087Suwe /* 63de47c087Suwe * The MI PCI code expects pcitag_t to be a scalar type. But besides 64de47c087Suwe * the bus/device/function we need to store the OFW node as well. We 656e4f5eb5Suwe * can squeeze them into a uint64_t with a little help from some 66de47c087Suwe * macros. And while we are at it mangle bus/device/function into a 67de47c087Suwe * form directly suitable for pci mode1 configuration address port. 68de47c087Suwe */ 69de47c087Suwe #define PCITAG_CREATE(n,b,d,f) \ 705b2f52ecSjdc (((uint64_t)(n)<<32)|0x80000000U|((b)<<16)|((d)<<11)|((f)<<8)|(b?1:0)) 71de47c087Suwe 726e4f5eb5Suwe #define PCITAG_NODE(t) ((uint32_t)(((t)>>32)&0xffffffff)) 736e4f5eb5Suwe #define PCITAG_OFFSET(t) ((uint32_t)((t)&0xffffffff)) 74de47c087Suwe #define PCITAG_BUS(t) ((PCITAG_OFFSET(t)>>16)&0xFF) 75de47c087Suwe #define PCITAG_DEV(t) ((PCITAG_OFFSET(t)>>11)&0x1F) 76de47c087Suwe #define PCITAG_FUN(t) ((PCITAG_OFFSET(t)>>8)&0x7) 77de47c087Suwe 78de47c087Suwe 79de47c087Suwe /* 80de47c087Suwe * Functions provided to machine-independent PCI code. 81de47c087Suwe */ 82cbab9cadSchs void pci_attach_hook(device_t, device_t, 83de47c087Suwe struct pcibus_attach_args *); 84de47c087Suwe int pci_bus_maxdevs(pci_chipset_tag_t, int); 85de47c087Suwe pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int); 86de47c087Suwe void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, 87de47c087Suwe int *, int *, int *); 88de47c087Suwe pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); 89de47c087Suwe void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t); 90d3e53912Sdyoung int pci_intr_map(const struct pci_attach_args *, 91d3e53912Sdyoung pci_intr_handle_t *); 92e58a356cSchristos const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t, 93e58a356cSchristos char *, size_t); 94de47c087Suwe const struct evcnt *pci_intr_evcnt(pci_chipset_tag_t, pci_intr_handle_t); 95de47c087Suwe void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, 96de47c087Suwe int, int (*)(void *), void *); 97de47c087Suwe void pci_intr_disestablish(pci_chipset_tag_t, void *); 98de47c087Suwe 99de47c087Suwe #endif /* _SPARC_PCI_MACHDEP_H_ */ 100