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