1 /*        $NetBSD: sticreg.h,v 1.9 2008/09/08 23:36:54 gmcgarry Exp $ */
2 
3 /*-
4  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Andrew Doran.
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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _TC_STICREG_H_
33 #define   _TC_STICREG_H_
34 
35 /*
36  * PixelStamp command packets take this general format:
37  *
38  * command word
39  * plane mask & primitive count
40  * always zero
41  * update method
42  *
43  * per-packet context (optional):
44  *      line width
45  *      xy mask
46  *        cliping rectangle min & max
47  *        rgb constant
48  *        z constant
49  *
50  * per-primitive context (optional):
51  *      xy mask
52  *      xy mask address
53  *      primitive data (vertices, spans info, video)
54  *      line width
55  *      halfspace equals conditions
56  *      rgb flat, or rgb{1,2,3} smooth
57  *      z flat, or z{1,2,3} smooth
58  */
59 
60 /*
61  * Command word.
62  */
63 
64 /* Base command */
65 #define   STAMP_CMD_POINTS        (0x0000)
66 #define   STAMP_CMD_LINES         (0x0001)
67 #define   STAMP_CMD_TRIANGLES     (0x0002)
68 #define   STAMP_CMD_COPYSPANS     (0x0005)
69 #define   STAMP_CMD_READSPANS     (0x0006)
70 #define   STAMP_CMD_WRITESPANS    (0x0007)
71 #define   STAMP_CMD_VIDEO         (0x0008)
72 
73 /* Color */
74 #define   STAMP_RGB_NONE          (0x0000)
75 #define   STAMP_RGB_CONST         (0x0010)
76 #define   STAMP_RGB_FLAT          (0x0020)
77 #define   STAMP_RGB_SMOOTH        (0x0030)
78 
79 /* Z */
80 #define   STAMP_Z_NONE            (0x0000)
81 #define   STAMP_Z_CONST           (0x0040)
82 #define   STAMP_Z_FLAT            (0x0080)
83 #define   STAMP_Z_SMOOTH          (0x00c0)
84 
85 /* XYMASK */
86 #define   STAMP_XY_NONE           (0x0000)
87 #define   STAMP_XY_PERPACKET      (0x0100)
88 #define   STAMP_XY_PERPRIMATIVE   (0x0200)
89 
90 /* Line width */
91 #define   STAMP_LW_NONE           (0x0000)
92 #define   STAMP_LW_PERPACKET      (0x0400)
93 #define   STAMP_LW_PERPRIMATIVE   (0x0800)
94 
95 /* Miscellaneous flags */
96 #define   STAMP_CLIPRECT          (0x00080000)
97 #define   STAMP_MESH              (0x00200000)
98 #define   STAMP_AALINE            (0x00800000)
99 #define   STAMP_HS_EQUALS         (0x80000000)
100 
101 /*
102  * Update word.
103  */
104 
105 /* XXX What does this do? Perhaps for 96-bit boards? */
106 #define   STAMP_PLANE_8X3               (0 << 5)
107 #define   STAMP_PLANE_24                (1 << 5)
108 
109 /* Write enable */
110 #define   STAMP_WE_SIGN                 (0x04 << 8)
111 #define   STAMP_WE_XYMASK               (0x02 << 8)
112 #define   STAMP_WE_CLIPRECT   (0x01 << 8)
113 #define   STAMP_WE_NONE                 (0x00 << 8)
114 
115 /* Pixel write method */
116 #define   STAMP_METHOD_CLEAR  (0x60 << 12)
117 #define   STAMP_METHOD_AND    (0x14 << 12)
118 #define   STAMP_METHOD_ANDREV (0x15 << 12)
119 #define   STAMP_METHOD_COPY   (0x20 << 12)
120 #define   STAMP_METHOD_ANDINV (0x16 << 12)
121 #define   STAMP_METHOD_NOOP   (0x40 << 12)
122 #define   STAMP_METHOD_XOR    (0x11 << 12)
123 #define   STAMP_METHOD_OR               (0x0f << 12)
124 #define   STAMP_METHOD_NOR    (0x17 << 12)
125 #define   STAMP_METHOD_EQUIV  (0x10 << 12)
126 #define   STAMP_METHOD_INV    (0x4e << 12)
127 #define   STAMP_METHOD_ORREV  (0x0e << 12)
128 #define   STAMP_METHOD_COPYINV          (0x2d << 12)
129 #define   STAMP_METHOD_ORINV  (0x0d << 12)
130 #define   STAMP_METHOD_NAND   (0x0c << 12)
131 #define   STAMP_METHOD_SET    (0x6c << 12)
132 #define   STAMP_METHOD_SUM    (0x00 << 12)
133 #define   STAMP_METHOD_DIFF   (0x02 << 12)
134 #define   STAMP_METHOD_REVDIFF          (0x01 << 12)
135 
136 /* Double buffering */
137 #define   STAMP_DB_NONE                 (0x00 << 28)
138 #define   STAMP_DB_01                   (0x01 << 28)
139 #define   STAMP_DB_12                   (0x02 << 28)
140 #define   STAMP_DB_02                   (0x04 << 28)
141 
142 /* Miscellaneous flags */
143 #define   STAMP_UPDATE_ENABLE (1 << 0)
144 #define   STAMP_SAVE_SIGN               (1 << 6)
145 #define   STAMP_SAVE_ALPHA    (1 << 7)
146 #define   STAMP_SUPERSAMPLE   (1 << 11)
147 #define   STAMP_SPAN                    (1 << 19)
148 #define   STAMP_COPYSPAN_ALIGNED        (1 << 20)
149 #define   STAMP_MINMAX                  (1 << 21)
150 #define   STAMP_MULT                    (1 << 22)
151 #define   STAMP_MULTACC                 (1 << 23)
152 #define   STAMP_HALF_BUFF               (1 << 27)
153 #define   STAMP_INITIALIZE    (1 << 31)
154 
155 /*
156  * XYMASK address calculation.
157  */
158 #define   XMASKADDR(sw, sx, a)          (((a)-((sx) % (sw))) & 15)
159 #define   YMASKADDR(shm, sy, b)         (((b)-((sy) & (shm))) & 15)
160 #define   XYMASKADDR(sw,shm,x,y,a,b)    \
161     (XMASKADDR(sw,x,a) << 16 | YMASKADDR(shm,y,b))
162 
163 /*
164  * Miscellenous constants.
165  */
166 #define   STIC_MAGIC_X        370
167 #define   STIC_MAGIC_Y        37
168 
169 /*
170  * Poll register magic values.
171  */
172 #define   STAMP_OK            (0)
173 #define   STAMP_BUSY                    (1)
174 #define   STAMP_RETRIES                 (100000)
175 #define   STAMP_DELAY                   (10)
176 
177 /*
178  * STIC registers.
179  */
180 struct stic_regs {
181           u_int32_t sr_pad0;
182           u_int32_t sr_pad1;
183           u_int32_t sr_hsync;
184           u_int32_t sr_hsync2;
185           u_int32_t sr_hblank;
186           u_int32_t sr_vsync;
187           u_int32_t sr_vblank;
188           u_int32_t sr_vtest;
189           u_int32_t sr_ipdvint;
190           u_int32_t sr_pad2;
191           u_int32_t sr_sticsr;
192           u_int32_t sr_busdat;
193           u_int32_t sr_busadr;
194           u_int32_t sr_pad3;
195           u_int32_t sr_buscsr;
196           u_int32_t sr_modcl;
197 } __packed;
198 
199 /*
200  * Bit definitions for stic_regs::sticsr.
201  */
202 #define   STIC_CSR_TSTFNC               0x00000003
203 # define STIC_CSR_TSTFNC_NORMAL         0
204 # define STIC_CSR_TSTFNC_PARITY         1
205 # define STIC_CSR_TSTFNC_CNTPIX         2
206 # define STIC_CSR_TSTFNC_TSTDAC         3
207 #define   STIC_CSR_CHECKPAR   0x00000004
208 #define   STIC_CSR_STARTVT    0x00000010
209 #define   STIC_CSR_START                0x00000020
210 #define   STIC_CSR_RESET                0x00000040
211 #define   STIC_CSR_STARTST    0x00000080
212 
213 /*
214  * Bit definitions for stic_regs::int.  Three four-bit wide fields, for
215  * error (E), vertical-blank (V), and packet-done (P) intererupts,
216  * respectively.  The low-order three bits of each field are interrupt
217  * enable, condition flagged, and nybble write enable.  The top bit of each
218  * field is unused.
219  */
220 #define   STIC_INT_E_EN                 0x00000001
221 #define   STIC_INT_E                    0x00000002
222 #define   STIC_INT_E_WE                 0x00000004
223 
224 #define   STIC_INT_V_EN                 0x00000100
225 #define   STIC_INT_V                    0x00000200
226 #define   STIC_INT_V_WE                 0x00000400
227 
228 #define   STIC_INT_P_EN                 0x00010000
229 #define   STIC_INT_P                    0x00020000
230 #define   STIC_INT_P_WE                 0x00040000
231 
232 #define   STIC_INT_E_MASK     (STIC_INT_E_EN | STIC_INT_E | STIC_INT_E_WE)
233 #define   STIC_INT_V_MASK     (STIC_INT_V_EN | STIC_INT_V | STIC_INT_V_WE)
234 #define   STIC_INT_P_MASK     (STIC_INT_P_EN | STIC_INT_P | STIC_INT_P_WE)
235 #define   STIC_INT_MASK       (STIC_INT_E_MASK | STIC_INT_P_MASK | STIC_INT_V_MASK)
236 
237 #define   STIC_INT_WE         (STIC_INT_E_WE | STIC_INT_V_WE | STIC_INT_P_WE)
238 #define   STIC_INT_CLR        (STIC_INT_E_EN | STIC_INT_V_EN | STIC_INT_P_EN)
239 
240 /*
241  * On DMA: reading from a STIC poll register causes load & execution of
242  * the packet at the correspoinding physical address.  Either STAMP_OK
243  * or STAMP_BUSY will be returned to indicate status.
244  *
245  * The STIC sees only 23-bits (8MB) of address space.  Bits 21-22 in
246  * physical address space map to bits 27-28, and bits 15-20 map to bits
247  * 18-23 in the STIC's warped view of the word.  On the PXG, the STIC
248  * sees only the onboard SRAM (so any `physical addresses' are offsets
249  * into the beginning of the SRAM).
250  */
251 
252 #endif    /* _TC_STICREG_H_ */
253