Home | History | Annotate | Line # | Download | only in include
pci_machdep.h revision 1.3
      1 /* $NetBSD: pci_machdep.h,v 1.3 2007/10/25 16:55:50 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 /*
     58  * Forward declarations.
     59  */
     60 struct pci_attach_args;
     61 
     62 /* Per bus information structure */
     63 struct genppc_pci_chipset_businfo {
     64 	SIMPLEQ_ENTRY(genppc_pci_chipset_businfo) next;
     65 	prop_dictionary_t	pbi_properties; /* chipset properties */
     66 };
     67 
     68 /*
     69  * Generic PPC PCI structure and type definitions.
     70  * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
     71  */
     72 struct genppc_pci_chipset {
     73 	void		*pc_conf_v;
     74 	void		(*pc_attach_hook)(struct device *,
     75 			    struct device *, struct pcibus_attach_args *);
     76 	int		(*pc_bus_maxdevs)(pci_chipset_tag_t, int);
     77 	pcitag_t	(*pc_make_tag)(void *, int, int, int);
     78 	pcireg_t	(*pc_conf_read)(void *, pcitag_t, int);
     79 	void		(*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
     80 
     81 	void		*pc_intr_v;
     82 	int		(*pc_intr_map)(struct pci_attach_args *,
     83 			    pci_intr_handle_t *);
     84 	const char	*(*pc_intr_string)(void *, pci_intr_handle_t);
     85 	const struct evcnt *(*pc_intr_evcnt)(void *, pci_intr_handle_t);
     86 	void		*(*pc_intr_establish)(void *, pci_intr_handle_t,
     87 			    int, int (*)(void *), void *);
     88 	void		(*pc_intr_disestablish)(void *, void *);
     89 	void		(*pc_conf_interrupt)(pci_chipset_tag_t, int, int, int,
     90 			    int, int *);
     91 	void		(*pc_decompose_tag)(void *, pcitag_t, int *,
     92 			    int *, int *);
     93 	int		(*pc_conf_hook)(pci_chipset_tag_t, int, int, int,
     94 			    pcireg_t);
     95 
     96 	u_int32_t	*pc_addr;
     97 	u_int32_t	*pc_data;
     98 	int		pc_node;
     99 	int		pc_ihandle;
    100 	int		pc_bus;
    101 	bus_space_tag_t	pc_memt;
    102 	bus_space_tag_t	pc_iot;
    103 
    104 	SIMPLEQ_HEAD(, genppc_pci_chipset_businfo) pc_pbi;
    105 };
    106 
    107 /*
    108  * Functions provided to machine-independent PCI code.
    109  */
    110 #define	pci_attach_hook(p, s, pba)					\
    111     (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
    112 #define	pci_bus_maxdevs(c, b)						\
    113     (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b))
    114 #define	pci_make_tag(c, b, d, f)					\
    115     (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f))
    116 #define	pci_conf_read(c, t, r)						\
    117     (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
    118 #define	pci_conf_write(c, t, r, v)					\
    119     (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v))
    120 #define	pci_intr_map(pa, ihp)						\
    121     (*(pa)->pa_pc->pc_intr_map)((pa), (ihp))
    122 #define	pci_intr_string(c, ih)						\
    123     (*(c)->pc_intr_string)((c)->pc_intr_v, (ih))
    124 #define	pci_intr_evcnt(c, ih)						\
    125     (*(c)->pc_intr_evcnt)((c)->pc_intr_v, (ih))
    126 #define	pci_intr_establish(c, ih, l, h, a)				\
    127     (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a))
    128 #define	pci_intr_disestablish(c, iv)					\
    129     (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv))
    130 #define	pci_conf_interrupt(c, b, d, p, s, ip)				\
    131     (*(c)->pc_conf_interrupt)((c)->pc_conf_v, (b), (d), (p), (s), (ip))
    132 #define	pci_decompose_tag(c, t, bp, dp, fp)				\
    133     (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
    134 #define	pci_conf_hook(c, b, d, f, i)					\
    135     (*(c)->pc_conf_hook)((c)->pc_conf_v, (b), (d), (f), (i))
    136 
    137 #ifdef _KERNEL
    138 
    139 /*
    140  * Generic PowerPC PCI functions.  Override if necc.
    141  */
    142 
    143 int genppc_pci_bus_maxdevs(pci_chipset_tag_t, int);
    144 const char *genppc_pci_intr_string(void *, pci_intr_handle_t);
    145 const struct evcnt *genppc_pci_intr_evcnt(void *, pci_intr_handle_t);
    146 void *genppc_pci_intr_establish(void *, pci_intr_handle_t, int, int (*)(void *),
    147     void *);
    148 void genppc_pci_intr_disestablish(void *, void *);
    149 void genppc_pci_conf_interrupt(pci_chipset_tag_t, int, int, int, int, int *);
    150 int genppc_pci_conf_hook(pci_chipset_tag_t, int, int, int, pcireg_t);
    151 int genppc_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp);
    152 
    153 /* generic indirect PCI functions */
    154 void genppc_pci_indirect_attach_hook(struct device *, struct device *,
    155     struct pcibus_attach_args *);
    156 pcitag_t genppc_pci_indirect_make_tag(void *, int, int, int);
    157 pcireg_t genppc_pci_indirect_conf_read(void *, pcitag_t, int);
    158 void genppc_pci_indirect_conf_write(void *, pcitag_t, int, pcireg_t);
    159 void genppc_pci_indirect_decompose_tag(void *, pcitag_t, int *, int *, int *);
    160 
    161 /* generic OFW method PCI functions */
    162 void genppc_pci_ofmethod_attach_hook(struct device *, struct device *,
    163     struct pcibus_attach_args *);
    164 pcitag_t genppc_pci_ofmethod_make_tag(void *, int, int, int);
    165 pcireg_t genppc_pci_ofmethod_conf_read(void *, pcitag_t, int);
    166 void genppc_pci_ofmethod_conf_write(void *, pcitag_t, int, pcireg_t);
    167 void genppc_pci_ofmethod_decompose_tag(void *, pcitag_t, int *, int *, int *);
    168 
    169 /* XXX for now macppc needs its own pci_bus_dma_tag */
    170 #ifndef macppc
    171 extern struct powerpc_bus_dma_tag pci_bus_dma_tag;
    172 #endif
    173 
    174 /* Generic OFW PCI functions */
    175 
    176 int genofw_find_picnode(int);
    177 void genofw_find_ofpics(int);
    178 void genofw_fixup_picnode_offsets(void);
    179 void genofw_setup_pciintr_map(struct genppc_pci_chipset_businfo *, int);
    180 int genofw_find_node_by_devfunc(int, int, int, int);
    181 int genofw_pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
    182 int genofw_pci_conf_hook(pci_chipset_tag_t, int, int, int, pcireg_t);
    183 
    184 
    185 /* OFW PCI structures and defines */
    186 #define PICNODE_TYPE_OPENPIC	1
    187 #define PICNODE_TYPE_8259	2
    188 #define PICNODE_TYPE_HEATHROW	3
    189 #define PICNODE_TYPE_OHARE	4
    190 
    191 typedef struct _ofw_pic_node_t {
    192 	int node;
    193 	int parent;
    194 	int16_t cells;
    195 	int16_t intrs;
    196 	int16_t offset;
    197 	int16_t type;
    198 } ofw_pic_node_t;
    199 
    200 #endif /* _KERNEL */
    201 
    202 #endif /* _PCI_MACHDEP_H_ */
    203