Home | History | Annotate | Line # | Download | only in include
pci_machdep.h revision 1.10
      1 /* $NetBSD: pci_machdep.h,v 1.10 2011/04/04 20:37:52 dyoung Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2002,2007 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Klaus Klein and Tim Rightnour
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _PCI_MACHDEP_H_
     33 #define _PCI_MACHDEP_H_
     34 
     35 #include <prop/proplib.h>
     36 
     37 /*
     38  * Machine-specific definitions for PCI autoconfiguration.
     39  */
     40 
     41 #define __HAVE_PCI_CONF_HOOK
     42 
     43 /*
     44  * Types provided to machine-independent PCI code
     45  */
     46 typedef struct genppc_pci_chipset *pci_chipset_tag_t;
     47 typedef int pcitag_t;
     48 typedef int pci_intr_handle_t;
     49 
     50 extern struct powerpc_bus_dma_tag pci_bus_dma_tag;
     51 
     52 /*
     53  * Forward declarations.
     54  */
     55 struct pci_attach_args;
     56 
     57 /* Per bus information structure */
     58 struct genppc_pci_chipset_businfo {
     59 	SIMPLEQ_ENTRY(genppc_pci_chipset_businfo) next;
     60 	prop_dictionary_t	pbi_properties; /* chipset properties */
     61 };
     62 
     63 /*
     64  * Generic PPC PCI structure and type definitions.
     65  * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
     66  */
     67 struct genppc_pci_chipset {
     68 	void		*pc_conf_v;
     69 	void		(*pc_attach_hook)(device_t, device_t,
     70 			    struct pcibus_attach_args *);
     71 	int		(*pc_bus_maxdevs)(void *, int);
     72 	pcitag_t	(*pc_make_tag)(void *, int, int, int);
     73 	pcireg_t	(*pc_conf_read)(void *, pcitag_t, int);
     74 	void		(*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
     75 
     76 	void		*pc_intr_v;
     77 	int		(*pc_intr_map)(const struct pci_attach_args *,
     78 			    pci_intr_handle_t *);
     79 	const char	*(*pc_intr_string)(void *, pci_intr_handle_t);
     80 	const struct evcnt *(*pc_intr_evcnt)(void *, pci_intr_handle_t);
     81 	void		*(*pc_intr_establish)(void *, pci_intr_handle_t,
     82 			    int, int (*)(void *), void *);
     83 	void		(*pc_intr_disestablish)(void *, void *);
     84 	void		(*pc_conf_interrupt)(pci_chipset_tag_t, int, int, int,
     85 			    int, int *);
     86 	void		(*pc_decompose_tag)(void *, pcitag_t, int *,
     87 			    int *, int *);
     88 	int		(*pc_conf_hook)(pci_chipset_tag_t, int, int, int,
     89 			    pcireg_t);
     90 
     91 	u_int32_t	*pc_addr;
     92 	u_int32_t	*pc_data;
     93 	int		pc_node;
     94 	int		pc_ihandle;
     95 	int		pc_bus;
     96 	bus_space_tag_t	pc_memt;
     97 	bus_space_tag_t	pc_iot;
     98 
     99 	SIMPLEQ_HEAD(, genppc_pci_chipset_businfo) pc_pbi;
    100 };
    101 
    102 /*
    103  * Functions provided to machine-independent PCI code.
    104  */
    105 #define	pci_attach_hook(p, s, pba)					\
    106     (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
    107 #define	pci_bus_maxdevs(c, b)						\
    108     (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b))
    109 #define	pci_make_tag(c, b, d, f)					\
    110     (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f))
    111 #define	pci_conf_read(c, t, r)						\
    112     (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
    113 #define	pci_conf_write(c, t, r, v)					\
    114     (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v))
    115 #define	pci_intr_map(pa, ihp)						\
    116     (*(pa)->pa_pc->pc_intr_map)((pa), (ihp))
    117 #define	pci_intr_string(c, ih)						\
    118     (*(c)->pc_intr_string)((c)->pc_intr_v, (ih))
    119 #define	pci_intr_evcnt(c, ih)						\
    120     (*(c)->pc_intr_evcnt)((c)->pc_intr_v, (ih))
    121 #define	pci_intr_establish(c, ih, l, h, a)				\
    122     (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a))
    123 #define	pci_intr_disestablish(c, iv)					\
    124     (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv))
    125 #define	pci_conf_interrupt(c, b, d, p, s, ip)				\
    126     (*(c)->pc_conf_interrupt)((c)->pc_conf_v, (b), (d), (p), (s), (ip))
    127 #define	pci_decompose_tag(c, t, bp, dp, fp)				\
    128     (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
    129 #define	pci_conf_hook(c, b, d, f, i)					\
    130     (*(c)->pc_conf_hook)((c)->pc_conf_v, (b), (d), (f), (i))
    131 
    132 #ifdef _KERNEL
    133 
    134 /*
    135  * Generic PowerPC PCI functions.  Override if necc.
    136  */
    137 
    138 int genppc_pci_bus_maxdevs(void *, int);
    139 const char *genppc_pci_intr_string(void *, pci_intr_handle_t);
    140 const struct evcnt *genppc_pci_intr_evcnt(void *, pci_intr_handle_t);
    141 void *genppc_pci_intr_establish(void *, pci_intr_handle_t, int, int (*)(void *),
    142     void *);
    143 void genppc_pci_intr_disestablish(void *, void *);
    144 void genppc_pci_conf_interrupt(pci_chipset_tag_t, int, int, int, int, int *);
    145 int genppc_pci_conf_hook(pci_chipset_tag_t, int, int, int, pcireg_t);
    146 int genppc_pci_intr_map(const struct pci_attach_args *pa,
    147     pci_intr_handle_t *ihp);
    148 
    149 /* generic indirect PCI functions */
    150 void genppc_pci_indirect_attach_hook(device_t, device_t,
    151     struct pcibus_attach_args *);
    152 pcitag_t genppc_pci_indirect_make_tag(void *, int, int, int);
    153 pcireg_t genppc_pci_indirect_conf_read(void *, pcitag_t, int);
    154 void genppc_pci_indirect_conf_write(void *, pcitag_t, int, pcireg_t);
    155 void genppc_pci_indirect_decompose_tag(void *, pcitag_t, int *, int *, int *);
    156 
    157 /* generic OFW method PCI functions */
    158 void genppc_pci_ofmethod_attach_hook(device_t, device_t,
    159     struct pcibus_attach_args *);
    160 pcitag_t genppc_pci_ofmethod_make_tag(void *, int, int, int);
    161 pcireg_t genppc_pci_ofmethod_conf_read(void *, pcitag_t, int);
    162 void genppc_pci_ofmethod_conf_write(void *, pcitag_t, int, pcireg_t);
    163 void genppc_pci_ofmethod_decompose_tag(void *, pcitag_t, int *, int *, int *);
    164 
    165 /* Generic OFW PCI functions */
    166 
    167 int genofw_find_picnode(int);
    168 void genofw_find_ofpics(int);
    169 void genofw_fixup_picnode_offsets(void);
    170 void genofw_setup_pciintr_map(void *, struct genppc_pci_chipset_businfo *, int);
    171 int genofw_find_node_by_devfunc(int, int, int, int);
    172 int genofw_pci_intr_map(const struct pci_attach_args *, pci_intr_handle_t *);
    173 int genofw_pci_conf_hook(pci_chipset_tag_t, int, int, int, pcireg_t);
    174 
    175 
    176 /* OFW PCI structures and defines */
    177 #define PICNODE_TYPE_OPENPIC	1
    178 #define PICNODE_TYPE_8259	2
    179 #define PICNODE_TYPE_HEATHROW	3
    180 #define PICNODE_TYPE_OHARE	4
    181 #define PICNODE_TYPE_IVR	5
    182 
    183 typedef struct _ofw_pic_node_t {
    184 	int node;
    185 	int parent;
    186 	int16_t cells;
    187 	int16_t intrs;
    188 	int16_t offset;
    189 	int16_t type;
    190 } ofw_pic_node_t;
    191 
    192 #endif /* _KERNEL */
    193 
    194 #endif /* _PCI_MACHDEP_H_ */
    195