• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef STICORE_H
2 #define STICORE_H
3 
4 /* generic STI structures & functions */
5 
6 #if 0
7 #define DPRINTK(x)	printk x
8 #else
9 #define DPRINTK(x)
10 #endif
11 
12 #define MAX_STI_ROMS 4		/* max no. of ROMs which this driver handles */
13 
14 #define STI_REGION_MAX 8	/* hardcoded STI constants */
15 #define STI_DEV_NAME_LENGTH 32
16 #define STI_MONITOR_MAX 256
17 
18 #define STI_FONT_HPROMAN8 1
19 #define STI_FONT_KANA8 2
20 
21 #define ALT_CODE_TYPE_UNKNOWN 0x00	/* alt code type values */
22 #define ALT_CODE_TYPE_PA_RISC_64 0x01
23 
24 /* The latency of the STI functions cannot really be reduced by setting
25  * this to 0;  STI doesn't seem to be designed to allow calling a different
26  * function (or the same function with different arguments) after a
27  * function exited with 1 as return value.
28  *
29  * As all of the functions below could be called from interrupt context,
30  * we have to spin_lock_irqsave around the do { ret = bla(); } while(ret==1)
31  * block.  Really bad latency there.
32  *
33  * Probably the best solution to all this is have the generic code manage
34  * the screen buffer and a kernel thread to call STI occasionally.
35  *
36  * Luckily, the frame buffer guys have the same problem so we can just wait
37  * for them to fix it and steal their solution.   prumpf
38  */
39 
40 #include <asm/io.h>
41 
42 #define STI_WAIT 1
43 
44 #define STI_PTR(p)	( virt_to_phys(p) )
45 #define PTR_STI(p)	( phys_to_virt((unsigned long)p) )
46 
47 #define sti_onscreen_x(sti) (sti->glob_cfg->onscreen_x)
48 #define sti_onscreen_y(sti) (sti->glob_cfg->onscreen_y)
49 
50 /* sti_font_xy() use the native font ROM ! */
51 #define sti_font_x(sti) (PTR_STI(sti->font)->width)
52 #define sti_font_y(sti) (PTR_STI(sti->font)->height)
53 
54 #ifdef CONFIG_64BIT
55 #define STI_LOWMEM	(GFP_KERNEL | GFP_DMA)
56 #else
57 #define STI_LOWMEM	(GFP_KERNEL)
58 #endif
59 
60 
61 /* STI function configuration structs */
62 
63 typedef union region {
64 	struct {
65 		u32 offset	: 14;	/* offset in 4kbyte page */
66 		u32 sys_only	: 1;	/* don't map to user space */
67 		u32 cache	: 1;	/* map to data cache */
68 		u32 btlb	: 1;	/* map to block tlb */
69 		u32 last	: 1;	/* last region in list */
70 		u32 length	: 14;	/* length in 4kbyte page */
71 	} region_desc;
72 
73 	u32 region;			/* complete region value */
74 } region_t;
75 
76 #define REGION_OFFSET_TO_PHYS( rt, hpa ) \
77 	(((rt).region_desc.offset << 12) + (hpa))
78 
79 struct sti_glob_cfg_ext {
80 	 u8 curr_mon;			/* current monitor configured */
81 	 u8 friendly_boot;		/* in friendly boot mode */
82 	s16 power;			/* power calculation (in Watts) */
83 	s32 freq_ref;			/* frequency reference */
84 	u32 sti_mem_addr;		/* pointer to global sti memory (size=sti_mem_request) */
85 	u32 future_ptr; 		/* pointer to future data */
86 };
87 
88 struct sti_glob_cfg {
89 	s32 text_planes;		/* number of planes used for text */
90 	s16 onscreen_x;			/* screen width in pixels */
91 	s16 onscreen_y;			/* screen height in pixels */
92 	s16 offscreen_x;		/* offset width in pixels */
93 	s16 offscreen_y;		/* offset height in pixels */
94 	s16 total_x;			/* frame buffer width in pixels */
95 	s16 total_y;			/* frame buffer height in pixels */
96 	u32 region_ptrs[STI_REGION_MAX]; /* region pointers */
97 	s32 reent_lvl;			/* storage for reentry level value */
98 	u32 save_addr;			/* where to save or restore reentrant state */
99 	u32 ext_ptr;			/* pointer to extended glob_cfg data structure */
100 };
101 
102 
103 /* STI init function structs */
104 
105 struct sti_init_flags {
106 	u32 wait : 1;		/* should routine idle wait or not */
107 	u32 reset : 1;		/* hard reset the device? */
108 	u32 text : 1;		/* turn on text display planes? */
109 	u32 nontext : 1;	/* turn on non-text display planes? */
110 	u32 clear : 1;		/* clear text display planes? */
111 	u32 cmap_blk : 1;	/* non-text planes cmap black? */
112 	u32 enable_be_timer : 1; /* enable bus error timer */
113 	u32 enable_be_int : 1;	/* enable bus error timer interrupt */
114 	u32 no_chg_tx : 1;	/* don't change text settings */
115 	u32 no_chg_ntx : 1;	/* don't change non-text settings */
116 	u32 no_chg_bet : 1;	/* don't change berr timer settings */
117 	u32 no_chg_bei : 1;	/* don't change berr int settings */
118 	u32 init_cmap_tx : 1;	/* initialize cmap for text planes */
119 	u32 cmt_chg : 1;	/* change current monitor type */
120 	u32 retain_ie : 1;	/* don't allow reset to clear int enables */
121 	u32 caller_bootrom : 1;	/* set only by bootrom for each call */
122 	u32 caller_kernel : 1;	/* set only by kernel for each call */
123 	u32 caller_other : 1;	/* set only by non-[BR/K] caller */
124 	u32 pad	: 14;		/* pad to word boundary */
125 	u32 future_ptr; 	/* pointer to future data */
126 };
127 
128 struct sti_init_inptr_ext {
129 	u8  config_mon_type;	/* configure to monitor type */
130 	u8  pad[1];		/* pad to word boundary */
131 	u16 inflight_data;	/* inflight data possible on PCI */
132 	u32 future_ptr; 	/* pointer to future data */
133 };
134 
135 struct sti_init_inptr {
136 	s32 text_planes;	/* number of planes to use for text */
137 	u32 ext_ptr;		/* pointer to extended init_graph inptr data structure*/
138 };
139 
140 
141 struct sti_init_outptr {
142 	s32 errno;		/* error number on failure */
143 	s32 text_planes;	/* number of planes used for text */
144 	u32 future_ptr; 	/* pointer to future data */
145 };
146 
147 
148 
149 /* STI configuration function structs */
150 
151 struct sti_conf_flags {
152 	u32 wait : 1;		/* should routine idle wait or not */
153 	u32 pad : 31;		/* pad to word boundary */
154 	u32 future_ptr; 	/* pointer to future data */
155 };
156 
157 struct sti_conf_inptr {
158 	u32 future_ptr; 	/* pointer to future data */
159 };
160 
161 struct sti_conf_outptr_ext {
162 	u32 crt_config[3];	/* hardware specific X11/OGL information */
163 	u32 crt_hdw[3];
164 	u32 future_ptr;
165 };
166 
167 struct sti_conf_outptr {
168 	s32 errno;		/* error number on failure */
169 	s16 onscreen_x;		/* screen width in pixels */
170 	s16 onscreen_y;		/* screen height in pixels */
171 	s16 offscreen_x;	/* offscreen width in pixels */
172 	s16 offscreen_y;	/* offscreen height in pixels */
173 	s16 total_x;		/* frame buffer width in pixels */
174 	s16 total_y;		/* frame buffer height in pixels */
175 	s32 bits_per_pixel;	/* bits/pixel device has configured */
176 	s32 bits_used;		/* bits which can be accessed */
177 	s32 planes;		/* number of fb planes in system */
178 	 u8 dev_name[STI_DEV_NAME_LENGTH]; /* null terminated product name */
179 	u32 attributes;		/* flags denoting attributes */
180 	u32 ext_ptr;		/* pointer to future data */
181 };
182 
183 struct sti_rom {
184 	 u8 type[4];
185 	 u8 res004;
186 	 u8 num_mons;
187 	 u8 revno[2];
188 	u32 graphics_id[2];
189 
190 	u32 font_start;
191 	u32 statesize;
192 	u32 last_addr;
193 	u32 region_list;
194 
195 	u16 reentsize;
196 	u16 maxtime;
197 	u32 mon_tbl_addr;
198 	u32 user_data_addr;
199 	u32 sti_mem_req;
200 
201 	u32 user_data_size;
202 	u16 power;
203 	 u8 bus_support;
204 	 u8 ext_bus_support;
205 	 u8 alt_code_type;
206 	 u8 ext_dd_struct[3];
207 	u32 cfb_addr;
208 
209 	u32 init_graph;
210 	u32 state_mgmt;
211 	u32 font_unpmv;
212 	u32 block_move;
213 	u32 self_test;
214 	u32 excep_hdlr;
215 	u32 inq_conf;
216 	u32 set_cm_entry;
217 	u32 dma_ctrl;
218 	 u8 res040[7 * 4];
219 
220 	u32 init_graph_addr;
221 	u32 state_mgmt_addr;
222 	u32 font_unp_addr;
223 	u32 block_move_addr;
224 	u32 self_test_addr;
225 	u32 excep_hdlr_addr;
226 	u32 inq_conf_addr;
227 	u32 set_cm_entry_addr;
228 	u32 image_unpack_addr;
229 	u32 pa_risx_addrs[7];
230 };
231 
232 struct sti_rom_font {
233 	u16 first_char;
234 	u16 last_char;
235 	 u8 width;
236 	 u8 height;
237 	 u8 font_type;		/* language type */
238 	 u8 bytes_per_char;
239 	u32 next_font;
240 	 u8 underline_height;
241 	 u8 underline_pos;
242 	 u8 res008[2];
243 };
244 
245 /* sticore internal font handling */
246 
247 struct sti_cooked_font {
248         struct sti_rom_font *raw;
249 	struct sti_cooked_font *next_font;
250 };
251 
252 struct sti_cooked_rom {
253         struct sti_rom *raw;
254 	struct sti_cooked_font *font_start;
255 };
256 
257 /* STI font printing function structs */
258 
259 struct sti_font_inptr {
260 	u32 font_start_addr;	/* address of font start */
261 	s16 index;		/* index into font table of character */
262 	u8 fg_color;		/* foreground color of character */
263 	u8 bg_color;		/* background color of character */
264 	s16 dest_x;		/* X location of character upper left */
265 	s16 dest_y;		/* Y location of character upper left */
266 	u32 future_ptr; 	/* pointer to future data */
267 };
268 
269 struct sti_font_flags {
270 	u32 wait : 1;		/* should routine idle wait or not */
271 	u32 non_text : 1;	/* font unpack/move in non_text planes =1, text =0 */
272 	u32 pad : 30;		/* pad to word boundary */
273 	u32 future_ptr; 	/* pointer to future data */
274 };
275 
276 struct sti_font_outptr {
277 	s32 errno;		/* error number on failure */
278 	u32 future_ptr; 	/* pointer to future data */
279 };
280 
281 /* STI blockmove structs */
282 
283 struct sti_blkmv_flags {
284 	u32 wait : 1;		/* should routine idle wait or not */
285 	u32 color : 1;		/* change color during move? */
286 	u32 clear : 1;		/* clear during move? */
287 	u32 non_text : 1;	/* block move in non_text planes =1, text =0 */
288 	u32 pad : 28;		/* pad to word boundary */
289 	u32 future_ptr; 	/* pointer to future data */
290 };
291 
292 struct sti_blkmv_inptr {
293 	u8 fg_color;		/* foreground color after move */
294 	u8 bg_color;		/* background color after move */
295 	s16 src_x;		/* source upper left pixel x location */
296 	s16 src_y;		/* source upper left pixel y location */
297 	s16 dest_x;		/* dest upper left pixel x location */
298 	s16 dest_y;		/* dest upper left pixel y location */
299 	s16 width;		/* block width in pixels */
300 	s16 height;		/* block height in pixels */
301 	u32 future_ptr; 	/* pointer to future data */
302 };
303 
304 struct sti_blkmv_outptr {
305 	s32 errno;		/* error number on failure */
306 	u32 future_ptr; 	/* pointer to future data */
307 };
308 
309 
310 /* sti_all_data is an internal struct which needs to be allocated in
311  * low memory (< 4GB) if STI is used with 32bit STI on a 64bit kernel */
312 
313 struct sti_all_data {
314 	struct sti_glob_cfg glob_cfg;
315 	struct sti_glob_cfg_ext glob_cfg_ext;
316 
317 	struct sti_conf_inptr		inq_inptr;
318 	struct sti_conf_outptr		inq_outptr; /* configuration */
319 	struct sti_conf_outptr_ext	inq_outptr_ext;
320 
321 	struct sti_init_inptr_ext	init_inptr_ext;
322 	struct sti_init_inptr		init_inptr;
323 	struct sti_init_outptr		init_outptr;
324 
325 	struct sti_blkmv_inptr		blkmv_inptr;
326 	struct sti_blkmv_outptr		blkmv_outptr;
327 
328 	struct sti_font_inptr		font_inptr;
329 	struct sti_font_outptr		font_outptr;
330 
331 	/* leave as last entries */
332 	unsigned long save_addr[1024 / sizeof(unsigned long)];
333 	   /* min 256 bytes which is STI default, max sti->sti_mem_request */
334 	unsigned long sti_mem_addr[256 / sizeof(unsigned long)];
335 	/* do not add something below here ! */
336 };
337 
338 /* internal generic STI struct */
339 
340 struct sti_struct {
341 	spinlock_t lock;
342 
343 	/* the following fields needs to be filled in by the word/byte routines */
344 	int font_width;
345 	int font_height;
346 	/* char **mon_strings; */
347 	int sti_mem_request;
348 	u32 graphics_id[2];
349 
350 	struct sti_cooked_rom *rom;
351 
352 	unsigned long font_unpmv;
353 	unsigned long block_move;
354 	unsigned long init_graph;
355 	unsigned long inq_conf;
356 
357 	/* all following fields are initialized by the generic routines */
358 	int text_planes;
359 	region_t regions[STI_REGION_MAX];
360 	unsigned long regions_phys[STI_REGION_MAX];
361 
362 	struct sti_glob_cfg *glob_cfg;	/* points into sti_all_data */
363 
364 	struct sti_cooked_font *font;	/* ptr to selected font (cooked) */
365 
366 	struct pci_dev *pd;
367 
368 	/* PCI data structures (pg. 17ff from sti.pdf) */
369 	u8 rm_entry[16]; /* pci region mapper array == pci config space offset */
370 
371 	/* pointer to the fb_info where this STI device is used */
372 	struct fb_info *info;
373 
374 	/* pointer to all internal data */
375 	struct sti_all_data *sti_data;
376 };
377 
378 
379 /* sticore interface functions */
380 
381 struct sti_struct *sti_get_rom(unsigned int index); /* 0: default sti */
382 
383 
384 /* sticore main function to call STI firmware */
385 
386 int sti_call(const struct sti_struct *sti, unsigned long func,
387 		const void *flags, void *inptr, void *outptr,
388 		struct sti_glob_cfg *glob_cfg);
389 
390 
391 /* functions to call the STI ROM directly */
392 
393 void sti_putc(struct sti_struct *sti, int c, int y, int x);
394 void sti_set(struct sti_struct *sti, int src_y, int src_x,
395 	     int height, int width, u8 color);
396 void sti_clear(struct sti_struct *sti, int src_y, int src_x,
397 	       int height, int width, int c);
398 void sti_bmove(struct sti_struct *sti, int src_y, int src_x,
399 	       int dst_y, int dst_x, int height, int width);
400 
401 #endif	/* STICORE_H */
402