1 /* $Id: sun-fb.h,v 1.4 2009/11/08 17:02:39 fredette Exp $ */
2 
3 /* machine/sun/sun-fb.h - header file for Sun framebuffer emulation: */
4 
5 /*
6  * Copyright (c) 2004, 2006 Matt Fredette
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed by Matt Fredette.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _MACHINE_SUN_FB_H
37 #define _MACHINE_SUN_FB_H
38 
39 #include <tme/common.h>
40 _TME_RCSID("$Id: sun-fb.h,v 1.4 2009/11/08 17:02:39 fredette Exp $");
41 
42 /* includes: */
43 #include <tme/generic/bus.h>
44 #include <tme/generic/bus-device.h>
45 #include <tme/generic/fb.h>
46 #include <tme/ic/bt458.h>
47 #include <tme/completion.h>
48 
49 /* macros: */
50 
51 /* Sun framebuffer sizes: */
52 /* NB: TME_SUNFB_SIZE_1152_900 should be first, since whatever size is
53    first is what most framebuffers will default to: */
54 #define TME_SUNFB_SIZE_NULL			(0)
55 #define TME_SUNFB_SIZE_1152_900			TME_BIT(0)
56 #define TME_SUNFB_SIZE_1024_1024		TME_BIT(1)
57 #define TME_SUNFB_SIZE_1280_1024		TME_BIT(2)
58 #define TME_SUNFB_SIZE_1600_1280		TME_BIT(3)
59 #define TME_SUNFB_SIZE_1440_1440		TME_BIT(4)
60 #define TME_SUNFB_SIZE_1024_768			TME_BIT(5)
61 #define TME_SUNFB_SIZE_640_480			TME_BIT(6)
62 
63 /* P4 register framebuffer identifiers: */
64 #define TME_SUNFB_P4_ID_MASK			(0xf0000000)
65 #define  TME_SUNFB_P4_ID_BWTWO			(0x00000000)
66 #define  TME_SUNFB_P4_ID_CGFOUR			(0x40000000)
67 #define  TME_SUNFB_P4_ID_CGEIGHT		(0x45000000)
68 #define  TME_SUNFB_P4_ID_CGSIX			(0x60000000)
69 
70 /* offsets in many P4 framebuffers: */
71 #define TME_SUNFB_P4_OFFSET_P4			(0x00000000)
72 #define TME_SUNFB_P4_OFFSET_BITMAP		(0x00100000)
73 
74 /* offsets in many S4 framebuffers: */
75 #define TME_SUNFB_S4_OFFSET_REGS		(0x00400000)
76 #define TME_SUNFB_S4_OFFSET_MEMORY		(0x00800000)
77 
78 /* flags: */
79 #define TME_SUNFB_FLAG_BT458_CMAP_PACKED	TME_BIT(0)
80 #define TME_SUNFB_FLAG_BT458_BYTE_D0_D7		(0)
81 #define TME_SUNFB_FLAG_BT458_BYTE_D24_D31	TME_BIT(1)
82 
83 /* callout flags: */
84 #define TME_SUNFB_CALLOUT_RUNNING		TME_BIT(0)
85 #define TME_SUNFB_CALLOUTS_MASK			(-2)
86 #define  TME_SUNFB_CALLOUT_MODE_CHANGE		TME_BIT(1)
87 #define	 TME_SUNFB_CALLOUT_INT			TME_BIT(2)
88 
89 /* the maximum number of bus subregions for registers that a Sun
90    framebuffer can have: */
91 #define TME_SUNFB_BUS_SUBREGIONS_MAX	(8)
92 
93 /* the log handle: */
94 #define TME_SUNFB_LOG_HANDLE(sunfb)		(&(sunfb)->tme_sunfb_element->tme_element_log_handle)
95 
96 #define TME_SUNFB_BUS_TRANSITION		(1)
97 
98 /* a Sun framebuffer: */
99 struct tme_sunfb {
100 
101   /* our simple bus device header: */
102   struct tme_bus_device tme_sunfb_device;
103 #define tme_sunfb_element tme_sunfb_device.tme_bus_device_element
104 
105   /* the mutex protecting the card: */
106   tme_mutex_t tme_sunfb_mutex;
107 
108   /* the rwlock protecting the card: */
109   tme_rwlock_t tme_sunfb_rwlock;
110 
111   /* the framebuffer connection: */
112   struct tme_fb_connection *tme_sunfb_fb_connection;
113 
114   /* more bus subregions: */
115   struct tme_bus_subregion tme_sunfb_bus_subregions[TME_SUNFB_BUS_SUBREGIONS_MAX];
116 
117   /* bus cycle handlers for the subregions: */
118   tme_bus_cycle_handler tme_sunfb_bus_handlers[TME_SUNFB_BUS_SUBREGIONS_MAX];
119 
120   /* some of the bus subregions have specific purposes: */
121 #define tme_sunfb_bus_subregion_memory tme_sunfb_device.tme_bus_device_subregions
122 #define tme_sunfb_bus_subregion_regs tme_sunfb_bus_subregions[0]
123 #define tme_sunfb_bus_handler_regs tme_sunfb_bus_handlers[0]
124 
125   /* the class of the framebuffer: */
126   unsigned int tme_sunfb_class;
127 
128   /* the depth of the framebuffer: */
129   unsigned int tme_sunfb_depth;
130 
131   /* the size of the framebuffer: */
132   tme_uint32_t tme_sunfb_size;
133 
134   /* framebuffer flags: */
135   tme_uint32_t tme_sunfb_flags;
136 
137   /* the callout flags: */
138   int tme_sunfb_callout_flags;
139 
140   /* this is nonzero if the interrupt is asserted: */
141   int tme_sunfb_int_asserted;
142 
143   /* the callout thread condition: */
144   tme_cond_t tme_sunfb_callout_cond;
145 
146   /* the (relative) bus address of the last byte of displayed
147      framebuffer memory: */
148   tme_bus_addr32_t tme_sunfb_memory_address_last_displayed;
149 
150   /* the memory.  usually, this memory is displayed directly, but this
151      won't be the case when there is an overlay plane, for example: */
152   tme_uint8_t *tme_sunfb_memory;
153 
154   /* any memory pad: */
155   tme_uint8_t *tme_sunfb_memory_pad;
156 
157   /* a framebuffer memory update function: */
158   int (*tme_sunfb_memory_update)(struct tme_fb_connection *conn_fb);
159 
160   /* this forces the next update to be a full one: */
161   void (*tme_sunfb_update_full) _TME_P((struct tme_sunfb *));
162 
163   /* the token for one outstanding writable TLB entry: */
164   struct tme_token *tme_sunfb_tlb_token;
165 
166   /* the offsets of the first and last bytes updated in the real
167      framebuffer memory: */
168   tme_uint32_t tme_sunfb_offset_updated_first;
169   tme_uint32_t tme_sunfb_offset_updated_last;
170 
171   /* these are used for index-mapping pixel values or pixel subfield
172      values to intensities, or vice-versa.  if these are NULL,
173      everything is linearly mapped: */
174   void *tme_sunfb_cmap_primaries[3];
175 #define tme_sunfb_cmap_g tme_sunfb_cmap_primaries[0]
176 #define tme_sunfb_cmap_r tme_sunfb_cmap_primaries[1]
177 #define tme_sunfb_cmap_b tme_sunfb_cmap_primaries[2]
178 
179   /* a P4 register: */
180   tme_uint32_t tme_sunfb_p4;
181 
182   /* many Sun 8-bit framebuffers use the Brooktree Bt458 RAMDAC: */
183   struct tme_bt458 tme_sunfb_bt458;
184 
185   /* S4 basic registers: */
186   struct {
187     tme_uint8_t tme_sunfb_s4_regs_control;
188 #define tme_sunfb_s4_regs_first tme_sunfb_s4_regs_control
189     tme_uint8_t tme_sunfb_s4_regs_status;
190     tme_uint8_t tme_sunfb_s4_regs_cursor_start;
191     tme_uint8_t tme_sunfb_s4_regs_cursor_end;
192     tme_uint8_t tme_sunfb_s4_regs_h_blank_set;
193     tme_uint8_t tme_sunfb_s4_regs_h_blank_clear;
194     tme_uint8_t tme_sunfb_s4_regs_h_sync_set;
195     tme_uint8_t tme_sunfb_s4_regs_h_sync_clear;
196     tme_uint8_t tme_sunfb_s4_regs_comp_sync_clear;
197     tme_uint8_t tme_sunfb_s4_regs_v_blank_set_high;
198     tme_uint8_t tme_sunfb_s4_regs_v_blank_set_low;
199     tme_uint8_t tme_sunfb_s4_regs_v_blank_clear;
200     tme_uint8_t tme_sunfb_s4_regs_v_sync_set;
201     tme_uint8_t tme_sunfb_s4_regs_v_sync_clear;
202     tme_uint8_t tme_sunfb_s4_regs_xfer_holdoff_set;
203     tme_uint8_t tme_sunfb_s4_regs_xfer_holdoff_clear;
204   } tme_sunfb_s4_regs;
205 
206   /* if the given type is valid, it returns NULL and updates the
207      framebuffer structure, else it returns a string of valid types: */
208   const char *(*tme_sunfb_type_set) _TME_P((struct tme_sunfb *, const char *));
209 
210   /* any interrupt signal: */
211   tme_uint32_t tme_sunfb_bus_signal_int;
212 };
213 
214 /* prototypes: */
215 
216 /* miscellaneous: */
217 tme_uint32_t tme_sunfb_size _TME_P((const char *));
218 tme_uint32_t tme_sunfb_size_width _TME_P((tme_uint32_t));
219 tme_uint32_t tme_sunfb_size_height _TME_P((tme_uint32_t));
220 
221 /* this creates a new Sun framebuffer: */
222 int tme_sunfb_new(struct tme_sunfb *sunfb, const char * const *args, char **_output);
223 
224 /* some standard register bus cycle handlers: */
225 int tme_sunfb_bus_cycle_p4 _TME_P((void *, struct tme_bus_cycle *));
226 int tme_sunfb_bus_cycle_s4 _TME_P((void *, struct tme_bus_cycle *));
227 int tme_sunfb_bus_cycle_bt458 _TME_P((void *, struct tme_bus_cycle *));
228 
229 /* this is called before the framebuffer's display is updated: */
230 int tme_sunfb_memory_update _TME_P((struct tme_fb_connection *));
231 
232 #if TME_SUNFB_BUS_TRANSITION
233 
234 /* this is the bus cycle transition glue: */
235 struct tme_completion;
236 int tme_sunfb_bus_cycle_transition _TME_P((void *,
237 					   struct tme_bus_cycle *,
238 					   void (*) _TME_P((struct tme_sunfb *,
239 							    struct tme_bus_cycle *,
240 							    tme_uint32_t *,
241 							    struct tme_completion *))));
242 
243 #endif /* TME_SUNFB_BUS_TRANSITION */
244 
245 #endif /* !_MACHINE_SUN_FB_H */
246