xref: /openbsd/sys/arch/sparc64/dev/psychovar.h (revision 0af614b4)
1 /*	$OpenBSD: psychovar.h,v 1.8 2019/12/05 12:46:54 mpi Exp $	*/
2 /*	$NetBSD: psychovar.h,v 1.6 2001/07/20 00:07:13 eeh Exp $	*/
3 
4 /*
5  * Copyright (c) 1999, 2000 Matthew R. Green
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef _SPARC64_DEV_PSYCHOVAR_H_
31 #define _SPARC64_DEV_PSYCHOVAR_H_
32 
33 /* per real PCI bus info */
34 struct psycho_softc;
35 
36 struct psycho_pbm {
37 	/* link to mum */
38 	struct psycho_softc		*pp_sc;
39 
40 	/*
41 	 * note that the sabre really only has one ranges property,
42 	 * used for both simba a and simba b (but the ranges for
43 	 * real psychos are the same for PCI A and PCI B anyway).
44 	 */
45 	struct psycho_registers		*pp_regs;
46 	struct psycho_ranges		*pp_range;
47 
48 	/* counts of above */
49 	int				pp_nregs;
50 	int				pp_nrange;
51 	int				pp_nintmap;
52 
53 	/* PCI Bus Module A or PCI Bus Module B */
54 	int				pp_id;
55 #define PSYCHO_PBM_UNKNOWN	0
56 #define PSYCHO_PBM_A		1
57 #define PSYCHO_PBM_B		2
58 
59 	/* chipset tag for this instance */
60 	pci_chipset_tag_t		pp_pc;
61 
62 	/* our tags */
63 	bus_space_tag_t			pp_memt;
64 	bus_space_tag_t			pp_iot;
65 	bus_dma_tag_t			pp_dmat;
66 	int				pp_bus;
67 	int				pp_flags;
68 
69 	/* and pointers into the psycho regs for our bits */
70 	bus_space_handle_t		pp_pcictl;
71 	struct strbuf_ctl		pp_sb;
72 	/* area we can use for flushing our streaming buffer */
73 	char				pp_flush[0x80];
74 };
75 
76 /*
77  * per-PCI bus on mainbus softc structure; one for sabre, or two
78  * per pair of psycho's.
79  */
80 struct psycho_softc {
81 	struct	device			sc_dev;
82 
83 	/*
84 	 * one sabre has two simba's.  psycho's are separately attached,
85 	 * with the `other' psycho_pbm allocated at the first's attach.
86 	 */
87 	struct psycho_pbm		*__sc_psycho_this;
88 	struct psycho_pbm		*__sc_psycho_other;
89 #define	sc_psycho_this	__sc_psycho_this
90 #define	sc_psycho_other	__sc_psycho_other
91 
92 	/*
93 	 * PSYCHO register.  we record the base physical address of these
94 	 * also as it is the base of the entire PSYCHO
95 	 */
96 	bus_space_handle_t		sc_regsh;
97 	bus_space_handle_t		sc_pcictl;
98 	paddr_t				sc_basepaddr;
99 
100 	/* Interrupt Group Number for this device */
101 	int				sc_ign;
102 
103 	/* our tags (from parent) */
104 	bus_space_tag_t			sc_bustag;
105 	bus_dma_tag_t			sc_dmatag;
106 
107 	/* config space */
108 	bus_space_tag_t			sc_configtag;
109 	bus_space_handle_t		sc_configaddr;
110 
111 	int				sc_clockfreq;
112 	int				sc_node;	/* prom node */
113 	int				sc_mode;	/* (whatareya?) */
114 #define	PSYCHO_MODE_SABRE	1	/* i'm a sabre (yob) */
115 #define	PSYCHO_MODE_PSYCHO	2	/* i'm a psycho (w*nker) */
116 #define	PSYCHO_MODE_CMU_CH	3	/* i'm a CMU-CH (castrate) */
117 
118 	struct iommu_state		*sc_is;
119 };
120 
121 /* config space is per-psycho.  mem/io/dma are per-pci bus */
122 bus_dma_tag_t psycho_alloc_dma_tag(struct psycho_pbm *);
123 
124 bus_space_tag_t psycho_alloc_mem_tag(struct psycho_pbm *);
125 bus_space_tag_t psycho_alloc_io_tag(struct psycho_pbm *);
126 bus_space_tag_t psycho_alloc_config_tag(struct psycho_pbm *);
127 
128 /* uperf attachment to psycho's */
129 struct uperf_psycho_attach_args {
130 	char *upaa_name;
131 	struct perfmon *upaa_regs;
132 };
133 
134 #define psycho_psychoreg_read(sc, reg)				\
135 	bus_space_read_8((sc)->sc_bustag, (sc)->sc_regsh,	\
136 	    offsetof(struct psychoreg, reg))
137 
138 #define psycho_psychoreg_write(sc, reg, v)			\
139 	bus_space_write_8((sc)->sc_bustag, (sc)->sc_regsh,	\
140 	    offsetof(struct psychoreg, reg), (v))
141 
142 #define psycho_psychoreg_vaddr(sc, reg)				\
143         (bus_space_vaddr((sc)->sc_bustag, (sc)->sc_regsh) +	\
144                 offsetof(struct psychoreg, reg))
145 
146 #define psycho_pcictl_read(sc, reg)				\
147 	bus_space_read_8((sc)->sc_bustag, (sc)->sc_pcictl,	\
148 	     offsetof(struct pci_ctl, reg))
149 
150 #define psycho_pcictl_write(sc, reg, v)	\
151 	bus_space_write_8((sc)->sc_bustag, (sc)->sc_pcictl,	\
152 	    offsetof(struct pci_ctl, reg), (v))
153 
154 #endif /* _SPARC64_DEV_PSYCHOVAR_H_ */
155