blob: 7da1ad03acb57118392dad947ce46703c8abb2ff [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Helge Deller02191322013-11-06 23:38:59 +01006 * Copyright (C) 2001-2013 Helge Deller <deller@gmx.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#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>
Rolf Eike Beer4a8a0782012-05-10 23:08:17 +020025#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/parisc-device.h>
Rolf Eike Beer4a8a0782012-05-10 23:08:17 +020027#include <asm/pdc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/cacheflush.h>
Helge Dellerfdac4e62008-07-29 22:33:01 -070029#include <asm/grfioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Tomi Valkeinenf7018c22014-02-13 15:31:38 +020031#include "../fbdev/sticore.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Helge Deller02191322013-11-06 23:38:59 +010033#define STI_DRIVERVERSION "Version 0.9b"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Adrian Bunk3d1e4122008-07-25 19:46:26 -070035static struct sti_struct *default_sti __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Helge Dellercb6fc182006-01-17 12:40:40 -070037/* number of STI ROMS found and their ptrs to each struct */
38static int num_sti_roms __read_mostly;
39static struct sti_struct *sti_roms[MAX_STI_ROMS] __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41
42/* The colour indices used by STI are
43 * 0 - Black
44 * 1 - White
45 * 2 - Red
46 * 3 - Yellow/Brown
47 * 4 - Green
48 * 5 - Cyan
49 * 6 - Blue
50 * 7 - Magenta
51 *
52 * So we have the same colours as VGA (basically one bit each for R, G, B),
53 * but have to translate them, anyway. */
54
55static const u8 col_trans[8] = {
56 0, 6, 4, 5,
57 2, 7, 3, 1
58};
59
60#define c_fg(sti, c) col_trans[((c>> 8) & 7)]
61#define c_bg(sti, c) col_trans[((c>>11) & 7)]
62#define c_index(sti, c) ((c) & 0xff)
63
64static const struct sti_init_flags default_init_flags = {
65 .wait = STI_WAIT,
66 .reset = 1,
67 .text = 1,
68 .nontext = 1,
69 .no_chg_bet = 1,
70 .no_chg_bei = 1,
71 .init_cmap_tx = 1,
72};
73
Adrian Bunk3d1e4122008-07-25 19:46:26 -070074static int sti_init_graph(struct sti_struct *sti)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Helge Deller02191322013-11-06 23:38:59 +010076 struct sti_init_inptr *inptr = &sti->sti_data->init_inptr;
77 struct sti_init_inptr_ext *inptr_ext = &sti->sti_data->init_inptr_ext;
78 struct sti_init_outptr *outptr = &sti->sti_data->init_outptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 unsigned long flags;
Helge Deller02191322013-11-06 23:38:59 +010080 int ret, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 spin_lock_irqsave(&sti->lock, flags);
83
Helge Deller02191322013-11-06 23:38:59 +010084 memset(inptr, 0, sizeof(*inptr));
85 inptr->text_planes = 3; /* # of text planes (max 3 for STI) */
86 memset(inptr_ext, 0, sizeof(*inptr_ext));
87 inptr->ext_ptr = STI_PTR(inptr_ext);
88 outptr->errno = 0;
89
90 ret = sti_call(sti, sti->init_graph, &default_init_flags, inptr,
91 outptr, sti->glob_cfg);
92
93 if (ret >= 0)
94 sti->text_planes = outptr->text_planes;
95 err = outptr->errno;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 spin_unlock_irqrestore(&sti->lock, flags);
98
99 if (ret < 0) {
Helge Deller02191322013-11-06 23:38:59 +0100100 pr_err("STI init_graph failed (ret %d, errno %d)\n", ret, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 return -1;
102 }
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 return 0;
105}
106
107static const struct sti_conf_flags default_conf_flags = {
108 .wait = STI_WAIT,
109};
110
Adrian Bunk3d1e4122008-07-25 19:46:26 -0700111static void sti_inq_conf(struct sti_struct *sti)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Helge Deller02191322013-11-06 23:38:59 +0100113 struct sti_conf_inptr *inptr = &sti->sti_data->inq_inptr;
114 struct sti_conf_outptr *outptr = &sti->sti_data->inq_outptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 unsigned long flags;
116 s32 ret;
117
Helge Deller02191322013-11-06 23:38:59 +0100118 outptr->ext_ptr = STI_PTR(&sti->sti_data->inq_outptr_ext);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120 do {
121 spin_lock_irqsave(&sti->lock, flags);
Helge Deller02191322013-11-06 23:38:59 +0100122 memset(inptr, 0, sizeof(*inptr));
123 ret = sti_call(sti, sti->inq_conf, &default_conf_flags,
124 inptr, outptr, sti->glob_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 spin_unlock_irqrestore(&sti->lock, flags);
126 } while (ret == 1);
127}
128
129static const struct sti_font_flags default_font_flags = {
130 .wait = STI_WAIT,
131 .non_text = 0,
132};
133
134void
135sti_putc(struct sti_struct *sti, int c, int y, int x)
136{
Helge Deller02191322013-11-06 23:38:59 +0100137 struct sti_font_inptr *inptr = &sti->sti_data->font_inptr;
138 struct sti_font_inptr inptr_default = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 .font_start_addr= STI_PTR(sti->font->raw),
140 .index = c_index(sti, c),
141 .fg_color = c_fg(sti, c),
142 .bg_color = c_bg(sti, c),
143 .dest_x = x * sti->font_width,
144 .dest_y = y * sti->font_height,
145 };
Helge Deller02191322013-11-06 23:38:59 +0100146 struct sti_font_outptr *outptr = &sti->sti_data->font_outptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 s32 ret;
148 unsigned long flags;
149
150 do {
151 spin_lock_irqsave(&sti->lock, flags);
Helge Deller02191322013-11-06 23:38:59 +0100152 *inptr = inptr_default;
153 ret = sti_call(sti, sti->font_unpmv, &default_font_flags,
154 inptr, outptr, sti->glob_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 spin_unlock_irqrestore(&sti->lock, flags);
156 } while (ret == 1);
157}
158
159static const struct sti_blkmv_flags clear_blkmv_flags = {
160 .wait = STI_WAIT,
161 .color = 1,
162 .clear = 1,
163};
164
165void
166sti_set(struct sti_struct *sti, int src_y, int src_x,
167 int height, int width, u8 color)
168{
Helge Deller02191322013-11-06 23:38:59 +0100169 struct sti_blkmv_inptr *inptr = &sti->sti_data->blkmv_inptr;
170 struct sti_blkmv_inptr inptr_default = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 .fg_color = color,
172 .bg_color = color,
173 .src_x = src_x,
174 .src_y = src_y,
175 .dest_x = src_x,
176 .dest_y = src_y,
177 .width = width,
178 .height = height,
179 };
Helge Deller02191322013-11-06 23:38:59 +0100180 struct sti_blkmv_outptr *outptr = &sti->sti_data->blkmv_outptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 s32 ret;
182 unsigned long flags;
183
184 do {
185 spin_lock_irqsave(&sti->lock, flags);
Helge Deller02191322013-11-06 23:38:59 +0100186 *inptr = inptr_default;
187 ret = sti_call(sti, sti->block_move, &clear_blkmv_flags,
188 inptr, outptr, sti->glob_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 spin_unlock_irqrestore(&sti->lock, flags);
190 } while (ret == 1);
191}
192
193void
194sti_clear(struct sti_struct *sti, int src_y, int src_x,
195 int height, int width, int c)
196{
Helge Deller02191322013-11-06 23:38:59 +0100197 struct sti_blkmv_inptr *inptr = &sti->sti_data->blkmv_inptr;
198 struct sti_blkmv_inptr inptr_default = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 .fg_color = c_fg(sti, c),
200 .bg_color = c_bg(sti, c),
201 .src_x = src_x * sti->font_width,
202 .src_y = src_y * sti->font_height,
203 .dest_x = src_x * sti->font_width,
204 .dest_y = src_y * sti->font_height,
205 .width = width * sti->font_width,
206 .height = height* sti->font_height,
207 };
Helge Deller02191322013-11-06 23:38:59 +0100208 struct sti_blkmv_outptr *outptr = &sti->sti_data->blkmv_outptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 s32 ret;
210 unsigned long flags;
211
212 do {
213 spin_lock_irqsave(&sti->lock, flags);
Helge Deller02191322013-11-06 23:38:59 +0100214 *inptr = inptr_default;
215 ret = sti_call(sti, sti->block_move, &clear_blkmv_flags,
216 inptr, outptr, sti->glob_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 spin_unlock_irqrestore(&sti->lock, flags);
218 } while (ret == 1);
219}
220
221static const struct sti_blkmv_flags default_blkmv_flags = {
222 .wait = STI_WAIT,
223};
224
225void
226sti_bmove(struct sti_struct *sti, int src_y, int src_x,
227 int dst_y, int dst_x, int height, int width)
228{
Helge Deller02191322013-11-06 23:38:59 +0100229 struct sti_blkmv_inptr *inptr = &sti->sti_data->blkmv_inptr;
230 struct sti_blkmv_inptr inptr_default = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 .src_x = src_x * sti->font_width,
232 .src_y = src_y * sti->font_height,
233 .dest_x = dst_x * sti->font_width,
234 .dest_y = dst_y * sti->font_height,
235 .width = width * sti->font_width,
236 .height = height* sti->font_height,
237 };
Helge Deller02191322013-11-06 23:38:59 +0100238 struct sti_blkmv_outptr *outptr = &sti->sti_data->blkmv_outptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 s32 ret;
240 unsigned long flags;
241
242 do {
243 spin_lock_irqsave(&sti->lock, flags);
Helge Deller02191322013-11-06 23:38:59 +0100244 *inptr = inptr_default;
245 ret = sti_call(sti, sti->block_move, &default_blkmv_flags,
246 inptr, outptr, sti->glob_cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 spin_unlock_irqrestore(&sti->lock, flags);
248 } while (ret == 1);
249}
250
251
Kyle McMartin03b18f12007-06-29 02:17:50 -0400252static void sti_flush(unsigned long start, unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Kyle McMartin03b18f12007-06-29 02:17:50 -0400254 flush_icache_range(start, end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
256
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800257static void sti_rom_copy(unsigned long base, unsigned long count, void *dest)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 unsigned long dest_start = (unsigned long) dest;
260
261 /* this still needs to be revisited (see arch/parisc/mm/init.c:246) ! */
262 while (count >= 4) {
263 count -= 4;
264 *(u32 *)dest = gsc_readl(base);
265 base += 4;
266 dest += 4;
267 }
268 while (count) {
269 count--;
270 *(u8 *)dest = gsc_readb(base);
271 base++;
272 dest++;
273 }
274
Kyle McMartin03b18f12007-06-29 02:17:50 -0400275 sti_flush(dest_start, (unsigned long)dest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
278
279
280
Helge Dellercb6fc182006-01-17 12:40:40 -0700281static char default_sti_path[21] __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283#ifndef MODULE
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800284static int sti_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
286 if (str)
287 strlcpy (default_sti_path, str, sizeof (default_sti_path));
288
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800289 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
292/* Assuming the machine has multiple STI consoles (=graphic cards) which
293 * all get detected by sticon, the user may define with the linux kernel
294 * parameter sti=<x> which of them will be the initial boot-console.
295 * <x> is a number between 0 and MAX_STI_ROMS, with 0 as the default
296 * STI screen.
297 */
298__setup("sti=", sti_setup);
299#endif
300
301
302
Helge Deller02191322013-11-06 23:38:59 +0100303static char *font_name[MAX_STI_ROMS];
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800304static int font_index[MAX_STI_ROMS],
305 font_height[MAX_STI_ROMS],
306 font_width[MAX_STI_ROMS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307#ifndef MODULE
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800308static int sti_font_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
310 char *x;
311 int i = 0;
312
313 /* we accept sti_font=VGA8x16, sti_font=10x20, sti_font=10*20
314 * or sti_font=7 style command lines. */
315
316 while (i<MAX_STI_ROMS && str && *str) {
317 if (*str>='0' && *str<='9') {
318 if ((x = strchr(str, 'x')) || (x = strchr(str, '*'))) {
319 font_height[i] = simple_strtoul(str, NULL, 0);
320 font_width[i] = simple_strtoul(x+1, NULL, 0);
321 } else {
322 font_index[i] = simple_strtoul(str, NULL, 0);
323 }
324 } else {
325 font_name[i] = str; /* fb font name */
326 }
327
328 if ((x = strchr(str, ',')))
329 *x++ = 0;
330 str = x;
331
332 i++;
333 }
334
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800335 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
338/* The optional linux kernel parameter "sti_font" defines which font
339 * should be used by the sticon driver to draw characters to the screen.
340 * Possible values are:
341 * - sti_font=<fb_fontname>:
342 * <fb_fontname> is the name of one of the linux-kernel built-in
343 * framebuffer font names (e.g. VGA8x16, SUN22x18).
344 * This is only available if the fonts have been statically compiled
345 * in with e.g. the CONFIG_FONT_8x16 or CONFIG_FONT_SUN12x22 options.
346 * - sti_font=<number>
347 * most STI ROMs have built-in HP specific fonts, which can be selected
348 * by giving the desired number to the sticon driver.
349 * NOTE: This number is machine and STI ROM dependend.
350 * - sti_font=<height>x<width> (e.g. sti_font=16x8)
351 * <height> and <width> gives hints to the height and width of the
352 * font which the user wants. The sticon driver will try to use
353 * a font with this height and width, but if no suitable font is
354 * found, sticon will use the default 8x8 font.
355 */
356__setup("sti_font=", sti_font_setup);
357#endif
358
359
360
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800361static void sti_dump_globcfg(struct sti_glob_cfg *glob_cfg,
362 unsigned int sti_mem_request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
364 struct sti_glob_cfg_ext *cfg;
365
366 DPRINTK((KERN_INFO
367 "%d text planes\n"
368 "%4d x %4d screen resolution\n"
369 "%4d x %4d offscreen\n"
370 "%4d x %4d layout\n"
371 "regions at %08x %08x %08x %08x\n"
372 "regions at %08x %08x %08x %08x\n"
373 "reent_lvl %d\n"
374 "save_addr %08x\n",
375 glob_cfg->text_planes,
376 glob_cfg->onscreen_x, glob_cfg->onscreen_y,
377 glob_cfg->offscreen_x, glob_cfg->offscreen_y,
378 glob_cfg->total_x, glob_cfg->total_y,
379 glob_cfg->region_ptrs[0], glob_cfg->region_ptrs[1],
380 glob_cfg->region_ptrs[2], glob_cfg->region_ptrs[3],
381 glob_cfg->region_ptrs[4], glob_cfg->region_ptrs[5],
382 glob_cfg->region_ptrs[6], glob_cfg->region_ptrs[7],
383 glob_cfg->reent_lvl,
384 glob_cfg->save_addr));
385
386 /* dump extended cfg */
Helge Deller857600c2006-03-22 15:19:46 -0700387 cfg = PTR_STI((unsigned long)glob_cfg->ext_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 DPRINTK(( KERN_INFO
389 "monitor %d\n"
390 "in friendly mode: %d\n"
391 "power consumption %d watts\n"
392 "freq ref %d\n"
393 "sti_mem_addr %08x (size=%d bytes)\n",
394 cfg->curr_mon,
395 cfg->friendly_boot,
396 cfg->power,
397 cfg->freq_ref,
398 cfg->sti_mem_addr, sti_mem_request));
399}
400
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800401static void sti_dump_outptr(struct sti_struct *sti)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
403 DPRINTK((KERN_INFO
404 "%d bits per pixel\n"
405 "%d used bits\n"
406 "%d planes\n"
407 "attributes %08x\n",
Helge Deller02191322013-11-06 23:38:59 +0100408 sti->sti_data->inq_outptr.bits_per_pixel,
409 sti->sti_data->inq_outptr.bits_used,
410 sti->sti_data->inq_outptr.planes,
411 sti->sti_data->inq_outptr.attributes));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800414static int sti_init_glob_cfg(struct sti_struct *sti, unsigned long rom_address,
415 unsigned long hpa)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
417 struct sti_glob_cfg *glob_cfg;
418 struct sti_glob_cfg_ext *glob_cfg_ext;
419 void *save_addr;
420 void *sti_mem_addr;
Helge Deller02191322013-11-06 23:38:59 +0100421 int i, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Helge Deller02191322013-11-06 23:38:59 +0100423 if (sti->sti_mem_request < 256)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 sti->sti_mem_request = 256; /* STI default */
425
Helge Deller02191322013-11-06 23:38:59 +0100426 size = sizeof(struct sti_all_data) + sti->sti_mem_request - 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Helge Deller02191322013-11-06 23:38:59 +0100428 sti->sti_data = kzalloc(size, STI_LOWMEM);
429 if (!sti->sti_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 return -ENOMEM;
Helge Deller02191322013-11-06 23:38:59 +0100431
432 glob_cfg = &sti->sti_data->glob_cfg;
433 glob_cfg_ext = &sti->sti_data->glob_cfg_ext;
434 save_addr = &sti->sti_data->save_addr;
435 sti_mem_addr = &sti->sti_data->sti_mem_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 glob_cfg->ext_ptr = STI_PTR(glob_cfg_ext);
438 glob_cfg->save_addr = STI_PTR(save_addr);
439 for (i=0; i<8; i++) {
440 unsigned long newhpa, len;
441
442 if (sti->pd) {
443 unsigned char offs = sti->rm_entry[i];
444
445 if (offs == 0)
446 continue;
447 if (offs != PCI_ROM_ADDRESS &&
448 (offs < PCI_BASE_ADDRESS_0 ||
449 offs > PCI_BASE_ADDRESS_5)) {
450 printk (KERN_WARNING
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200451 "STI pci region mapping for region %d (%02x) can't be mapped\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 i,sti->rm_entry[i]);
453 continue;
454 }
455 newhpa = pci_resource_start (sti->pd, (offs - PCI_BASE_ADDRESS_0) / 4);
456 } else
457 newhpa = (i == 0) ? rom_address : hpa;
458
459 sti->regions_phys[i] =
460 REGION_OFFSET_TO_PHYS(sti->regions[i], newhpa);
461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 len = sti->regions[i].region_desc.length * 4096;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 if (len)
464 glob_cfg->region_ptrs[i] = sti->regions_phys[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Helge Deller857600c2006-03-22 15:19:46 -0700466 DPRINTK(("region #%d: phys %08lx, region_ptr %08x, len=%lukB, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 "btlb=%d, sysonly=%d, cache=%d, last=%d\n",
468 i, sti->regions_phys[i], glob_cfg->region_ptrs[i],
469 len/1024,
470 sti->regions[i].region_desc.btlb,
471 sti->regions[i].region_desc.sys_only,
472 sti->regions[i].region_desc.cache,
473 sti->regions[i].region_desc.last));
474
475 /* last entry reached ? */
476 if (sti->regions[i].region_desc.last)
477 break;
478 }
479
480 if (++i<8 && sti->regions[i].region)
481 printk(KERN_WARNING "%s: *future ptr (0x%8x) not yet supported !\n",
482 __FILE__, sti->regions[i].region);
483
484 glob_cfg_ext->sti_mem_addr = STI_PTR(sti_mem_addr);
485
486 sti->glob_cfg = glob_cfg;
487
488 return 0;
489}
490
Helge Deller8a10bc92014-01-31 15:39:40 +0100491#ifdef CONFIG_FONT_SUPPORT
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800492static struct sti_cooked_font *
493sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494{
Helge Deller02191322013-11-06 23:38:59 +0100495 const struct font_desc *fbfont = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 unsigned int size, bpc;
497 void *dest;
498 struct sti_rom_font *nf;
499 struct sti_cooked_font *cooked_font;
500
Helge Deller02191322013-11-06 23:38:59 +0100501 if (fbfont_name && strlen(fbfont_name))
502 fbfont = find_font(fbfont_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (!fbfont)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -0700504 fbfont = get_default_font(1024,768, ~(u32)0, ~(u32)0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (!fbfont)
Matthew Wilcox951a0152005-10-21 22:41:49 -0400506 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Helge Deller02191322013-11-06 23:38:59 +0100508 pr_info("STI selected %dx%d framebuffer font %s for sticon\n",
509 fbfont->width, fbfont->height, fbfont->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 bpc = ((fbfont->width+7)/8) * fbfont->height;
512 size = bpc * 256;
513 size += sizeof(struct sti_rom_font);
514
Helge Deller02191322013-11-06 23:38:59 +0100515 nf = kzalloc(size, STI_LOWMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 if (!nf)
Matthew Wilcox951a0152005-10-21 22:41:49 -0400517 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 nf->first_char = 0;
520 nf->last_char = 255;
521 nf->width = fbfont->width;
522 nf->height = fbfont->height;
523 nf->font_type = STI_FONT_HPROMAN8;
524 nf->bytes_per_char = bpc;
525 nf->next_font = 0;
526 nf->underline_height = 1;
527 nf->underline_pos = fbfont->height - nf->underline_height;
528
529 dest = nf;
530 dest += sizeof(struct sti_rom_font);
531 memcpy(dest, fbfont->data, bpc*256);
532
Helge Dellercb6fc182006-01-17 12:40:40 -0700533 cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 if (!cooked_font) {
Matthew Wilcox951a0152005-10-21 22:41:49 -0400535 kfree(nf);
536 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 }
538
539 cooked_font->raw = nf;
540 cooked_font->next_font = NULL;
541
542 cooked_rom->font_start = cooked_font;
543
544 return cooked_font;
545}
546#else
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800547static struct sti_cooked_font *
548sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
550 return NULL;
551}
552#endif
553
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800554static struct sti_cooked_font *sti_select_font(struct sti_cooked_rom *rom,
555 int (*search_font_fnc)(struct sti_cooked_rom *, int, int))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
557 struct sti_cooked_font *font;
558 int i;
559 int index = num_sti_roms;
560
561 /* check for framebuffer-font first */
562 if ((font = sti_select_fbfont(rom, font_name[index])))
563 return font;
564
565 if (font_width[index] && font_height[index])
566 font_index[index] = search_font_fnc(rom,
567 font_height[index], font_width[index]);
568
569 for (font = rom->font_start, i = font_index[index];
570 font && (i > 0);
571 font = font->next_font, i--);
572
573 if (font)
574 return font;
575 else
576 return rom->font_start;
577}
578
579
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800580static void sti_dump_rom(struct sti_rom *rom)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Matthew Wilcox951a0152005-10-21 22:41:49 -0400582 printk(KERN_INFO " id %04x-%04x, conforms to spec rev. %d.%02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 rom->graphics_id[0],
584 rom->graphics_id[1],
585 rom->revno[0] >> 4,
586 rom->revno[0] & 0x0f);
587 DPRINTK((" supports %d monitors\n", rom->num_mons));
588 DPRINTK((" font start %08x\n", rom->font_start));
589 DPRINTK((" region list %08x\n", rom->region_list));
590 DPRINTK((" init_graph %08x\n", rom->init_graph));
591 DPRINTK((" bus support %02x\n", rom->bus_support));
592 DPRINTK((" ext bus support %02x\n", rom->ext_bus_support));
593 DPRINTK((" alternate code type %d\n", rom->alt_code_type));
594}
595
596
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800597static int sti_cook_fonts(struct sti_cooked_rom *cooked_rom,
598 struct sti_rom *raw_rom)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
600 struct sti_rom_font *raw_font, *font_start;
601 struct sti_cooked_font *cooked_font;
602
Helge Dellercb6fc182006-01-17 12:40:40 -0700603 cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 if (!cooked_font)
605 return 0;
606
607 cooked_rom->font_start = cooked_font;
608
609 raw_font = ((void *)raw_rom) + (raw_rom->font_start);
610
611 font_start = raw_font;
612 cooked_font->raw = raw_font;
613
614 while (raw_font->next_font) {
615 raw_font = ((void *)font_start) + (raw_font->next_font);
616
Helge Dellercb6fc182006-01-17 12:40:40 -0700617 cooked_font->next_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 if (!cooked_font->next_font)
619 return 1;
620
621 cooked_font = cooked_font->next_font;
622
623 cooked_font->raw = raw_font;
624 }
625
626 cooked_font->next_font = NULL;
627 return 1;
628}
629
630
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800631static int sti_search_font(struct sti_cooked_rom *rom, int height, int width)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
633 struct sti_cooked_font *font;
634 int i = 0;
635
Matthew Wilcox951a0152005-10-21 22:41:49 -0400636 for (font = rom->font_start; font; font = font->next_font, i++) {
637 if ((font->raw->width == width) &&
638 (font->raw->height == height))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 return i;
640 }
641 return 0;
642}
643
Matthew Wilcox951a0152005-10-21 22:41:49 -0400644#define BMODE_RELOCATE(offset) offset = (offset) / 4;
645#define BMODE_LAST_ADDR_OFFS 0x50
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800647static void *sti_bmode_font_raw(struct sti_cooked_font *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648{
649 unsigned char *n, *p, *q;
650 int size = f->raw->bytes_per_char*256+sizeof(struct sti_rom_font);
651
Helge Deller02191322013-11-06 23:38:59 +0100652 n = kzalloc(4*size, STI_LOWMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 if (!n)
654 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 p = n + 3;
656 q = (unsigned char *)f->raw;
657 while (size--) {
658 *p = *q++;
659 p+=4;
660 }
661 return n + 3;
662}
663
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800664static void sti_bmode_rom_copy(unsigned long base, unsigned long count,
665 void *dest)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 unsigned long dest_start = (unsigned long) dest;
668
669 while (count) {
670 count--;
671 *(u8 *)dest = gsc_readl(base);
672 base += 4;
673 dest++;
674 }
Kyle McMartin03b18f12007-06-29 02:17:50 -0400675
676 sti_flush(dest_start, (unsigned long)dest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677}
678
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800679static struct sti_rom *sti_get_bmode_rom (unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
681 struct sti_rom *raw;
682 u32 size;
Matthew Wilcox951a0152005-10-21 22:41:49 -0400683 struct sti_rom_font *raw_font, *font_start;
684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 sti_bmode_rom_copy(address + BMODE_LAST_ADDR_OFFS, sizeof(size), &size);
Matthew Wilcox951a0152005-10-21 22:41:49 -0400686
687 size = (size+3) / 4;
Helge Deller02191322013-11-06 23:38:59 +0100688 raw = kmalloc(size, STI_LOWMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 if (raw) {
Matthew Wilcox951a0152005-10-21 22:41:49 -0400690 sti_bmode_rom_copy(address, size, raw);
691 memmove (&raw->res004, &raw->type[0], 0x3c);
692 raw->type[3] = raw->res004;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Matthew Wilcox951a0152005-10-21 22:41:49 -0400694 BMODE_RELOCATE (raw->region_list);
695 BMODE_RELOCATE (raw->font_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Matthew Wilcox951a0152005-10-21 22:41:49 -0400697 BMODE_RELOCATE (raw->init_graph);
698 BMODE_RELOCATE (raw->state_mgmt);
699 BMODE_RELOCATE (raw->font_unpmv);
700 BMODE_RELOCATE (raw->block_move);
701 BMODE_RELOCATE (raw->inq_conf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Matthew Wilcox951a0152005-10-21 22:41:49 -0400703 raw_font = ((void *)raw) + raw->font_start;
704 font_start = raw_font;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Matthew Wilcox951a0152005-10-21 22:41:49 -0400706 while (raw_font->next_font) {
707 BMODE_RELOCATE (raw_font->next_font);
708 raw_font = ((void *)font_start) + raw_font->next_font;
709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 }
Matthew Wilcox951a0152005-10-21 22:41:49 -0400711 return raw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712}
713
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800714static struct sti_rom *sti_get_wmode_rom(unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715{
716 struct sti_rom *raw;
717 unsigned long size;
Matthew Wilcox951a0152005-10-21 22:41:49 -0400718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 /* read the ROM size directly from the struct in ROM */
720 size = gsc_readl(address + offsetof(struct sti_rom,last_addr));
721
Helge Deller02191322013-11-06 23:38:59 +0100722 raw = kmalloc(size, STI_LOWMEM);
Matthew Wilcox951a0152005-10-21 22:41:49 -0400723 if (raw)
724 sti_rom_copy(address, size, raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Matthew Wilcox951a0152005-10-21 22:41:49 -0400726 return raw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727}
728
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800729static int sti_read_rom(int wordmode, struct sti_struct *sti,
730 unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
732 struct sti_cooked_rom *cooked;
733 struct sti_rom *raw = NULL;
Helge Dellerfdac4e62008-07-29 22:33:01 -0700734 unsigned long revno;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736 cooked = kmalloc(sizeof *cooked, GFP_KERNEL);
737 if (!cooked)
738 goto out_err;
739
Matthew Wilcox951a0152005-10-21 22:41:49 -0400740 if (wordmode)
741 raw = sti_get_wmode_rom (address);
742 else
743 raw = sti_get_bmode_rom (address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Matthew Wilcox951a0152005-10-21 22:41:49 -0400745 if (!raw)
746 goto out_err;
747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 if (!sti_cook_fonts(cooked, raw)) {
749 printk(KERN_ERR "No font found for STI at %08lx\n", address);
750 goto out_err;
751 }
752
753 if (raw->region_list)
754 memcpy(sti->regions, ((void *)raw)+raw->region_list, sizeof(sti->regions));
755
756 address = (unsigned long) STI_PTR(raw);
757
Helge Deller02191322013-11-06 23:38:59 +0100758 pr_info("STI ROM supports 32 %sbit firmware functions.\n",
759 raw->alt_code_type == ALT_CODE_TYPE_PA_RISC_64
760 ? "and 64 " : "");
761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 sti->font_unpmv = address + (raw->font_unpmv & 0x03ffffff);
763 sti->block_move = address + (raw->block_move & 0x03ffffff);
764 sti->init_graph = address + (raw->init_graph & 0x03ffffff);
765 sti->inq_conf = address + (raw->inq_conf & 0x03ffffff);
766
767 sti->rom = cooked;
768 sti->rom->raw = raw;
769
770 sti->font = sti_select_font(sti->rom, sti_search_font);
771 sti->font_width = sti->font->raw->width;
772 sti->font_height = sti->font->raw->height;
773 if (!wordmode)
Matthew Wilcox951a0152005-10-21 22:41:49 -0400774 sti->font->raw = sti_bmode_font_raw(sti->font);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 sti->sti_mem_request = raw->sti_mem_req;
777 sti->graphics_id[0] = raw->graphics_id[0];
778 sti->graphics_id[1] = raw->graphics_id[1];
779
780 sti_dump_rom(raw);
Helge Dellerfdac4e62008-07-29 22:33:01 -0700781
782 /* check if the ROM routines in this card are compatible */
783 if (wordmode || sti->graphics_id[1] != 0x09A02587)
784 goto ok;
785
786 revno = (raw->revno[0] << 8) | raw->revno[1];
787
788 switch (sti->graphics_id[0]) {
789 case S9000_ID_HCRX:
790 /* HyperA or HyperB ? */
791 if (revno == 0x8408 || revno == 0x840b)
792 goto msg_not_supported;
793 break;
794 case CRT_ID_THUNDER:
795 if (revno == 0x8509)
796 goto msg_not_supported;
797 break;
798 case CRT_ID_THUNDER2:
799 if (revno == 0x850c)
800 goto msg_not_supported;
801 }
802ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 return 1;
804
Helge Dellerfdac4e62008-07-29 22:33:01 -0700805msg_not_supported:
806 printk(KERN_ERR "Sorry, this GSC/STI card is not yet supported.\n");
807 printk(KERN_ERR "Please see http://parisc-linux.org/faq/"
808 "graphics-howto.html for more info.\n");
809 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810out_err:
811 kfree(raw);
812 kfree(cooked);
813 return 0;
814}
815
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800816static struct sti_struct *sti_try_rom_generic(unsigned long address,
817 unsigned long hpa,
818 struct pci_dev *pd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819{
820 struct sti_struct *sti;
821 int ok;
822 u32 sig;
823
824 if (num_sti_roms >= MAX_STI_ROMS) {
Matthew Wilcox951a0152005-10-21 22:41:49 -0400825 printk(KERN_WARNING "maximum number of STI ROMS reached !\n");
826 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
828
Helge Dellercb6fc182006-01-17 12:40:40 -0700829 sti = kzalloc(sizeof(*sti), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 if (!sti) {
Matthew Wilcox951a0152005-10-21 22:41:49 -0400831 printk(KERN_ERR "Not enough memory !\n");
832 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 }
Matthew Wilcox951a0152005-10-21 22:41:49 -0400834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 spin_lock_init(&sti->lock);
836
837test_rom:
838 /* if we can't read the ROM, bail out early. Not being able
839 * to read the hpa is okay, for romless sti */
840 if (pdc_add_valid(address))
841 goto out_err;
842
843 sig = gsc_readl(address);
844
845 /* check for a PCI ROM structure */
846 if ((le32_to_cpu(sig)==0xaa55)) {
847 unsigned int i, rm_offset;
848 u32 *rm;
849 i = gsc_readl(address+0x04);
850 if (i != 1) {
851 /* The ROM could have multiple architecture
852 * dependent images (e.g. i386, parisc,...) */
853 printk(KERN_WARNING
854 "PCI ROM is not a STI ROM type image (0x%8x)\n", i);
855 goto out_err;
856 }
857
858 sti->pd = pd;
859
860 i = gsc_readl(address+0x0c);
861 DPRINTK(("PCI ROM size (from header) = %d kB\n",
862 le16_to_cpu(i>>16)*512/1024));
863 rm_offset = le16_to_cpu(i & 0xffff);
864 if (rm_offset) {
865 /* read 16 bytes from the pci region mapper array */
866 rm = (u32*) &sti->rm_entry;
867 *rm++ = gsc_readl(address+rm_offset+0x00);
868 *rm++ = gsc_readl(address+rm_offset+0x04);
869 *rm++ = gsc_readl(address+rm_offset+0x08);
870 *rm++ = gsc_readl(address+rm_offset+0x0c);
871 DPRINTK(("PCI region Mapper offset = %08x: ",
872 rm_offset));
873 for (i=0; i<16; i++)
874 DPRINTK(("%02x ", sti->rm_entry[i]));
875 DPRINTK(("\n"));
876 }
877
878 address += le32_to_cpu(gsc_readl(address+8));
879 DPRINTK(("sig %04x, PCI STI ROM at %08lx\n", sig, address));
880 goto test_rom;
881 }
882
883 ok = 0;
884
885 if ((sig & 0xff) == 0x01) {
886 DPRINTK((" byte mode ROM at %08lx, hpa at %08lx\n",
887 address, hpa));
888 ok = sti_read_rom(0, sti, address);
889 }
890
891 if ((sig & 0xffff) == 0x0303) {
892 DPRINTK((" word mode ROM at %08lx, hpa at %08lx\n",
893 address, hpa));
894 ok = sti_read_rom(1, sti, address);
895 }
896
897 if (!ok)
898 goto out_err;
899
900 if (sti_init_glob_cfg(sti, address, hpa))
901 goto out_err; /* not enough memory */
902
903 /* disable STI PCI ROM. ROM and card RAM overlap and
904 * leaving it enabled would force HPMCs
905 */
906 if (sti->pd) {
907 unsigned long rom_base;
908 rom_base = pci_resource_start(sti->pd, PCI_ROM_RESOURCE);
909 pci_write_config_dword(sti->pd, PCI_ROM_ADDRESS, rom_base & ~PCI_ROM_ADDRESS_ENABLE);
910 DPRINTK((KERN_DEBUG "STI PCI ROM disabled\n"));
911 }
912
913 if (sti_init_graph(sti))
914 goto out_err;
915
916 sti_inq_conf(sti);
917 sti_dump_globcfg(sti->glob_cfg, sti->sti_mem_request);
918 sti_dump_outptr(sti);
919
Helge Deller02191322013-11-06 23:38:59 +0100920 pr_info(" graphics card name: %s\n",
921 sti->sti_data->inq_outptr.dev_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
923 sti_roms[num_sti_roms] = sti;
924 num_sti_roms++;
925
926 return sti;
927
928out_err:
929 kfree(sti);
930 return NULL;
931}
932
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800933static void sticore_check_for_default_sti(struct sti_struct *sti, char *path)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
935 if (strcmp (path, default_sti_path) == 0)
936 default_sti = sti;
937}
938
939/*
940 * on newer systems PDC gives the address of the ROM
941 * in the additional address field addr[1] while on
942 * older Systems the PDC stores it in page0->proc_sti
943 */
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800944static int sticore_pa_init(struct parisc_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 char pa_path[21];
947 struct sti_struct *sti = NULL;
Matthew Wilcox951a0152005-10-21 22:41:49 -0400948 int hpa = dev->hpa.start;
949
950 if (dev->num_addrs && dev->addr[0])
951 sti = sti_try_rom_generic(dev->addr[0], hpa, NULL);
952 if (!sti)
953 sti = sti_try_rom_generic(hpa, hpa, NULL);
954 if (!sti)
955 sti = sti_try_rom_generic(PAGE0->proc_sti, hpa, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 if (!sti)
957 return 1;
Matthew Wilcox951a0152005-10-21 22:41:49 -0400958
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 print_pa_hwpath(dev, pa_path);
Matthew Wilcox951a0152005-10-21 22:41:49 -0400960 sticore_check_for_default_sti(sti, pa_path);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 return 0;
962}
963
964
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800965static int sticore_pci_init(struct pci_dev *pd, const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
967#ifdef CONFIG_PCI
968 unsigned long fb_base, rom_base;
969 unsigned int fb_len, rom_len;
Helge Deller1a1dba32009-08-02 15:26:51 +0200970 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 struct sti_struct *sti;
972
Helge Deller1a1dba32009-08-02 15:26:51 +0200973 err = pci_enable_device(pd);
974 if (err < 0) {
975 dev_err(&pd->dev, "Cannot enable PCI device\n");
976 return err;
977 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 fb_base = pci_resource_start(pd, 0);
980 fb_len = pci_resource_len(pd, 0);
981 rom_base = pci_resource_start(pd, PCI_ROM_RESOURCE);
982 rom_len = pci_resource_len(pd, PCI_ROM_RESOURCE);
983 if (rom_base) {
984 pci_write_config_dword(pd, PCI_ROM_ADDRESS, rom_base | PCI_ROM_ADDRESS_ENABLE);
985 DPRINTK((KERN_DEBUG "STI PCI ROM enabled at 0x%08lx\n", rom_base));
986 }
987
988 printk(KERN_INFO "STI PCI graphic ROM found at %08lx (%u kB), fb at %08lx (%u MB)\n",
989 rom_base, rom_len/1024, fb_base, fb_len/1024/1024);
990
991 DPRINTK((KERN_DEBUG "Trying PCI STI ROM at %08lx, PCI hpa at %08lx\n",
992 rom_base, fb_base));
993
994 sti = sti_try_rom_generic(rom_base, fb_base, pd);
995 if (sti) {
996 char pa_path[30];
997 print_pci_hwpath(pd, pa_path);
998 sticore_check_for_default_sti(sti, pa_path);
999 }
1000
1001 if (!sti) {
1002 printk(KERN_WARNING "Unable to handle STI device '%s'\n",
1003 pci_name(pd));
1004 return -ENODEV;
1005 }
1006#endif /* CONFIG_PCI */
1007
1008 return 0;
1009}
1010
1011
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -08001012static void sticore_pci_remove(struct pci_dev *pd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
1014 BUG();
1015}
1016
1017
1018static struct pci_device_id sti_pci_tbl[] = {
1019 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_EG) },
1020 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX6) },
1021 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX4) },
1022 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX2) },
1023 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FXE) },
1024 { 0, } /* terminate list */
1025};
1026MODULE_DEVICE_TABLE(pci, sti_pci_tbl);
1027
1028static struct pci_driver pci_sti_driver = {
1029 .name = "sti",
1030 .id_table = sti_pci_tbl,
1031 .probe = sticore_pci_init,
1032 .remove = sticore_pci_remove,
1033};
1034
1035static struct parisc_device_id sti_pa_tbl[] = {
1036 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00077 },
1037 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00085 },
1038 { 0, }
1039};
1040
1041static struct parisc_driver pa_sti_driver = {
1042 .name = "sti",
1043 .id_table = sti_pa_tbl,
1044 .probe = sticore_pa_init,
1045};
1046
1047
1048/*
1049 * sti_init_roms() - detects all STI ROMs and stores them in sti_roms[]
1050 */
1051
Helge Dellercb6fc182006-01-17 12:40:40 -07001052static int sticore_initialized __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -08001054static void sti_init_roms(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055{
1056 if (sticore_initialized)
1057 return;
1058
1059 sticore_initialized = 1;
1060
1061 printk(KERN_INFO "STI GSC/PCI core graphics driver "
1062 STI_DRIVERVERSION "\n");
1063
1064 /* Register drivers for native & PCI cards */
1065 register_parisc_driver(&pa_sti_driver);
Helge Deller1a1dba32009-08-02 15:26:51 +02001066 WARN_ON(pci_register_driver(&pci_sti_driver));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 /* if we didn't find the given default sti, take the first one */
1069 if (!default_sti)
1070 default_sti = sti_roms[0];
1071
1072}
1073
1074/*
1075 * index = 0 gives default sti
1076 * index > 0 gives other stis in detection order
1077 */
1078struct sti_struct * sti_get_rom(unsigned int index)
1079{
1080 if (!sticore_initialized)
1081 sti_init_roms();
1082
1083 if (index == 0)
1084 return default_sti;
1085
1086 if (index > num_sti_roms)
1087 return NULL;
1088
1089 return sti_roms[index-1];
1090}
1091EXPORT_SYMBOL(sti_get_rom);
1092
Helge Deller02191322013-11-06 23:38:59 +01001093
1094int sti_call(const struct sti_struct *sti, unsigned long func,
1095 const void *flags, void *inptr, void *outptr,
1096 struct sti_glob_cfg *glob_cfg)
1097{
1098 unsigned long _flags = STI_PTR(flags);
1099 unsigned long _inptr = STI_PTR(inptr);
1100 unsigned long _outptr = STI_PTR(outptr);
1101 unsigned long _glob_cfg = STI_PTR(glob_cfg);
1102 int ret;
1103
1104#ifdef CONFIG_64BIT
1105 /* Check for overflow when using 32bit STI on 64bit kernel. */
1106 if (WARN_ONCE(_flags>>32 || _inptr>>32 || _outptr>>32 || _glob_cfg>>32,
1107 "Out of 32bit-range pointers!"))
1108 return -1;
1109#endif
1110
1111 ret = pdc_sti_call(func, _flags, _inptr, _outptr, _glob_cfg);
1112
1113 return ret;
1114}
1115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116MODULE_AUTHOR("Philipp Rumpf, Helge Deller, Thomas Bogendoerfer");
1117MODULE_DESCRIPTION("Core STI driver for HP's NGLE series graphics cards in HP PARISC machines");
1118MODULE_LICENSE("GPL v2");
1119