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