1/* $NetBSD: pci_machdep.h,v 1.15 2022/08/16 14:00:03 skrll Exp $ */
2/* NetBSD: pci_machdep.h,v 1.3 1999/03/19 03:40:46 cgd Exp  */
3
4/*
5 * Copyright (c) 1996 Carnegie-Mellon University.
6 * All rights reserved.
7 *
8 * Author: Chris G. Demetriou
9 *
10 * Permission to use, copy, modify and distribute this software and
11 * its documentation is hereby granted, provided that both the copyright
12 * notice and this permission notice appear in all copies of the
13 * software, derivative works or modified versions, and any portions
14 * thereof, and that both notices appear in supporting documentation.
15 *
16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 *
20 * Carnegie Mellon requests users of this software to return to
21 *
22 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23 *  School of Computer Science
24 *  Carnegie Mellon University
25 *  Pittsburgh PA 15213-3890
26 *
27 * any improvements or extensions that they make and grant Carnegie the
28 * rights to redistribute these changes.
29 */
30
31#ifndef	_MACHINE_PCI_MACHDEP_H_
32#define	_MACHINE_PCI_MACHDEP_H_
33
34/*
35 * Machine-specific definitions for PCI autoconfiguration.
36 */
37#define __HAVE_PCI_CONF_HOOK
38
39/*
40 * Forward declarations.
41 */
42struct pci_attach_args;
43
44/*
45 * Types provided to machine-independent PCI code
46 */
47typedef struct arc_pci_chipset *pci_chipset_tag_t;
48typedef u_long pcitag_t;
49typedef u_long pci_intr_handle_t;
50
51/*
52 * arc-specific PCI structure and type definitions.
53 * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
54 */
55struct arc_pci_chipset {
56	void		(*pc_attach_hook)(device_t, device_t,
57			    struct pcibus_attach_args *);
58	int		(*pc_bus_maxdevs)(pci_chipset_tag_t, int);
59	pcitag_t	(*pc_make_tag)(pci_chipset_tag_t, int, int, int);
60	void		(*pc_decompose_tag)(pci_chipset_tag_t, pcitag_t,
61			    int *, int *, int *);
62	pcireg_t	(*pc_conf_read)(pci_chipset_tag_t, pcitag_t, int);
63	void		(*pc_conf_write)(pci_chipset_tag_t, pcitag_t, int,
64			    pcireg_t);
65	int		(*pc_intr_map)(const struct pci_attach_args *,
66			    pci_intr_handle_t *);
67	const char	*(*pc_intr_string)(pci_chipset_tag_t,
68			    pci_intr_handle_t, char *, size_t);
69	int		(*pc_intr_setattr)(void *, pci_intr_handle_t *,
70			    int, uint64_t);
71	void		*(*pc_intr_establish)(pci_chipset_tag_t,
72			    pci_intr_handle_t, int, int (*)(void *), void *);
73	void		(*pc_intr_disestablish)(pci_chipset_tag_t, void *);
74	void		(*pc_conf_interrupt)(pci_chipset_tag_t, int, int, int,
75			    int, int *);
76	int		(*pc_conf_hook)(pci_chipset_tag_t, int, int, int,
77			    pcireg_t);
78};
79
80/*
81 * Functions provided to machine-independent PCI code.
82 */
83#define	pci_attach_hook(p, s, pba)					\
84    (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
85#define	pci_bus_maxdevs(c, b)						\
86    (*(c)->pc_bus_maxdevs)((c), (b))
87#define	pci_make_tag(c, b, d, f)					\
88    (*(c)->pc_make_tag)((c), (b), (d), (f))
89#define	pci_decompose_tag(c, t, bp, dp, fp)				\
90    (*(c)->pc_decompose_tag)((c), (t), (bp), (dp), (fp))
91#define	pci_conf_read(c, t, r)						\
92    (*(c)->pc_conf_read)((c), (t), (r))
93#define	pci_conf_write(c, t, r, v)					\
94    (*(c)->pc_conf_write)((c), (t), (r), (v))
95#define	pci_intr_map(pa, ihp)						\
96    (*(pa)->pa_pc->pc_intr_map)((pa), (ihp))
97#define	pci_intr_string(c, ih, buf, len)				\
98    (*(c)->pc_intr_string)((c), (ih), (buf), (len))
99#define	pci_intr_establish(c, ih, l, h, a)				\
100    (*(c)->pc_intr_establish)((c), (ih), (l), (h), (a))
101#define	pci_intr_disestablish(c, iv)					\
102    (*(c)->pc_intr_disestablish)((c), (iv))
103#define	pci_conf_interrupt(c, b, d, f, s, i)				\
104    (*(c)->pc_conf_interrupt)((c), (b), (d), (f), (s), (i))
105#define	pci_conf_hook(c, b, d, f, i)					\
106    (*(c)->pc_conf_hook)((c), (b), (d), (f), (i))
107
108static inline int
109pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ihp,
110    int attr, uint64_t data)
111{
112	if (!pc->pc_intr_setattr)
113		return ENODEV;
114	return pc->pc_intr_setattr(pc, ihp, attr, data);
115}
116
117#endif /* _MACHINE_PCI_MACHDEP_H_ */
118