Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/drivers/video/console/sticore.c - | |
3 | * core code for console driver using HP's STI firmware | |
4 | * | |
5 | * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org> | |
6 | * Copyright (C) 2001-2003 Helge Deller <deller@gmx.de> | |
7 | * Copyright (C) 2001-2002 Thomas Bogendoerfer <tsbogend@alpha.franken.de> | |
8 | * | |
9 | * TODO: | |
10 | * - call STI in virtual mode rather than in real mode | |
11 | * - screen blanking with state_mgmt() in text mode STI ? | |
12 | * - try to make it work on m68k hp workstations ;) | |
13 | * | |
14 | */ | |
15 | ||
1da177e4 LT |
16 | #include <linux/module.h> |
17 | #include <linux/types.h> | |
18 | #include <linux/kernel.h> | |
19 | #include <linux/slab.h> | |
20 | #include <linux/init.h> | |
21 | #include <linux/pci.h> | |
22 | #include <linux/font.h> | |
23 | ||
24 | #include <asm/hardware.h> | |
25 | #include <asm/parisc-device.h> | |
26 | #include <asm/cacheflush.h> | |
27 | ||
28 | #include "../sticore.h" | |
29 | ||
30 | #define STI_DRIVERVERSION "Version 0.9a" | |
31 | ||
3d1e412a | 32 | static struct sti_struct *default_sti __read_mostly; |
1da177e4 | 33 | |
cb6fc18e HD |
34 | /* number of STI ROMS found and their ptrs to each struct */ |
35 | static int num_sti_roms __read_mostly; | |
36 | static struct sti_struct *sti_roms[MAX_STI_ROMS] __read_mostly; | |
1da177e4 LT |
37 | |
38 | ||
39 | /* The colour indices used by STI are | |
40 | * 0 - Black | |
41 | * 1 - White | |
42 | * 2 - Red | |
43 | * 3 - Yellow/Brown | |
44 | * 4 - Green | |
45 | * 5 - Cyan | |
46 | * 6 - Blue | |
47 | * 7 - Magenta | |
48 | * | |
49 | * So we have the same colours as VGA (basically one bit each for R, G, B), | |
50 | * but have to translate them, anyway. */ | |
51 | ||
52 | static const u8 col_trans[8] = { | |
53 | 0, 6, 4, 5, | |
54 | 2, 7, 3, 1 | |
55 | }; | |
56 | ||
57 | #define c_fg(sti, c) col_trans[((c>> 8) & 7)] | |
58 | #define c_bg(sti, c) col_trans[((c>>11) & 7)] | |
59 | #define c_index(sti, c) ((c) & 0xff) | |
60 | ||
61 | static const struct sti_init_flags default_init_flags = { | |
62 | .wait = STI_WAIT, | |
63 | .reset = 1, | |
64 | .text = 1, | |
65 | .nontext = 1, | |
66 | .no_chg_bet = 1, | |
67 | .no_chg_bei = 1, | |
68 | .init_cmap_tx = 1, | |
69 | }; | |
70 | ||
3d1e412a | 71 | static int sti_init_graph(struct sti_struct *sti) |
1da177e4 LT |
72 | { |
73 | struct sti_init_inptr_ext inptr_ext = { 0, }; | |
74 | struct sti_init_inptr inptr = { | |
75 | .text_planes = 3, /* # of text planes (max 3 for STI) */ | |
76 | .ext_ptr = STI_PTR(&inptr_ext) | |
77 | }; | |
78 | struct sti_init_outptr outptr = { 0, }; | |
79 | unsigned long flags; | |
80 | int ret; | |
81 | ||
82 | spin_lock_irqsave(&sti->lock, flags); | |
83 | ||
84 | ret = STI_CALL(sti->init_graph, &default_init_flags, &inptr, | |
85 | &outptr, sti->glob_cfg); | |
86 | ||
87 | spin_unlock_irqrestore(&sti->lock, flags); | |
88 | ||
89 | if (ret < 0) { | |
90 | printk(KERN_ERR "STI init_graph failed (ret %d, errno %d)\n",ret,outptr.errno); | |
91 | return -1; | |
92 | } | |
93 | ||
94 | sti->text_planes = outptr.text_planes; | |
95 | return 0; | |
96 | } | |
97 | ||
98 | static const struct sti_conf_flags default_conf_flags = { | |
99 | .wait = STI_WAIT, | |
100 | }; | |
101 | ||
3d1e412a | 102 | static void sti_inq_conf(struct sti_struct *sti) |
1da177e4 LT |
103 | { |
104 | struct sti_conf_inptr inptr = { 0, }; | |
105 | unsigned long flags; | |
106 | s32 ret; | |
107 | ||
108 | sti->outptr.ext_ptr = STI_PTR(&sti->outptr_ext); | |
109 | ||
110 | do { | |
111 | spin_lock_irqsave(&sti->lock, flags); | |
112 | ret = STI_CALL(sti->inq_conf, &default_conf_flags, | |
113 | &inptr, &sti->outptr, sti->glob_cfg); | |
114 | spin_unlock_irqrestore(&sti->lock, flags); | |
115 | } while (ret == 1); | |
116 | } | |
117 | ||
118 | static const struct sti_font_flags default_font_flags = { | |
119 | .wait = STI_WAIT, | |
120 | .non_text = 0, | |
121 | }; | |
122 | ||
123 | void | |
124 | sti_putc(struct sti_struct *sti, int c, int y, int x) | |
125 | { | |
126 | struct sti_font_inptr inptr = { | |
127 | .font_start_addr= STI_PTR(sti->font->raw), | |
128 | .index = c_index(sti, c), | |
129 | .fg_color = c_fg(sti, c), | |
130 | .bg_color = c_bg(sti, c), | |
131 | .dest_x = x * sti->font_width, | |
132 | .dest_y = y * sti->font_height, | |
133 | }; | |
134 | struct sti_font_outptr outptr = { 0, }; | |
135 | s32 ret; | |
136 | unsigned long flags; | |
137 | ||
138 | do { | |
139 | spin_lock_irqsave(&sti->lock, flags); | |
140 | ret = STI_CALL(sti->font_unpmv, &default_font_flags, | |
141 | &inptr, &outptr, sti->glob_cfg); | |
142 | spin_unlock_irqrestore(&sti->lock, flags); | |
143 | } while (ret == 1); | |
144 | } | |
145 | ||
146 | static const struct sti_blkmv_flags clear_blkmv_flags = { | |
147 | .wait = STI_WAIT, | |
148 | .color = 1, | |
149 | .clear = 1, | |
150 | }; | |
151 | ||
152 | void | |
153 | sti_set(struct sti_struct *sti, int src_y, int src_x, | |
154 | int height, int width, u8 color) | |
155 | { | |
156 | struct sti_blkmv_inptr inptr = { | |
157 | .fg_color = color, | |
158 | .bg_color = color, | |
159 | .src_x = src_x, | |
160 | .src_y = src_y, | |
161 | .dest_x = src_x, | |
162 | .dest_y = src_y, | |
163 | .width = width, | |
164 | .height = height, | |
165 | }; | |
166 | struct sti_blkmv_outptr outptr = { 0, }; | |
167 | s32 ret; | |
168 | unsigned long flags; | |
169 | ||
170 | do { | |
171 | spin_lock_irqsave(&sti->lock, flags); | |
172 | ret = STI_CALL(sti->block_move, &clear_blkmv_flags, | |
173 | &inptr, &outptr, sti->glob_cfg); | |
174 | spin_unlock_irqrestore(&sti->lock, flags); | |
175 | } while (ret == 1); | |
176 | } | |
177 | ||
178 | void | |
179 | sti_clear(struct sti_struct *sti, int src_y, int src_x, | |
180 | int height, int width, int c) | |
181 | { | |
182 | struct sti_blkmv_inptr inptr = { | |
183 | .fg_color = c_fg(sti, c), | |
184 | .bg_color = c_bg(sti, c), | |
185 | .src_x = src_x * sti->font_width, | |
186 | .src_y = src_y * sti->font_height, | |
187 | .dest_x = src_x * sti->font_width, | |
188 | .dest_y = src_y * sti->font_height, | |
189 | .width = width * sti->font_width, | |
190 | .height = height* sti->font_height, | |
191 | }; | |
192 | struct sti_blkmv_outptr outptr = { 0, }; | |
193 | s32 ret; | |
194 | unsigned long flags; | |
195 | ||
196 | do { | |
197 | spin_lock_irqsave(&sti->lock, flags); | |
198 | ret = STI_CALL(sti->block_move, &clear_blkmv_flags, | |
199 | &inptr, &outptr, sti->glob_cfg); | |
200 | spin_unlock_irqrestore(&sti->lock, flags); | |
201 | } while (ret == 1); | |
202 | } | |
203 | ||
204 | static const struct sti_blkmv_flags default_blkmv_flags = { | |
205 | .wait = STI_WAIT, | |
206 | }; | |
207 | ||
208 | void | |
209 | sti_bmove(struct sti_struct *sti, int src_y, int src_x, | |
210 | int dst_y, int dst_x, int height, int width) | |
211 | { | |
212 | struct sti_blkmv_inptr inptr = { | |
213 | .src_x = src_x * sti->font_width, | |
214 | .src_y = src_y * sti->font_height, | |
215 | .dest_x = dst_x * sti->font_width, | |
216 | .dest_y = dst_y * sti->font_height, | |
217 | .width = width * sti->font_width, | |
218 | .height = height* sti->font_height, | |
219 | }; | |
220 | struct sti_blkmv_outptr outptr = { 0, }; | |
221 | s32 ret; | |
222 | unsigned long flags; | |
223 | ||
224 | do { | |
225 | spin_lock_irqsave(&sti->lock, flags); | |
226 | ret = STI_CALL(sti->block_move, &default_blkmv_flags, | |
227 | &inptr, &outptr, sti->glob_cfg); | |
228 | spin_unlock_irqrestore(&sti->lock, flags); | |
229 | } while (ret == 1); | |
230 | } | |
231 | ||
232 | ||
03b18f1b | 233 | static void sti_flush(unsigned long start, unsigned long end) |
1da177e4 | 234 | { |
03b18f1b | 235 | flush_icache_range(start, end); |
1da177e4 LT |
236 | } |
237 | ||
3d1e412a AB |
238 | static void __devinit sti_rom_copy(unsigned long base, unsigned long count, |
239 | void *dest) | |
1da177e4 | 240 | { |
1da177e4 LT |
241 | unsigned long dest_start = (unsigned long) dest; |
242 | ||
243 | /* this still needs to be revisited (see arch/parisc/mm/init.c:246) ! */ | |
244 | while (count >= 4) { | |
245 | count -= 4; | |
246 | *(u32 *)dest = gsc_readl(base); | |
247 | base += 4; | |
248 | dest += 4; | |
249 | } | |
250 | while (count) { | |
251 | count--; | |
252 | *(u8 *)dest = gsc_readb(base); | |
253 | base++; | |
254 | dest++; | |
255 | } | |
256 | ||
03b18f1b | 257 | sti_flush(dest_start, (unsigned long)dest); |
1da177e4 LT |
258 | } |
259 | ||
260 | ||
261 | ||
262 | ||
cb6fc18e | 263 | static char default_sti_path[21] __read_mostly; |
1da177e4 LT |
264 | |
265 | #ifndef MODULE | |
48a7d5c6 | 266 | static int __devinit sti_setup(char *str) |
1da177e4 LT |
267 | { |
268 | if (str) | |
269 | strlcpy (default_sti_path, str, sizeof (default_sti_path)); | |
270 | ||
9b41046c | 271 | return 1; |
1da177e4 LT |
272 | } |
273 | ||
274 | /* Assuming the machine has multiple STI consoles (=graphic cards) which | |
275 | * all get detected by sticon, the user may define with the linux kernel | |
276 | * parameter sti=<x> which of them will be the initial boot-console. | |
277 | * <x> is a number between 0 and MAX_STI_ROMS, with 0 as the default | |
278 | * STI screen. | |
279 | */ | |
280 | __setup("sti=", sti_setup); | |
281 | #endif | |
282 | ||
283 | ||
284 | ||
48a7d5c6 HD |
285 | static char __devinitdata *font_name[MAX_STI_ROMS] = { "VGA8x16", }; |
286 | static int __devinitdata font_index[MAX_STI_ROMS], | |
287 | font_height[MAX_STI_ROMS], | |
288 | font_width[MAX_STI_ROMS]; | |
1da177e4 | 289 | #ifndef MODULE |
48a7d5c6 | 290 | static int __devinit sti_font_setup(char *str) |
1da177e4 LT |
291 | { |
292 | char *x; | |
293 | int i = 0; | |
294 | ||
295 | /* we accept sti_font=VGA8x16, sti_font=10x20, sti_font=10*20 | |
296 | * or sti_font=7 style command lines. */ | |
297 | ||
298 | while (i<MAX_STI_ROMS && str && *str) { | |
299 | if (*str>='0' && *str<='9') { | |
300 | if ((x = strchr(str, 'x')) || (x = strchr(str, '*'))) { | |
301 | font_height[i] = simple_strtoul(str, NULL, 0); | |
302 | font_width[i] = simple_strtoul(x+1, NULL, 0); | |
303 | } else { | |
304 | font_index[i] = simple_strtoul(str, NULL, 0); | |
305 | } | |
306 | } else { | |
307 | font_name[i] = str; /* fb font name */ | |
308 | } | |
309 | ||
310 | if ((x = strchr(str, ','))) | |
311 | *x++ = 0; | |
312 | str = x; | |
313 | ||
314 | i++; | |
315 | } | |
316 | ||
9b41046c | 317 | return 1; |
1da177e4 LT |
318 | } |
319 | ||
320 | /* The optional linux kernel parameter "sti_font" defines which font | |
321 | * should be used by the sticon driver to draw characters to the screen. | |
322 | * Possible values are: | |
323 | * - sti_font=<fb_fontname>: | |
324 | * <fb_fontname> is the name of one of the linux-kernel built-in | |
325 | * framebuffer font names (e.g. VGA8x16, SUN22x18). | |
326 | * This is only available if the fonts have been statically compiled | |
327 | * in with e.g. the CONFIG_FONT_8x16 or CONFIG_FONT_SUN12x22 options. | |
328 | * - sti_font=<number> | |
329 | * most STI ROMs have built-in HP specific fonts, which can be selected | |
330 | * by giving the desired number to the sticon driver. | |
331 | * NOTE: This number is machine and STI ROM dependend. | |
332 | * - sti_font=<height>x<width> (e.g. sti_font=16x8) | |
333 | * <height> and <width> gives hints to the height and width of the | |
334 | * font which the user wants. The sticon driver will try to use | |
335 | * a font with this height and width, but if no suitable font is | |
336 | * found, sticon will use the default 8x8 font. | |
337 | */ | |
338 | __setup("sti_font=", sti_font_setup); | |
339 | #endif | |
340 | ||
341 | ||
342 | ||
48a7d5c6 | 343 | static void __devinit |
1da177e4 LT |
344 | sti_dump_globcfg(struct sti_glob_cfg *glob_cfg, unsigned int sti_mem_request) |
345 | { | |
346 | struct sti_glob_cfg_ext *cfg; | |
347 | ||
348 | DPRINTK((KERN_INFO | |
349 | "%d text planes\n" | |
350 | "%4d x %4d screen resolution\n" | |
351 | "%4d x %4d offscreen\n" | |
352 | "%4d x %4d layout\n" | |
353 | "regions at %08x %08x %08x %08x\n" | |
354 | "regions at %08x %08x %08x %08x\n" | |
355 | "reent_lvl %d\n" | |
356 | "save_addr %08x\n", | |
357 | glob_cfg->text_planes, | |
358 | glob_cfg->onscreen_x, glob_cfg->onscreen_y, | |
359 | glob_cfg->offscreen_x, glob_cfg->offscreen_y, | |
360 | glob_cfg->total_x, glob_cfg->total_y, | |
361 | glob_cfg->region_ptrs[0], glob_cfg->region_ptrs[1], | |
362 | glob_cfg->region_ptrs[2], glob_cfg->region_ptrs[3], | |
363 | glob_cfg->region_ptrs[4], glob_cfg->region_ptrs[5], | |
364 | glob_cfg->region_ptrs[6], glob_cfg->region_ptrs[7], | |
365 | glob_cfg->reent_lvl, | |
366 | glob_cfg->save_addr)); | |
367 | ||
368 | /* dump extended cfg */ | |
857600c7 | 369 | cfg = PTR_STI((unsigned long)glob_cfg->ext_ptr); |
1da177e4 LT |
370 | DPRINTK(( KERN_INFO |
371 | "monitor %d\n" | |
372 | "in friendly mode: %d\n" | |
373 | "power consumption %d watts\n" | |
374 | "freq ref %d\n" | |
375 | "sti_mem_addr %08x (size=%d bytes)\n", | |
376 | cfg->curr_mon, | |
377 | cfg->friendly_boot, | |
378 | cfg->power, | |
379 | cfg->freq_ref, | |
380 | cfg->sti_mem_addr, sti_mem_request)); | |
381 | } | |
382 | ||
48a7d5c6 | 383 | static void __devinit |
1da177e4 LT |
384 | sti_dump_outptr(struct sti_struct *sti) |
385 | { | |
386 | DPRINTK((KERN_INFO | |
387 | "%d bits per pixel\n" | |
388 | "%d used bits\n" | |
389 | "%d planes\n" | |
390 | "attributes %08x\n", | |
391 | sti->outptr.bits_per_pixel, | |
392 | sti->outptr.bits_used, | |
393 | sti->outptr.planes, | |
394 | sti->outptr.attributes)); | |
395 | } | |
396 | ||
48a7d5c6 | 397 | static int __devinit |
1da177e4 LT |
398 | sti_init_glob_cfg(struct sti_struct *sti, |
399 | unsigned long rom_address, unsigned long hpa) | |
400 | { | |
401 | struct sti_glob_cfg *glob_cfg; | |
402 | struct sti_glob_cfg_ext *glob_cfg_ext; | |
403 | void *save_addr; | |
404 | void *sti_mem_addr; | |
405 | const int save_addr_size = 1024; /* XXX */ | |
406 | int i; | |
407 | ||
408 | if (!sti->sti_mem_request) | |
409 | sti->sti_mem_request = 256; /* STI default */ | |
410 | ||
cb6fc18e HD |
411 | glob_cfg = kzalloc(sizeof(*sti->glob_cfg), GFP_KERNEL); |
412 | glob_cfg_ext = kzalloc(sizeof(*glob_cfg_ext), GFP_KERNEL); | |
413 | save_addr = kzalloc(save_addr_size, GFP_KERNEL); | |
414 | sti_mem_addr = kzalloc(sti->sti_mem_request, GFP_KERNEL); | |
1da177e4 LT |
415 | |
416 | if (!(glob_cfg && glob_cfg_ext && save_addr && sti_mem_addr)) { | |
417 | kfree(glob_cfg); | |
418 | kfree(glob_cfg_ext); | |
419 | kfree(save_addr); | |
420 | kfree(sti_mem_addr); | |
421 | return -ENOMEM; | |
422 | } | |
423 | ||
1da177e4 LT |
424 | glob_cfg->ext_ptr = STI_PTR(glob_cfg_ext); |
425 | glob_cfg->save_addr = STI_PTR(save_addr); | |
426 | for (i=0; i<8; i++) { | |
427 | unsigned long newhpa, len; | |
428 | ||
429 | if (sti->pd) { | |
430 | unsigned char offs = sti->rm_entry[i]; | |
431 | ||
432 | if (offs == 0) | |
433 | continue; | |
434 | if (offs != PCI_ROM_ADDRESS && | |
435 | (offs < PCI_BASE_ADDRESS_0 || | |
436 | offs > PCI_BASE_ADDRESS_5)) { | |
437 | printk (KERN_WARNING | |
438 | "STI pci region maping for region %d (%02x) can't be mapped\n", | |
439 | i,sti->rm_entry[i]); | |
440 | continue; | |
441 | } | |
442 | newhpa = pci_resource_start (sti->pd, (offs - PCI_BASE_ADDRESS_0) / 4); | |
443 | } else | |
444 | newhpa = (i == 0) ? rom_address : hpa; | |
445 | ||
446 | sti->regions_phys[i] = | |
447 | REGION_OFFSET_TO_PHYS(sti->regions[i], newhpa); | |
448 | ||
1da177e4 | 449 | len = sti->regions[i].region_desc.length * 4096; |
1da177e4 LT |
450 | if (len) |
451 | glob_cfg->region_ptrs[i] = sti->regions_phys[i]; | |
1da177e4 | 452 | |
857600c7 | 453 | DPRINTK(("region #%d: phys %08lx, region_ptr %08x, len=%lukB, " |
1da177e4 LT |
454 | "btlb=%d, sysonly=%d, cache=%d, last=%d\n", |
455 | i, sti->regions_phys[i], glob_cfg->region_ptrs[i], | |
456 | len/1024, | |
457 | sti->regions[i].region_desc.btlb, | |
458 | sti->regions[i].region_desc.sys_only, | |
459 | sti->regions[i].region_desc.cache, | |
460 | sti->regions[i].region_desc.last)); | |
461 | ||
462 | /* last entry reached ? */ | |
463 | if (sti->regions[i].region_desc.last) | |
464 | break; | |
465 | } | |
466 | ||
467 | if (++i<8 && sti->regions[i].region) | |
468 | printk(KERN_WARNING "%s: *future ptr (0x%8x) not yet supported !\n", | |
469 | __FILE__, sti->regions[i].region); | |
470 | ||
471 | glob_cfg_ext->sti_mem_addr = STI_PTR(sti_mem_addr); | |
472 | ||
473 | sti->glob_cfg = glob_cfg; | |
474 | ||
475 | return 0; | |
476 | } | |
477 | ||
478 | #ifdef CONFIG_FB | |
3d1e412a AB |
479 | static struct sti_cooked_font __devinit |
480 | *sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name) | |
1da177e4 | 481 | { |
cb6fc18e | 482 | const struct font_desc *fbfont; |
1da177e4 LT |
483 | unsigned int size, bpc; |
484 | void *dest; | |
485 | struct sti_rom_font *nf; | |
486 | struct sti_cooked_font *cooked_font; | |
487 | ||
488 | if (!fbfont_name || !strlen(fbfont_name)) | |
951a0150 | 489 | return NULL; |
1da177e4 LT |
490 | fbfont = find_font(fbfont_name); |
491 | if (!fbfont) | |
2d2699d9 | 492 | fbfont = get_default_font(1024,768, ~(u32)0, ~(u32)0); |
1da177e4 | 493 | if (!fbfont) |
951a0150 | 494 | return NULL; |
1da177e4 LT |
495 | |
496 | DPRINTK((KERN_DEBUG "selected %dx%d fb-font %s\n", | |
497 | fbfont->width, fbfont->height, fbfont->name)); | |
498 | ||
499 | bpc = ((fbfont->width+7)/8) * fbfont->height; | |
500 | size = bpc * 256; | |
501 | size += sizeof(struct sti_rom_font); | |
502 | ||
cb6fc18e | 503 | nf = kzalloc(size, GFP_KERNEL); |
1da177e4 | 504 | if (!nf) |
951a0150 | 505 | return NULL; |
1da177e4 LT |
506 | |
507 | nf->first_char = 0; | |
508 | nf->last_char = 255; | |
509 | nf->width = fbfont->width; | |
510 | nf->height = fbfont->height; | |
511 | nf->font_type = STI_FONT_HPROMAN8; | |
512 | nf->bytes_per_char = bpc; | |
513 | nf->next_font = 0; | |
514 | nf->underline_height = 1; | |
515 | nf->underline_pos = fbfont->height - nf->underline_height; | |
516 | ||
517 | dest = nf; | |
518 | dest += sizeof(struct sti_rom_font); | |
519 | memcpy(dest, fbfont->data, bpc*256); | |
520 | ||
cb6fc18e | 521 | cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL); |
1da177e4 | 522 | if (!cooked_font) { |
951a0150 MW |
523 | kfree(nf); |
524 | return NULL; | |
1da177e4 LT |
525 | } |
526 | ||
527 | cooked_font->raw = nf; | |
528 | cooked_font->next_font = NULL; | |
529 | ||
530 | cooked_rom->font_start = cooked_font; | |
531 | ||
532 | return cooked_font; | |
533 | } | |
534 | #else | |
3d1e412a AB |
535 | static struct sti_cooked_font __devinit |
536 | *sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name) | |
1da177e4 LT |
537 | { |
538 | return NULL; | |
539 | } | |
540 | #endif | |
541 | ||
3d1e412a AB |
542 | static struct sti_cooked_font __devinit |
543 | *sti_select_font(struct sti_cooked_rom *rom, | |
544 | int (*search_font_fnc)(struct sti_cooked_rom *, int, int)) | |
1da177e4 LT |
545 | { |
546 | struct sti_cooked_font *font; | |
547 | int i; | |
548 | int index = num_sti_roms; | |
549 | ||
550 | /* check for framebuffer-font first */ | |
551 | if ((font = sti_select_fbfont(rom, font_name[index]))) | |
552 | return font; | |
553 | ||
554 | if (font_width[index] && font_height[index]) | |
555 | font_index[index] = search_font_fnc(rom, | |
556 | font_height[index], font_width[index]); | |
557 | ||
558 | for (font = rom->font_start, i = font_index[index]; | |
559 | font && (i > 0); | |
560 | font = font->next_font, i--); | |
561 | ||
562 | if (font) | |
563 | return font; | |
564 | else | |
565 | return rom->font_start; | |
566 | } | |
567 | ||
568 | ||
48a7d5c6 | 569 | static void __devinit |
1da177e4 LT |
570 | sti_dump_rom(struct sti_rom *rom) |
571 | { | |
951a0150 | 572 | printk(KERN_INFO " id %04x-%04x, conforms to spec rev. %d.%02x\n", |
1da177e4 LT |
573 | rom->graphics_id[0], |
574 | rom->graphics_id[1], | |
575 | rom->revno[0] >> 4, | |
576 | rom->revno[0] & 0x0f); | |
577 | DPRINTK((" supports %d monitors\n", rom->num_mons)); | |
578 | DPRINTK((" font start %08x\n", rom->font_start)); | |
579 | DPRINTK((" region list %08x\n", rom->region_list)); | |
580 | DPRINTK((" init_graph %08x\n", rom->init_graph)); | |
581 | DPRINTK((" bus support %02x\n", rom->bus_support)); | |
582 | DPRINTK((" ext bus support %02x\n", rom->ext_bus_support)); | |
583 | DPRINTK((" alternate code type %d\n", rom->alt_code_type)); | |
584 | } | |
585 | ||
586 | ||
48a7d5c6 | 587 | static int __devinit |
1da177e4 LT |
588 | sti_cook_fonts(struct sti_cooked_rom *cooked_rom, |
589 | struct sti_rom *raw_rom) | |
590 | { | |
591 | struct sti_rom_font *raw_font, *font_start; | |
592 | struct sti_cooked_font *cooked_font; | |
593 | ||
cb6fc18e | 594 | cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL); |
1da177e4 LT |
595 | if (!cooked_font) |
596 | return 0; | |
597 | ||
598 | cooked_rom->font_start = cooked_font; | |
599 | ||
600 | raw_font = ((void *)raw_rom) + (raw_rom->font_start); | |
601 | ||
602 | font_start = raw_font; | |
603 | cooked_font->raw = raw_font; | |
604 | ||
605 | while (raw_font->next_font) { | |
606 | raw_font = ((void *)font_start) + (raw_font->next_font); | |
607 | ||
cb6fc18e | 608 | cooked_font->next_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL); |
1da177e4 LT |
609 | if (!cooked_font->next_font) |
610 | return 1; | |
611 | ||
612 | cooked_font = cooked_font->next_font; | |
613 | ||
614 | cooked_font->raw = raw_font; | |
615 | } | |
616 | ||
617 | cooked_font->next_font = NULL; | |
618 | return 1; | |
619 | } | |
620 | ||
621 | ||
48a7d5c6 | 622 | static int __devinit |
1da177e4 LT |
623 | sti_search_font(struct sti_cooked_rom *rom, int height, int width) |
624 | { | |
625 | struct sti_cooked_font *font; | |
626 | int i = 0; | |
627 | ||
951a0150 MW |
628 | for (font = rom->font_start; font; font = font->next_font, i++) { |
629 | if ((font->raw->width == width) && | |
630 | (font->raw->height == height)) | |
1da177e4 LT |
631 | return i; |
632 | } | |
633 | return 0; | |
634 | } | |
635 | ||
951a0150 MW |
636 | #define BMODE_RELOCATE(offset) offset = (offset) / 4; |
637 | #define BMODE_LAST_ADDR_OFFS 0x50 | |
1da177e4 | 638 | |
48a7d5c6 | 639 | static void * __devinit |
1da177e4 LT |
640 | sti_bmode_font_raw(struct sti_cooked_font *f) |
641 | { | |
642 | unsigned char *n, *p, *q; | |
643 | int size = f->raw->bytes_per_char*256+sizeof(struct sti_rom_font); | |
644 | ||
cb6fc18e | 645 | n = kzalloc (4*size, GFP_KERNEL); |
1da177e4 LT |
646 | if (!n) |
647 | return NULL; | |
1da177e4 LT |
648 | p = n + 3; |
649 | q = (unsigned char *)f->raw; | |
650 | while (size--) { | |
651 | *p = *q++; | |
652 | p+=4; | |
653 | } | |
654 | return n + 3; | |
655 | } | |
656 | ||
48a7d5c6 | 657 | static void __devinit |
1da177e4 LT |
658 | sti_bmode_rom_copy(unsigned long base, unsigned long count, void *dest) |
659 | { | |
1da177e4 LT |
660 | unsigned long dest_start = (unsigned long) dest; |
661 | ||
662 | while (count) { | |
663 | count--; | |
664 | *(u8 *)dest = gsc_readl(base); | |
665 | base += 4; | |
666 | dest++; | |
667 | } | |
03b18f1b KM |
668 | |
669 | sti_flush(dest_start, (unsigned long)dest); | |
1da177e4 LT |
670 | } |
671 | ||
48a7d5c6 | 672 | static struct sti_rom * __devinit |
1da177e4 LT |
673 | sti_get_bmode_rom (unsigned long address) |
674 | { | |
675 | struct sti_rom *raw; | |
676 | u32 size; | |
951a0150 MW |
677 | struct sti_rom_font *raw_font, *font_start; |
678 | ||
1da177e4 | 679 | sti_bmode_rom_copy(address + BMODE_LAST_ADDR_OFFS, sizeof(size), &size); |
951a0150 MW |
680 | |
681 | size = (size+3) / 4; | |
1da177e4 LT |
682 | raw = kmalloc(size, GFP_KERNEL); |
683 | if (raw) { | |
951a0150 MW |
684 | sti_bmode_rom_copy(address, size, raw); |
685 | memmove (&raw->res004, &raw->type[0], 0x3c); | |
686 | raw->type[3] = raw->res004; | |
1da177e4 | 687 | |
951a0150 MW |
688 | BMODE_RELOCATE (raw->region_list); |
689 | BMODE_RELOCATE (raw->font_start); | |
1da177e4 | 690 | |
951a0150 MW |
691 | BMODE_RELOCATE (raw->init_graph); |
692 | BMODE_RELOCATE (raw->state_mgmt); | |
693 | BMODE_RELOCATE (raw->font_unpmv); | |
694 | BMODE_RELOCATE (raw->block_move); | |
695 | BMODE_RELOCATE (raw->inq_conf); | |
1da177e4 | 696 | |
951a0150 MW |
697 | raw_font = ((void *)raw) + raw->font_start; |
698 | font_start = raw_font; | |
1da177e4 | 699 | |
951a0150 MW |
700 | while (raw_font->next_font) { |
701 | BMODE_RELOCATE (raw_font->next_font); | |
702 | raw_font = ((void *)font_start) + raw_font->next_font; | |
703 | } | |
1da177e4 | 704 | } |
951a0150 | 705 | return raw; |
1da177e4 LT |
706 | } |
707 | ||
3d1e412a | 708 | static struct sti_rom __devinit *sti_get_wmode_rom(unsigned long address) |
1da177e4 LT |
709 | { |
710 | struct sti_rom *raw; | |
711 | unsigned long size; | |
951a0150 | 712 | |
1da177e4 LT |
713 | /* read the ROM size directly from the struct in ROM */ |
714 | size = gsc_readl(address + offsetof(struct sti_rom,last_addr)); | |
715 | ||
716 | raw = kmalloc(size, GFP_KERNEL); | |
951a0150 MW |
717 | if (raw) |
718 | sti_rom_copy(address, size, raw); | |
1da177e4 | 719 | |
951a0150 | 720 | return raw; |
1da177e4 LT |
721 | } |
722 | ||
3d1e412a AB |
723 | static int __devinit sti_read_rom(int wordmode, struct sti_struct *sti, |
724 | unsigned long address) | |
1da177e4 LT |
725 | { |
726 | struct sti_cooked_rom *cooked; | |
727 | struct sti_rom *raw = NULL; | |
728 | ||
729 | cooked = kmalloc(sizeof *cooked, GFP_KERNEL); | |
730 | if (!cooked) | |
731 | goto out_err; | |
732 | ||
951a0150 MW |
733 | if (wordmode) |
734 | raw = sti_get_wmode_rom (address); | |
735 | else | |
736 | raw = sti_get_bmode_rom (address); | |
737 | ||
738 | if (!raw) | |
739 | goto out_err; | |
1da177e4 | 740 | |
1da177e4 LT |
741 | if (!sti_cook_fonts(cooked, raw)) { |
742 | printk(KERN_ERR "No font found for STI at %08lx\n", address); | |
743 | goto out_err; | |
744 | } | |
745 | ||
746 | if (raw->region_list) | |
747 | memcpy(sti->regions, ((void *)raw)+raw->region_list, sizeof(sti->regions)); | |
748 | ||
749 | address = (unsigned long) STI_PTR(raw); | |
750 | ||
751 | sti->font_unpmv = address + (raw->font_unpmv & 0x03ffffff); | |
752 | sti->block_move = address + (raw->block_move & 0x03ffffff); | |
753 | sti->init_graph = address + (raw->init_graph & 0x03ffffff); | |
754 | sti->inq_conf = address + (raw->inq_conf & 0x03ffffff); | |
755 | ||
756 | sti->rom = cooked; | |
757 | sti->rom->raw = raw; | |
758 | ||
759 | sti->font = sti_select_font(sti->rom, sti_search_font); | |
760 | sti->font_width = sti->font->raw->width; | |
761 | sti->font_height = sti->font->raw->height; | |
762 | if (!wordmode) | |
951a0150 | 763 | sti->font->raw = sti_bmode_font_raw(sti->font); |
1da177e4 LT |
764 | |
765 | sti->sti_mem_request = raw->sti_mem_req; | |
766 | sti->graphics_id[0] = raw->graphics_id[0]; | |
767 | sti->graphics_id[1] = raw->graphics_id[1]; | |
768 | ||
769 | sti_dump_rom(raw); | |
770 | ||
771 | return 1; | |
772 | ||
773 | out_err: | |
774 | kfree(raw); | |
775 | kfree(cooked); | |
776 | return 0; | |
777 | } | |
778 | ||
48a7d5c6 | 779 | static struct sti_struct * __devinit |
1da177e4 LT |
780 | sti_try_rom_generic(unsigned long address, unsigned long hpa, struct pci_dev *pd) |
781 | { | |
782 | struct sti_struct *sti; | |
783 | int ok; | |
784 | u32 sig; | |
785 | ||
786 | if (num_sti_roms >= MAX_STI_ROMS) { | |
951a0150 MW |
787 | printk(KERN_WARNING "maximum number of STI ROMS reached !\n"); |
788 | return NULL; | |
1da177e4 LT |
789 | } |
790 | ||
cb6fc18e | 791 | sti = kzalloc(sizeof(*sti), GFP_KERNEL); |
1da177e4 | 792 | if (!sti) { |
951a0150 MW |
793 | printk(KERN_ERR "Not enough memory !\n"); |
794 | return NULL; | |
1da177e4 | 795 | } |
951a0150 | 796 | |
1da177e4 LT |
797 | spin_lock_init(&sti->lock); |
798 | ||
799 | test_rom: | |
800 | /* if we can't read the ROM, bail out early. Not being able | |
801 | * to read the hpa is okay, for romless sti */ | |
802 | if (pdc_add_valid(address)) | |
803 | goto out_err; | |
804 | ||
805 | sig = gsc_readl(address); | |
806 | ||
807 | /* check for a PCI ROM structure */ | |
808 | if ((le32_to_cpu(sig)==0xaa55)) { | |
809 | unsigned int i, rm_offset; | |
810 | u32 *rm; | |
811 | i = gsc_readl(address+0x04); | |
812 | if (i != 1) { | |
813 | /* The ROM could have multiple architecture | |
814 | * dependent images (e.g. i386, parisc,...) */ | |
815 | printk(KERN_WARNING | |
816 | "PCI ROM is not a STI ROM type image (0x%8x)\n", i); | |
817 | goto out_err; | |
818 | } | |
819 | ||
820 | sti->pd = pd; | |
821 | ||
822 | i = gsc_readl(address+0x0c); | |
823 | DPRINTK(("PCI ROM size (from header) = %d kB\n", | |
824 | le16_to_cpu(i>>16)*512/1024)); | |
825 | rm_offset = le16_to_cpu(i & 0xffff); | |
826 | if (rm_offset) { | |
827 | /* read 16 bytes from the pci region mapper array */ | |
828 | rm = (u32*) &sti->rm_entry; | |
829 | *rm++ = gsc_readl(address+rm_offset+0x00); | |
830 | *rm++ = gsc_readl(address+rm_offset+0x04); | |
831 | *rm++ = gsc_readl(address+rm_offset+0x08); | |
832 | *rm++ = gsc_readl(address+rm_offset+0x0c); | |
833 | DPRINTK(("PCI region Mapper offset = %08x: ", | |
834 | rm_offset)); | |
835 | for (i=0; i<16; i++) | |
836 | DPRINTK(("%02x ", sti->rm_entry[i])); | |
837 | DPRINTK(("\n")); | |
838 | } | |
839 | ||
840 | address += le32_to_cpu(gsc_readl(address+8)); | |
841 | DPRINTK(("sig %04x, PCI STI ROM at %08lx\n", sig, address)); | |
842 | goto test_rom; | |
843 | } | |
844 | ||
845 | ok = 0; | |
846 | ||
847 | if ((sig & 0xff) == 0x01) { | |
848 | DPRINTK((" byte mode ROM at %08lx, hpa at %08lx\n", | |
849 | address, hpa)); | |
850 | ok = sti_read_rom(0, sti, address); | |
851 | } | |
852 | ||
853 | if ((sig & 0xffff) == 0x0303) { | |
854 | DPRINTK((" word mode ROM at %08lx, hpa at %08lx\n", | |
855 | address, hpa)); | |
856 | ok = sti_read_rom(1, sti, address); | |
857 | } | |
858 | ||
859 | if (!ok) | |
860 | goto out_err; | |
861 | ||
862 | if (sti_init_glob_cfg(sti, address, hpa)) | |
863 | goto out_err; /* not enough memory */ | |
864 | ||
865 | /* disable STI PCI ROM. ROM and card RAM overlap and | |
866 | * leaving it enabled would force HPMCs | |
867 | */ | |
868 | if (sti->pd) { | |
869 | unsigned long rom_base; | |
870 | rom_base = pci_resource_start(sti->pd, PCI_ROM_RESOURCE); | |
871 | pci_write_config_dword(sti->pd, PCI_ROM_ADDRESS, rom_base & ~PCI_ROM_ADDRESS_ENABLE); | |
872 | DPRINTK((KERN_DEBUG "STI PCI ROM disabled\n")); | |
873 | } | |
874 | ||
875 | if (sti_init_graph(sti)) | |
876 | goto out_err; | |
877 | ||
878 | sti_inq_conf(sti); | |
879 | sti_dump_globcfg(sti->glob_cfg, sti->sti_mem_request); | |
880 | sti_dump_outptr(sti); | |
881 | ||
882 | printk(KERN_INFO " graphics card name: %s\n", sti->outptr.dev_name ); | |
883 | ||
884 | sti_roms[num_sti_roms] = sti; | |
885 | num_sti_roms++; | |
886 | ||
887 | return sti; | |
888 | ||
889 | out_err: | |
890 | kfree(sti); | |
891 | return NULL; | |
892 | } | |
893 | ||
48a7d5c6 | 894 | static void __devinit sticore_check_for_default_sti(struct sti_struct *sti, char *path) |
1da177e4 LT |
895 | { |
896 | if (strcmp (path, default_sti_path) == 0) | |
897 | default_sti = sti; | |
898 | } | |
899 | ||
900 | /* | |
901 | * on newer systems PDC gives the address of the ROM | |
902 | * in the additional address field addr[1] while on | |
903 | * older Systems the PDC stores it in page0->proc_sti | |
904 | */ | |
48a7d5c6 | 905 | static int __devinit sticore_pa_init(struct parisc_device *dev) |
1da177e4 | 906 | { |
1da177e4 LT |
907 | char pa_path[21]; |
908 | struct sti_struct *sti = NULL; | |
951a0150 MW |
909 | int hpa = dev->hpa.start; |
910 | ||
911 | if (dev->num_addrs && dev->addr[0]) | |
912 | sti = sti_try_rom_generic(dev->addr[0], hpa, NULL); | |
913 | if (!sti) | |
914 | sti = sti_try_rom_generic(hpa, hpa, NULL); | |
915 | if (!sti) | |
916 | sti = sti_try_rom_generic(PAGE0->proc_sti, hpa, NULL); | |
1da177e4 LT |
917 | if (!sti) |
918 | return 1; | |
951a0150 | 919 | |
1da177e4 | 920 | print_pa_hwpath(dev, pa_path); |
951a0150 | 921 | sticore_check_for_default_sti(sti, pa_path); |
1da177e4 LT |
922 | return 0; |
923 | } | |
924 | ||
925 | ||
926 | static int __devinit sticore_pci_init(struct pci_dev *pd, | |
927 | const struct pci_device_id *ent) | |
928 | { | |
929 | #ifdef CONFIG_PCI | |
930 | unsigned long fb_base, rom_base; | |
931 | unsigned int fb_len, rom_len; | |
932 | struct sti_struct *sti; | |
933 | ||
934 | pci_enable_device(pd); | |
935 | ||
936 | fb_base = pci_resource_start(pd, 0); | |
937 | fb_len = pci_resource_len(pd, 0); | |
938 | rom_base = pci_resource_start(pd, PCI_ROM_RESOURCE); | |
939 | rom_len = pci_resource_len(pd, PCI_ROM_RESOURCE); | |
940 | if (rom_base) { | |
941 | pci_write_config_dword(pd, PCI_ROM_ADDRESS, rom_base | PCI_ROM_ADDRESS_ENABLE); | |
942 | DPRINTK((KERN_DEBUG "STI PCI ROM enabled at 0x%08lx\n", rom_base)); | |
943 | } | |
944 | ||
945 | printk(KERN_INFO "STI PCI graphic ROM found at %08lx (%u kB), fb at %08lx (%u MB)\n", | |
946 | rom_base, rom_len/1024, fb_base, fb_len/1024/1024); | |
947 | ||
948 | DPRINTK((KERN_DEBUG "Trying PCI STI ROM at %08lx, PCI hpa at %08lx\n", | |
949 | rom_base, fb_base)); | |
950 | ||
951 | sti = sti_try_rom_generic(rom_base, fb_base, pd); | |
952 | if (sti) { | |
953 | char pa_path[30]; | |
954 | print_pci_hwpath(pd, pa_path); | |
955 | sticore_check_for_default_sti(sti, pa_path); | |
956 | } | |
957 | ||
958 | if (!sti) { | |
959 | printk(KERN_WARNING "Unable to handle STI device '%s'\n", | |
960 | pci_name(pd)); | |
961 | return -ENODEV; | |
962 | } | |
963 | #endif /* CONFIG_PCI */ | |
964 | ||
965 | return 0; | |
966 | } | |
967 | ||
968 | ||
969 | static void __devexit sticore_pci_remove(struct pci_dev *pd) | |
970 | { | |
971 | BUG(); | |
972 | } | |
973 | ||
974 | ||
975 | static struct pci_device_id sti_pci_tbl[] = { | |
976 | { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_EG) }, | |
977 | { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX6) }, | |
978 | { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX4) }, | |
979 | { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX2) }, | |
980 | { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FXE) }, | |
981 | { 0, } /* terminate list */ | |
982 | }; | |
983 | MODULE_DEVICE_TABLE(pci, sti_pci_tbl); | |
984 | ||
985 | static struct pci_driver pci_sti_driver = { | |
986 | .name = "sti", | |
987 | .id_table = sti_pci_tbl, | |
988 | .probe = sticore_pci_init, | |
989 | .remove = sticore_pci_remove, | |
990 | }; | |
991 | ||
992 | static struct parisc_device_id sti_pa_tbl[] = { | |
993 | { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00077 }, | |
994 | { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00085 }, | |
995 | { 0, } | |
996 | }; | |
997 | ||
998 | static struct parisc_driver pa_sti_driver = { | |
999 | .name = "sti", | |
1000 | .id_table = sti_pa_tbl, | |
1001 | .probe = sticore_pa_init, | |
1002 | }; | |
1003 | ||
1004 | ||
1005 | /* | |
1006 | * sti_init_roms() - detects all STI ROMs and stores them in sti_roms[] | |
1007 | */ | |
1008 | ||
cb6fc18e | 1009 | static int sticore_initialized __read_mostly; |
1da177e4 | 1010 | |
48a7d5c6 | 1011 | static void __devinit sti_init_roms(void) |
1da177e4 LT |
1012 | { |
1013 | if (sticore_initialized) | |
1014 | return; | |
1015 | ||
1016 | sticore_initialized = 1; | |
1017 | ||
1018 | printk(KERN_INFO "STI GSC/PCI core graphics driver " | |
1019 | STI_DRIVERVERSION "\n"); | |
1020 | ||
1021 | /* Register drivers for native & PCI cards */ | |
1022 | register_parisc_driver(&pa_sti_driver); | |
1023 | pci_register_driver(&pci_sti_driver); | |
1024 | ||
1025 | /* if we didn't find the given default sti, take the first one */ | |
1026 | if (!default_sti) | |
1027 | default_sti = sti_roms[0]; | |
1028 | ||
1029 | } | |
1030 | ||
1031 | /* | |
1032 | * index = 0 gives default sti | |
1033 | * index > 0 gives other stis in detection order | |
1034 | */ | |
1035 | struct sti_struct * sti_get_rom(unsigned int index) | |
1036 | { | |
1037 | if (!sticore_initialized) | |
1038 | sti_init_roms(); | |
1039 | ||
1040 | if (index == 0) | |
1041 | return default_sti; | |
1042 | ||
1043 | if (index > num_sti_roms) | |
1044 | return NULL; | |
1045 | ||
1046 | return sti_roms[index-1]; | |
1047 | } | |
1048 | EXPORT_SYMBOL(sti_get_rom); | |
1049 | ||
1050 | MODULE_AUTHOR("Philipp Rumpf, Helge Deller, Thomas Bogendoerfer"); | |
1051 | MODULE_DESCRIPTION("Core STI driver for HP's NGLE series graphics cards in HP PARISC machines"); | |
1052 | MODULE_LICENSE("GPL v2"); | |
1053 |