Home | History | Annotate | Line # | Download | only in include
      1 /*	$NetBSD: pci_machdep.h,v 1.18 2020/02/13 00:02:21 jmcneill Exp $	*/
      2 
      3 /*
      4  * Modified for arm32 by Mark Brinicombe
      5  *
      6  * from: sys/arch/alpha/pci/pci_machdep.h
      7  *
      8  * Copyright (c) 1996 Carnegie-Mellon University.
      9  * All rights reserved.
     10  *
     11  * Author: Chris G. Demetriou
     12  *
     13  * Permission to use, copy, modify and distribute this software and
     14  * its documentation is hereby granted, provided that both the copyright
     15  * notice and this permission notice appear in all copies of the
     16  * software, derivative works or modified versions, and any portions
     17  * thereof, and that both notices appear in supporting documentation.
     18  *
     19  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     20  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     21  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     22  *
     23  * Carnegie Mellon requests users of this software to return to
     24  *
     25  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     26  *  School of Computer Science
     27  *  Carnegie Mellon University
     28  *  Pittsburgh PA 15213-3890
     29  *
     30  * any improvements or extensions that they make and grant Carnegie the
     31  * rights to redistribute these changes.
     32  */
     33 
     34 #ifndef _ARM_PCI_MACHDEP_H_
     35 #define _ARM_PCI_MACHDEP_H_
     36 /*
     37  * Machine-specific definitions for PCI autoconfiguration.
     38  */
     39 
     40 #ifdef __aarch64__
     41 #define _PCI_HAVE_DMA64
     42 #endif
     43 
     44 #define __HAVE_PCI_GET_SEGMENT
     45 
     46 #include <sys/errno.h>
     47 
     48 /*
     49  * Types provided to machine-independent PCI code
     50  */
     51 typedef struct	arm32_pci_chipset	*pci_chipset_tag_t;
     52 typedef u_long	pcitag_t;
     53 typedef uint64_t pci_intr_handle_t;
     54 
     55 /*
     56  * pci_intr_handle_t fields
     57  */
     58 #define	ARM_PCI_INTR_MSI_VEC	0x000007ff00000000ULL
     59 #define	ARM_PCI_INTR_MPSAFE	0x0000000080000000ULL
     60 #define	ARM_PCI_INTR_MSIX	0x0000000040000000ULL
     61 #define	ARM_PCI_INTR_MSI	0x0000000020000000ULL
     62 #define	ARM_PCI_INTR_FRAME	0x0000000000ff0000ULL
     63 #define	ARM_PCI_INTR_IRQ	0x000000000000ffffULL
     64 
     65 #ifdef __HAVE_PCI_MSI_MSIX
     66 /*
     67  * PCI MSI/MSI-X support
     68  */
     69 typedef enum {
     70 	PCI_INTR_TYPE_INTX = 0,
     71 	PCI_INTR_TYPE_MSI,
     72 	PCI_INTR_TYPE_MSIX,
     73 	PCI_INTR_TYPE_SIZE,
     74 } pci_intr_type_t;
     75 #endif /* __HAVE_PCI_MSI_MSIX */
     76 
     77 /*
     78  * Forward declarations.
     79  */
     80 struct pci_attach_args;
     81 
     82 /*
     83  * arm32-specific PCI structure and type definitions.
     84  * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
     85  */
     86 struct arm32_pci_chipset {
     87 	void		*pc_conf_v;
     88 	void		(*pc_attach_hook)(device_t, device_t,
     89 			    struct pcibus_attach_args *);
     90 	int		(*pc_bus_maxdevs)(void *, int);
     91 	pcitag_t	(*pc_make_tag)(void *, int, int, int);
     92 	void		(*pc_decompose_tag)(void *, pcitag_t, int *,
     93 			    int *, int *);
     94 	u_int		(*pc_get_segment)(void *);
     95 	uint32_t	(*pc_get_devid)(void *, uint32_t);
     96 	uint32_t	(*pc_get_frameid)(void *, uint32_t);
     97 	pcireg_t	(*pc_conf_read)(void *, pcitag_t, int);
     98 	void		(*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
     99 
    100 	void		*pc_intr_v;
    101 	int		(*pc_intr_map)(const struct pci_attach_args *,
    102 			    pci_intr_handle_t *);
    103 	const char	*(*pc_intr_string)(void *, pci_intr_handle_t,
    104 			    char *, size_t);
    105 	const struct evcnt *(*pc_intr_evcnt)(void *, pci_intr_handle_t);
    106 	int		(*pc_intr_setattr)(void *, pci_intr_handle_t *,
    107 			    int, uint64_t);
    108 	void		*(*pc_intr_establish)(void *, pci_intr_handle_t,
    109 			    int, int (*)(void *), void *, const char *);
    110 	void		(*pc_intr_disestablish)(void *, void *);
    111 
    112 #ifdef __HAVE_PCI_CONF_HOOK
    113 	int		(*pc_conf_hook)(void *, int, int, int, pcireg_t);
    114 #endif
    115 	void		(*pc_conf_interrupt)(void *, int, int, int, int, int *);
    116 
    117 #ifdef __HAVE_PCI_MSI_MSIX
    118 	void		*pc_msi_v;
    119 	pci_intr_type_t	(*pc_intr_type)(void *, pci_intr_handle_t);
    120 	int		(*pc_intr_alloc)(const struct pci_attach_args *,
    121 			    pci_intr_handle_t **, int *, pci_intr_type_t);
    122 	void		(*pc_intr_release)(void *, pci_intr_handle_t *, int);
    123 	int		(*pc_intx_alloc)(const struct pci_attach_args *,
    124 			    pci_intr_handle_t **);
    125 	int		(*pc_msi_alloc)(const struct pci_attach_args *,
    126 			    pci_intr_handle_t **, int *);
    127 	int		(*pc_msi_alloc_exact)(const struct pci_attach_args *,
    128 			    pci_intr_handle_t **, int);
    129 	int		(*pc_msix_alloc)(const struct pci_attach_args *,
    130 			    pci_intr_handle_t **, int *);
    131 	int		(*pc_msix_alloc_exact)(const struct pci_attach_args *,
    132 			    pci_intr_handle_t **, int);
    133 	int		(*pc_msix_alloc_map)(const struct pci_attach_args *,
    134 			    pci_intr_handle_t **, u_int *, int);
    135 #endif
    136 
    137 	uint32_t	pc_cfg_cmd;
    138 };
    139 
    140 /*
    141  * Functions provided to machine-independent PCI code.
    142  */
    143 #define	pci_attach_hook(p, s, pba)					\
    144     (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
    145 #define	pci_bus_maxdevs(c, b)						\
    146     (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b))
    147 #define	pci_make_tag(c, b, d, f)					\
    148     (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f))
    149 #define	pci_decompose_tag(c, t, bp, dp, fp)				\
    150     (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
    151 #define pci_get_segment(c)						\
    152     ((c)->pc_get_segment ? (*(c)->pc_get_segment)((c)->pc_conf_v) : 0)
    153 #define pci_get_devid(c, d)						\
    154     ((c)->pc_get_devid ? (*(c)->pc_get_devid)((c)->pc_conf_v, (d)) : (d))
    155 #define pci_get_frameid(c, d)						\
    156     ((c)->pc_get_frameid ? (*(c)->pc_get_frameid)((c)->pc_conf_v, (d)) : 0)
    157 #define	pci_conf_read(c, t, r)						\
    158     (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
    159 #define	pci_conf_write(c, t, r, v)					\
    160     (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v))
    161 #define	pci_intr_map(pa, ihp)						\
    162     (*(pa)->pa_pc->pc_intr_map)((pa), (ihp))
    163 #define	pci_intr_string(c, ih, buf, len)				\
    164     (*(c)->pc_intr_string)((c)->pc_intr_v, (ih), (buf), (len))
    165 #define	pci_intr_evcnt(c, ih)						\
    166     (*(c)->pc_intr_evcnt)((c)->pc_intr_v, (ih))
    167 #define	pci_intr_establish(c, ih, l, h, a)				\
    168     (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a), NULL)
    169 #define	pci_intr_disestablish(c, iv)					\
    170     (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv))
    171 #ifdef __HAVE_PCI_CONF_HOOK
    172 #define	pci_conf_hook(c, b, d, f, id)					\
    173     (*(c)->pc_conf_hook)((c)->pc_conf_v, (b), (d), (f), (id))
    174 #endif
    175 #define	pci_conf_interrupt(c, b, d, i, s, p)				\
    176     (*(c)->pc_conf_interrupt)((c)->pc_conf_v, (b), (d), (i), (s), (p))
    177 
    178 static inline int
    179 pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ihp,
    180     int attr, uint64_t data)
    181 {
    182 	if (!pc->pc_intr_setattr)
    183 		return ENODEV;
    184 	return pc->pc_intr_setattr(pc, ihp, attr, data);
    185 }
    186 
    187 static inline void *
    188 pci_intr_establish_xname(pci_chipset_tag_t pc, pci_intr_handle_t ih,
    189     int level, int (*func)(void *), void *arg, const char *xname)
    190 {
    191 	return pc->pc_intr_establish(pc->pc_intr_v, ih, level, func, arg, xname);
    192 }
    193 
    194 #ifdef __HAVE_PCI_MSI_MSIX
    195 pci_intr_type_t	pci_intr_type(pci_chipset_tag_t, pci_intr_handle_t);
    196 int	pci_intr_alloc(const struct pci_attach_args *, pci_intr_handle_t **,
    197 	    int *, pci_intr_type_t);
    198 void	pci_intr_release(pci_chipset_tag_t, pci_intr_handle_t *, int);
    199 int	pci_intx_alloc(const struct pci_attach_args *, pci_intr_handle_t **);
    200 int	pci_msi_alloc(const struct pci_attach_args *, pci_intr_handle_t **,
    201 	    int *);
    202 int	pci_msi_alloc_exact(const struct pci_attach_args *,
    203 	    pci_intr_handle_t **, int);
    204 int	pci_msix_alloc(const struct pci_attach_args *, pci_intr_handle_t **,
    205 	    int *);
    206 int	pci_msix_alloc_exact(const struct pci_attach_args *,
    207 	    pci_intr_handle_t **, int);
    208 int	pci_msix_alloc_map(const struct pci_attach_args *, pci_intr_handle_t **,
    209 	    u_int *, int);
    210 #endif	/* __HAVE_PCI_MSI_MSIX */
    211 
    212 #endif	/* _ARM_PCI_MACHDEP_H_ */
    213