xref: /openbsd-src/sys/arch/octeon/include/pci_machdep.h (revision a8b581972213782bec450017fe45a05ea431addf)
1*a8b58197Sjsg /*	$OpenBSD: pci_machdep.h,v 1.13 2024/05/20 23:13:33 jsg Exp $ */
262023fb5Ssyuu 
362023fb5Ssyuu /*
462023fb5Ssyuu  * Copyright (c) 2003-2004 Opsycon AB  (www.opsycon.se / www.opsycon.com)
562023fb5Ssyuu  *
662023fb5Ssyuu  * Redistribution and use in source and binary forms, with or without
762023fb5Ssyuu  * modification, are permitted provided that the following conditions
862023fb5Ssyuu  * are met:
962023fb5Ssyuu  * 1. Redistributions of source code must retain the above copyright
1062023fb5Ssyuu  *    notice, this list of conditions and the following disclaimer.
1162023fb5Ssyuu  * 2. Redistributions in binary form must reproduce the above copyright
1262023fb5Ssyuu  *    notice, this list of conditions and the following disclaimer in the
1362023fb5Ssyuu  *    documentation and/or other materials provided with the distribution.
1462023fb5Ssyuu  *
1562023fb5Ssyuu  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
1662023fb5Ssyuu  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1762023fb5Ssyuu  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1862023fb5Ssyuu  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
1962023fb5Ssyuu  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2062023fb5Ssyuu  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2162023fb5Ssyuu  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2262023fb5Ssyuu  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2362023fb5Ssyuu  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2462023fb5Ssyuu  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2562023fb5Ssyuu  * SUCH DAMAGE.
2662023fb5Ssyuu  *
2762023fb5Ssyuu  */
2862023fb5Ssyuu #include <sys/systm.h>
2962023fb5Ssyuu 
3062023fb5Ssyuu typedef struct mips_pci_chipset *pci_chipset_tag_t;
31387a8b5bSderaadt 
32387a8b5bSderaadt typedef u_int64_t pcitag_t;
33387a8b5bSderaadt #define PCITAG_NODE(x)		((x) >> 32)
34387a8b5bSderaadt #define PCITAG_OFFSET(x)	((x) & 0xffffffff)
35387a8b5bSderaadt 
3662023fb5Ssyuu typedef u_long pci_intr_handle_t;
3762023fb5Ssyuu 
3862023fb5Ssyuu struct pci_attach_args;
3962023fb5Ssyuu 
4062023fb5Ssyuu /*
4162023fb5Ssyuu  * mips-specific PCI structure and type definitions.
4262023fb5Ssyuu  * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
4362023fb5Ssyuu  */
4462023fb5Ssyuu struct mips_pci_chipset {
4562023fb5Ssyuu 	void		*pc_conf_v;
4662023fb5Ssyuu 	void		(*pc_attach_hook)(struct device *,
4762023fb5Ssyuu 			    struct device *, struct pcibus_attach_args *);
4862023fb5Ssyuu 	int		(*pc_bus_maxdevs)(void *, int);
4962023fb5Ssyuu 	pcitag_t	(*pc_make_tag)(void *, int, int, int);
5062023fb5Ssyuu 	void		(*pc_decompose_tag)(void *, pcitag_t, int *,
5162023fb5Ssyuu 			    int *, int *);
52b1926db3Smiod 	int		(*pc_conf_size)(void *, pcitag_t);
5362023fb5Ssyuu 	pcireg_t	(*pc_conf_read)(void *, pcitag_t, int);
5462023fb5Ssyuu 	void		(*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
5562023fb5Ssyuu 
5662023fb5Ssyuu 	void		*pc_intr_v;
572a48857dSvisa 	int		(*pc_intr_map)(struct pci_attach_args *,
582a48857dSvisa 			    pci_intr_handle_t *);
5962023fb5Ssyuu 	const char	*(*pc_intr_string)(void *, pci_intr_handle_t);
6062023fb5Ssyuu 	void		*(*pc_intr_establish)(void *, pci_intr_handle_t,
6162023fb5Ssyuu 			    int, int (*)(void *), void *, char *);
6262023fb5Ssyuu 	void		(*pc_intr_disestablish)(void *, void *);
6362023fb5Ssyuu };
6462023fb5Ssyuu 
6562023fb5Ssyuu /*
6662023fb5Ssyuu  * Functions provided to machine-independent PCI code.
6762023fb5Ssyuu  */
6862023fb5Ssyuu //#define DEBUG_PCI_CONF
6962023fb5Ssyuu 
7062023fb5Ssyuu #define	pci_attach_hook(p, s, pba)					\
7162023fb5Ssyuu     (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
7262023fb5Ssyuu #define	pci_bus_maxdevs(c, b)						\
7362023fb5Ssyuu     (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b))
7462023fb5Ssyuu #define	pci_make_tag(c, b, d, f)					\
7562023fb5Ssyuu     (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f))
7662023fb5Ssyuu #define	pci_decompose_tag(c, t, bp, dp, fp)				\
7762023fb5Ssyuu     (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
7862023fb5Ssyuu 
79b1926db3Smiod #define	pci_conf_size(c, t)						\
80b1926db3Smiod     (*(c)->pc_conf_size)((c)->pc_conf_v, (t))
812a48857dSvisa 
8262023fb5Ssyuu #ifdef DEBUG_PCI_CONF
832a48857dSvisa static inline pcireg_t
pci_conf_read_db(void * cookie,pcitag_t tag,int reg,const char * file,const char * func,int line)842a48857dSvisa pci_conf_read_db(void *cookie, pcitag_t tag, int reg,
852a48857dSvisa     const char *file, const char *func, int line)
8662023fb5Ssyuu {
872a48857dSvisa 	struct mips_pci_chipset *pc = cookie;
882a48857dSvisa 	pcireg_t val;
892a48857dSvisa 
902a48857dSvisa 	val = (*(pc)->pc_conf_read)(pc->pc_conf_v, tag, reg);
916b5c68f6Svisa 	printf("%s:%s:%d:pci_conf_read(%llx,%x) = %x\n", file, func, line,
922a48857dSvisa 	    tag, reg, val);
932a48857dSvisa 	return val;
9462023fb5Ssyuu }
9562023fb5Ssyuu 
962a48857dSvisa static inline void
pci_conf_write_db(void * cookie,pcitag_t tag,int reg,pcireg_t val,const char * file,const char * func,int line)972a48857dSvisa pci_conf_write_db(void *cookie, pcitag_t tag, int reg, pcireg_t val,
982a48857dSvisa     const char *file, const char *func, int line)
9962023fb5Ssyuu {
1002a48857dSvisa 	struct mips_pci_chipset *pc = cookie;
1012a48857dSvisa 
1026b5c68f6Svisa 	printf("%s:%s:%d:pci_conf_write(%llx,%x,%x)\n", file, func, line,
1032a48857dSvisa 	    tag, reg, val);
1042a48857dSvisa 	(*(pc)->pc_conf_write)(pc->pc_conf_v, tag, reg, val);
10562023fb5Ssyuu }
10662023fb5Ssyuu 
10762023fb5Ssyuu 
1082a48857dSvisa #define	pci_conf_read(c, t, r)						\
1092a48857dSvisa     pci_conf_read_db(c, t, r, __FILE__, __FUNCTION__, __LINE__)
1102a48857dSvisa #define	pci_conf_write(c, t, r, v)					\
1112a48857dSvisa     pci_conf_write_db(c, t, r, v, __FILE__, __FUNCTION__, __LINE__)
11262023fb5Ssyuu #else
11362023fb5Ssyuu #define	pci_conf_read(c, t, r)						\
11462023fb5Ssyuu     (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
11562023fb5Ssyuu #define	pci_conf_write(c, t, r, v)					\
11662023fb5Ssyuu   (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v))
11762023fb5Ssyuu #endif
11862023fb5Ssyuu #define	pci_intr_map(c, ihp)				\
11962023fb5Ssyuu     (*(c)->pa_pc->pc_intr_map)((c), (ihp))
12042e25420Skettenis #define	pci_intr_map_msi(c, ihp)	(-1)
121058ea912Skettenis #define	pci_intr_map_msix(c, vec, ihp)	(-1)
12262023fb5Ssyuu #define	pci_intr_string(c, ih)						\
12362023fb5Ssyuu     (*(c)->pc_intr_string)((c)->pc_intr_v, (ih))
12462023fb5Ssyuu #define	pci_intr_establish(c, ih, l, h, a, nm)				\
12562023fb5Ssyuu     (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a), (nm))
12662023fb5Ssyuu #define	pci_intr_disestablish(c, iv)					\
12762023fb5Ssyuu     (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv))
128121a46e8Smiod #define	pci_probe_device_hook(c, a)	(0)
12962023fb5Ssyuu 
1309a8f49f4Skettenis #define	pci_min_powerstate(c, t)	(PCI_PMCSR_STATE_D3)
13125b7ac45Smpi #define	pci_set_powerstate_md(c, t, s, p)
1329a8f49f4Skettenis 
13362023fb5Ssyuu #define	pci_dev_postattach(a, b)
134