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