summaryrefslogtreecommitdiffstats
path: root/drivers/sbus/char/leo.c
blob: e08cf182252d2016898db1578b5d79c07ff8f3c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
/* $Id: leo.c,v 1.25 1997/08/22 17:33:58 jj Exp $
 * leo.c: SUNW,leo 24/8bit frame buffer driver
 *
 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
 * Copyright (C) 1997 Michal Rehacek (Michal.Rehacek@st.mff.cuni.cz)
 */
 
#include <linux/kd.h>
#include <linux/tty.h>
#include <linux/malloc.h>
#include <linux/proc_fs.h>
#include <linux/delay.h>

#include <asm/sbus.h>
#include <asm/io.h>
#include <asm/fbio.h>
#include <asm/pgtable.h>
#include <asm/uaccess.h>

/* These must be included after asm/fbio.h */
#include <linux/vt_kern.h>
#include <linux/selection.h>
#include <linux/console_struct.h>
#include "fb.h"
#include "cg_common.h"

#define LEO_OFF_LC_SS0_KRN	0x00200000
#define LEO_OFF_LC_SS0_USR	0x00201000
#define LEO_OFF_LC_SS1_KRN	0x01200000
#define LEO_OFF_LC_SS1_USR	0x01201000
#define LEO_OFF_LD_SS0		0x00400000
#define LEO_OFF_LD_SS1		0x01400000
#define LEO_OFF_LD_GBL		0x00401000
#define LEO_OFF_LX_KRN		0x00600000
#define LEO_OFF_LX_CURSOR	0x00601000
#define LEO_OFF_SS0		0x00800000
#define LEO_OFF_SS1		0x01800000
#define LEO_OFF_UNK		0x00602000
#define LEO_OFF_UNK2		0x00000000

#define LEO_CUR_ENABLE		0x00000080
#define LEO_CUR_UPDATE		0x00000030
#define LEO_CUR_PROGRESS	0x00000006
#define LEO_CUR_UPDATECMAP	0x00000003

#define LEO_CUR_TYPE_MASK	0x00000000
#define LEO_CUR_TYPE_IMAGE	0x00000020
#define LEO_CUR_TYPE_CMAP	0x00000050

struct leo_cursor {
	u8		xxx0[16];
	volatile u32	cur_type;
	volatile u32	cur_misc;
	volatile u32	cur_cursxy;
	volatile u32	cur_data;
};

#define LEO_KRN_TYPE_CLUT0	0x00001000
#define LEO_KRN_TYPE_CLUT1	0x00001001
#define LEO_KRN_TYPE_CLUT2	0x00001002
#define LEO_KRN_TYPE_WID	0x00001003
#define LEO_KRN_TYPE_UNK	0x00001006
#define LEO_KRN_TYPE_VIDEO	0x00002003
#define LEO_KRN_TYPE_CLUTDATA	0x00004000
#define LEO_KRN_CSR_ENABLE	0x00000008
#define LEO_KRN_CSR_PROGRESS	0x00000004
#define LEO_KRN_CSR_UNK		0x00000002
#define LEO_KRN_CSR_UNK2	0x00000001

struct leo_lx_krn {
	volatile u32	krn_type;
	volatile u32	krn_csr;
	volatile u32	krn_value;
};

struct leo_lc_ss0_krn {
	volatile u32 	misc;
	u8		xxx0[0x800-4];
	volatile u32	rev;
};

struct leo_lc_ss0_usr {
	volatile u32	csr;
	volatile u32	attrs;
	volatile u32 	fontc;
	volatile u32	fontc2;
	volatile u32	extent;
	volatile u32	src;
	u32		xxx1[1];
	volatile u32	copy;
	volatile u32	fill;
};

struct leo_lc_ss1_krn {
	u8	unknown;
};

struct leo_lc_ss1_usr {
	u8	unknown;
};

struct leo_ld_ss0 {
	u8		xxx0[0xe00];
	u32		xxx1[2];
	volatile u32	unk;
	u32		xxx2[1];
	volatile u32	unk2;
	volatile u32	unk3;
	u32		xxx3[2];
	volatile u32	fg;
	volatile u32	bg;
	u8		xxx4[0x05c];
	volatile u32	planemask;
	volatile u32	rop;
};

#define LEO_SS1_MISC_ENABLE	0x00000001
#define LEO_SS1_MISC_STEREO	0x00000002
struct leo_ld_ss1 {
	u8		xxx0[0xef4];
	volatile u32	ss1_misc;
};

struct leo_ld_gbl {
	u8	unknown;
};

static void leo_blitc(unsigned short, int, int);
static void leo_setw(int, int, unsigned short, int);
static void leo_cpyw(int, int, unsigned short *, int);
static void leo_fill(int, int, int *);
static void leo_penguin(int,int,int);

static void
leo_restore_palette (fbinfo_t *fb)
{
	fb->info.leo.ld_ss1->ss1_misc &= ~(LEO_SS1_MISC_ENABLE);
}

/* Ugh: X wants to mmap a bunch of cute stuff at the same time :-( */
/* So, we just mmap the things that are being asked for */
static int
leo_mmap (struct inode *inode, struct file *file, struct vm_area_struct *vma,
	  long base, fbinfo_t *fb)
{
	uint size, page, r, map_size = 0;
	unsigned long map_offset = 0;
			     
	size = vma->vm_end - vma->vm_start;
        if (vma->vm_offset & ~PAGE_MASK)
                return -ENXIO;

	/* To stop the swapper from even considering these pages */
	vma->vm_flags |= FB_MMAP_VM_FLAGS;
	
	/* Each page, see which map applies */
	for (page = 0; page < size; ){
		switch (vma->vm_offset+page){
		case LEO_SS0_MAP:
			map_size = 0x800000;
			map_offset = get_phys ((unsigned long)fb->base);
			break;
		case LEO_LC_SS0_USR_MAP:
			map_size = PAGE_SIZE;
			map_offset = get_phys ((unsigned long)fb->info.leo.lc_ss0_usr);
			break;
		case LEO_LD_SS0_MAP:
			map_size = PAGE_SIZE;
			map_offset = get_phys ((unsigned long)fb->info.leo.ld_ss0);
			break;
		case LEO_LX_CURSOR_MAP:
			map_size = PAGE_SIZE;
			map_offset = get_phys ((unsigned long)fb->info.leo.cursor);
			break;
		case LEO_SS1_MAP:	
			map_size = 0x800000;
			map_offset = fb->info.leo.offset + LEO_OFF_SS1;
			break;
		case LEO_LC_SS1_USR_MAP:
			map_size = PAGE_SIZE;
			map_offset = get_phys ((unsigned long)fb->info.leo.lc_ss1_usr);
			break;
		case LEO_LD_SS1_MAP:
			map_size = PAGE_SIZE;
			map_offset = get_phys ((unsigned long)fb->info.leo.ld_ss1);
			break;
		case LEO_UNK_MAP:	
			map_size = PAGE_SIZE;
			map_offset = fb->info.leo.offset + LEO_OFF_UNK;
			break;
		case LEO_LX_KRN_MAP:
			map_size = PAGE_SIZE;
			map_offset = get_phys ((unsigned long)fb->info.leo.lx_krn);
			break;
		case LEO_LC_SS0_KRN_MAP:
			map_size = PAGE_SIZE;
			map_offset = get_phys ((unsigned long)fb->info.leo.lc_ss0_krn);
			break;
		case LEO_LC_SS1_KRN_MAP:
			map_size = PAGE_SIZE;
			map_offset = get_phys ((unsigned long)fb->info.leo.lc_ss1_krn);
			break;
		case LEO_LD_GBL_MAP:
			map_size = PAGE_SIZE;
			map_offset = get_phys ((unsigned long)fb->info.leo.ld_gbl);
			break;
		case LEO_UNK2_MAP:
			map_size = 0x100000;
			map_offset = fb->info.leo.offset + LEO_OFF_UNK2;
			break;
		}
		if (!map_size){
			page += PAGE_SIZE;
			continue;
		}
		if (page + map_size > size)
			map_size = size - page;
		r = io_remap_page_range (vma->vm_start+page,
					 map_offset,
					 map_size, vma->vm_page_prot,
					 fb->space);
		if (r)
			return -EAGAIN;
		page += map_size;
	}

	vma->vm_dentry = dget(file->f_dentry);
        return 0;
}

static void
leo_setcursormap (fbinfo_t *fb, unsigned char *red,
				 unsigned char *green,
				 unsigned char *blue)
{
	struct leo_cursor *l = fb->info.leo.cursor;
	int i;

	for (i = 0; (l->cur_misc & LEO_CUR_PROGRESS) && i < 300000; i++)
		udelay (1); /* Busy wait at most 0.3 sec */
	if (i == 300000) return; /* Timed out - should we print some message? */
	l->cur_type = LEO_CUR_TYPE_CMAP;
	l->cur_data = (red[0] | (green[0]<<8) | (blue[0]<<16));
	l->cur_data = (red[1] | (green[1]<<8) | (blue[1]<<16));
	l->cur_misc = LEO_CUR_UPDATECMAP;
}

/* Load cursor information */
static void
leo_setcursor (fbinfo_t *fb)
{
	struct cg_cursor *c = &fb->cursor;
	struct leo_cursor *l = fb->info.leo.cursor;

	l->cur_misc &= ~LEO_CUR_ENABLE;
	l->cur_cursxy = ((c->cpos.fbx - c->chot.fbx) & 0x7ff)
			|(((c->cpos.fby - c->chot.fby) & 0x7ff) << 11);
	l->cur_misc |= LEO_CUR_UPDATE;
	if (c->enable)
		l->cur_misc |= LEO_CUR_ENABLE;
}

/* Set cursor shape */
static void
leo_setcurshape (fbinfo_t *fb)
{
	int i, j, k;
	u32 m, n, mask;
	struct leo_cursor *l = fb->info.leo.cursor;

	l->cur_misc &= ~LEO_CUR_ENABLE;
	for (k = 0; k < 2; k ++) {
		l->cur_type = (k * LEO_CUR_TYPE_IMAGE); /* LEO_CUR_TYPE_MASK is 0 */
		for (i = 0; i < 32; i++) {
			mask = 0;
			m = fb->cursor.bits[k][i];
			/* mask = m with reversed bit order */
			for (j = 0, n = 1; j < 32; j++, n <<= 1)
				if (m & n)
					mask |= (0x80000000 >> j);
			l->cur_data = mask;
		}
	}
	l->cur_misc |= LEO_CUR_ENABLE;
}

static void
leo_blank (fbinfo_t *fb)
{
	fb->info.leo.lx_krn->krn_type = LEO_KRN_TYPE_VIDEO;
	fb->info.leo.lx_krn->krn_csr &= ~LEO_KRN_CSR_ENABLE;
}

static void
leo_unblank (fbinfo_t *fb)
{
	fb->info.leo.lx_krn->krn_type = LEO_KRN_TYPE_VIDEO;
	if (!(fb->info.leo.lx_krn->krn_csr & LEO_KRN_CSR_ENABLE))
		fb->info.leo.lx_krn->krn_csr |= LEO_KRN_CSR_ENABLE;
}

static int leo_wait (struct leo_lx_krn *lx_krn)
{
	int i;
	for (i = 0; (lx_krn->krn_csr & LEO_KRN_CSR_PROGRESS) && i < 300000; i++)
		udelay (1); /* Busy wait at most 0.3 sec */
	if (i == 300000) return -EFAULT; /* Timed out - should we print some message? */
	return 0;
}

static int
leo_wid_get (fbinfo_t *fb, struct fb_wid_list *wl)
{
	struct leo_lx_krn *lx_krn = fb->info.leo.lx_krn;
	struct fb_wid_item *wi;
	int i, j;
	u32 l;
	
	lx_krn->krn_type = LEO_KRN_TYPE_WID;
	i = leo_wait (lx_krn);
	if (i) return i;
	lx_krn->krn_csr &= ~LEO_KRN_CSR_UNK2;
	lx_krn->krn_csr |= LEO_KRN_CSR_UNK;
	lx_krn->krn_type = LEO_KRN_TYPE_WID;
	i = leo_wait (lx_krn);
	if (i) return i;
	for (i = 0, wi = wl->wl_list; i < wl->wl_count; i++, wi++) {
		switch (wi->wi_type) {
		case FB_WID_DBL_8: j = (wi->wi_index & 0xf) + 0x40; break;
		case FB_WID_DBL_24: j = wi->wi_index & 0x3f; break;
		default: return -EINVAL;
		}
		wi->wi_attrs = 0xffff;
		lx_krn->krn_type = 0x5800 + j;
		l = lx_krn->krn_value;
		for (j = 0; j < 32; j++)
			wi->wi_values [j] = l;
	}
	return 0;
}

static int
leo_wid_put (fbinfo_t *fb, struct fb_wid_list *wl)
{
	struct leo_lx_krn *lx_krn = fb->info.leo.lx_krn;
	struct fb_wid_item *wi;
	int i, j;
	
	lx_krn->krn_type = LEO_KRN_TYPE_WID;
	i = leo_wait (lx_krn);
	if (i) return i;
	for (i = 0, wi = wl->wl_list; i < wl->wl_count; i++, wi++) {
		switch (wi->wi_type) {
		case FB_WID_DBL_8: j = (wi->wi_index & 0xf) + 0x40; break;
		case FB_WID_DBL_24: j = wi->wi_index & 0x3f; break;
		default: return -EINVAL;
		}
		lx_krn->krn_type = 0x5800 + j;
		lx_krn->krn_value = wi->wi_values[0];
	}
	return 0;
}

static int leo_clutstore (fbinfo_t *fb, int clutid)
{
	int i;
	u32 *clut = fb->info.leo.cluts [clutid];
	struct leo_lx_krn *lx_krn = fb->info.leo.lx_krn;
	
	lx_krn->krn_type = LEO_KRN_TYPE_CLUT0 + clutid;
	i = leo_wait (lx_krn);
	if (i) return i;
	lx_krn->krn_type = LEO_KRN_TYPE_CLUTDATA;
	for (i = 0; i < 256; i++)
		lx_krn->krn_value = *clut++; /* Throw colors there :)) */
	lx_krn->krn_type = LEO_KRN_TYPE_CLUT0 + clutid;
	lx_krn->krn_csr |= (LEO_KRN_CSR_UNK|LEO_KRN_CSR_UNK2);
	return 0;
}

static int leo_clutpost (fbinfo_t *fb, struct fb_clut *lc)
{
	int xlate = 0, i;
	u32 *clut;
	u8 *xlut = fb->info.leo.xlut;
	
	switch (lc->clutid) {
	case 0:
	case 1:
	case 2: break;
	case 3: return -EINVAL; /* gamma clut - not yet implemented */
	case 4: return -EINVAL; /* degamma clut - not yet implemented */
	default: return -EINVAL;
	}
	clut = fb->info.leo.cluts [lc->clutid] + lc->offset;
	for (i = 0; i < lc->count; i++)
		*clut++ = xlate ? 
		((xlut[(u8)(lc->red[i])])|(xlut[(u8)(lc->green[i])]<<8)|(xlut[(u8)(lc->blue[i])]<<16)) : 
		(((u8)(lc->red[i]))|(((u8)(lc->green[i]))<<8)|(((u8)(lc->blue[i]))<<16));
	return leo_clutstore (fb, lc->clutid);
}

static int leo_clutread (fbinfo_t *fb, struct fb_clut *lc)
{
	int i;
	u32 u;
	struct leo_lx_krn *lx_krn = fb->info.leo.lx_krn;

	if (lc->clutid >= 3) return -EINVAL;	
	lx_krn->krn_type = LEO_KRN_TYPE_CLUT0 + lc->clutid;
	i = leo_wait (lx_krn);
	if (i) return i;
	lx_krn->krn_csr &= ~LEO_KRN_CSR_UNK2;
	lx_krn->krn_csr |= LEO_KRN_CSR_UNK;
	i = leo_wait (lx_krn);
	if (i) return i;
	lx_krn->krn_type = LEO_KRN_TYPE_CLUTDATA;
	for (i = 0; i < lc->offset; i++)
		u = lx_krn->krn_value;
	for (i = 0; i < lc->count; i++) {
		u = lx_krn->krn_value;
		lc->red [i] = u;
		lc->green [i] = (u >> 8);
		lc->blue [i] = (u >> 16);
	}
	return 0;
}

static void
leo_loadcmap (fbinfo_t *fb, int index, int count)
{
	u32 *clut = ((u32 *)fb->info.leo.cluts [0]) + index;
	int i;
	
	for (i = index; count--; i++)
		*clut++ = ((fb->color_map CM(i,0))) |
			  ((fb->color_map CM(i,1)) << 8) |
			  ((fb->color_map CM(i,2)) << 16);
	leo_clutstore (fb, 0);
}

/* Handle leo-specific ioctls */
static int
leo_ioctl (struct inode *inode, struct file *file, unsigned cmd, unsigned long arg, fbinfo_t *fb)
{
	int i;
	
	switch (cmd) {
	case FBIO_WID_GET:
		i = verify_area (VERIFY_READ, (void *)arg, sizeof (struct fb_wid_list));
		if (i) return i;
		if (((struct fb_wid_list *)arg)->wl_count != 1 ||
		    !((struct fb_wid_list *)arg)->wl_list) return -EINVAL;
		i = verify_area (VERIFY_WRITE, (void *)(((struct fb_wid_list *)arg)->wl_list), 
			((struct fb_wid_list *)arg)->wl_count * sizeof (struct fb_wid_item));
		if (i) return i;
		return leo_wid_get (fb, (struct fb_wid_list *)arg);
	case FBIO_WID_PUT:
		i = verify_area (VERIFY_READ, (void *)arg, sizeof (struct fb_wid_list));
		if (i) return i;
		if (((struct fb_wid_list *)arg)->wl_count != 1 ||
		    !((struct fb_wid_list *)arg)->wl_list) return -EINVAL;
		i = verify_area (VERIFY_WRITE, (void *)(((struct fb_wid_list *)arg)->wl_list), 
			((struct fb_wid_list *)arg)->wl_count * sizeof (struct fb_wid_item));
		if (i) return i;
		return leo_wid_put (fb, (struct fb_wid_list *)arg);
	case LEO_CLUTPOST:
		i = verify_area (VERIFY_READ, (void *)arg, sizeof (struct fb_clut));
		if (i) return i;
		i = ((struct fb_clut *)arg)->offset + ((struct fb_clut *)arg)->count;
		if (i <= 0 || i > 256) return -EINVAL;
		i = verify_area (VERIFY_READ, ((struct fb_clut *)arg)->red, ((struct fb_clut *)arg)->count);
		if (i) return i;
		i = verify_area (VERIFY_READ, ((struct fb_clut *)arg)->green, ((struct fb_clut *)arg)->count);
		if (i) return i;
		i = verify_area (VERIFY_READ, ((struct fb_clut *)arg)->blue, ((struct fb_clut *)arg)->count);
		if (i) return i;
		return leo_clutpost (fb, (struct fb_clut *)arg);
	case LEO_CLUTREAD:
		i = verify_area (VERIFY_READ, (void *)arg, sizeof (struct fb_clut));
		if (i) return i;
		i = ((struct fb_clut *)arg)->offset + ((struct fb_clut *)arg)->count;
		if (i <= 0 || i > 256) return -EINVAL;
		i = verify_area (VERIFY_WRITE, ((struct fb_clut *)arg)->red, ((struct fb_clut *)arg)->count);
		if (i) return i;
		i = verify_area (VERIFY_WRITE, ((struct fb_clut *)arg)->green, ((struct fb_clut *)arg)->count);
		if (i) return i;
		i = verify_area (VERIFY_WRITE, ((struct fb_clut *)arg)->blue, ((struct fb_clut *)arg)->count);
		if (i) return i;
		return leo_clutread (fb, (struct fb_clut *)arg);
		
	default:
		return -ENOSYS;
	}
}

static void
leo_reset (fbinfo_t *fb)
{
	if (fb == &fbinfo[0])
		sbus_hw_hide_cursor ();
}


__initfunc(static unsigned long leo_postsetup (fbinfo_t *fb, unsigned long memory_start))
{
	fb->info.leo.cluts[0] = (u32 *)(memory_start);
	fb->info.leo.cluts[1] = (u32 *)(memory_start+256*4);
	fb->info.leo.cluts[2] = (u32 *)(memory_start+256*4*2);
	fb->info.leo.xlut = (u8 *)(memory_start+256*4*3);
	fb->color_map = (u8 *)(memory_start+256*4*3+256);
	return memory_start + (256*4*3) + 256 + 256*3;
}

__initfunc(void leo_setup (fbinfo_t *fb, int slot, u32 leo, int leo_io))
{
	struct leo_info *leoinfo;
	int i;
	struct fb_wid_item wi;
	struct fb_wid_list wl;
	
	printk ("leo%d at 0x%8.8x ", slot, leo);
	
	/* Fill in parameters we left out */
	fb->type.fb_size = 0x800000; /* 8MB */
	fb->type.fb_cmsize = 256;
	fb->mmap = leo_mmap;
	fb->loadcmap = leo_loadcmap;
	fb->postsetup = leo_postsetup;
	fb->ioctl = (void *)leo_ioctl;
	fb->reset = leo_reset;
	fb->blank = leo_blank;
	fb->unblank = leo_unblank;
	fb->setcursor = leo_setcursor;
	fb->setcursormap = leo_setcursormap;
	fb->setcurshape = leo_setcurshape;
	fb->blitc = leo_blitc;
	fb->setw = leo_setw;
	fb->cpyw = leo_cpyw;
	fb->fill = leo_fill;
	fb->draw_penguin = leo_penguin;
	fb->base_depth = 0;
	
	leoinfo = (struct leo_info *) &fb->info.leo;
	
	memset (leoinfo, 0, sizeof(struct leo_info));

	leoinfo->offset = leo;
	/* Map the hardware registers */
	leoinfo->lc_ss0_krn = sparc_alloc_io(leo + LEO_OFF_LC_SS0_KRN, 0,
		 PAGE_SIZE,"leo_lc_ss0_krn", fb->space, 0);
	leoinfo->lc_ss0_usr = sparc_alloc_io(leo + LEO_OFF_LC_SS0_USR, 0,
		 PAGE_SIZE,"leo_lc_ss0_usr", fb->space, 0);
	leoinfo->lc_ss1_krn = sparc_alloc_io(leo + LEO_OFF_LC_SS1_KRN, 0,
		 PAGE_SIZE,"leo_lc_ss1_krn", fb->space, 0);
	leoinfo->lc_ss1_usr = sparc_alloc_io(leo + LEO_OFF_LC_SS1_USR, 0,
		 PAGE_SIZE,"leo_lc_ss1_usr", fb->space, 0);
	leoinfo->ld_ss0 = sparc_alloc_io(leo + LEO_OFF_LD_SS0, 0,
		 PAGE_SIZE,"leo_ld_ss0", fb->space, 0);
	leoinfo->ld_ss1 = sparc_alloc_io(leo + LEO_OFF_LD_SS1, 0,
		 PAGE_SIZE,"leo_ld_ss1", fb->space, 0);
	leoinfo->ld_gbl = sparc_alloc_io(leo + LEO_OFF_LD_GBL, 0,
		 PAGE_SIZE,"leo_ld_gbl", fb->space, 0);
	leoinfo->lx_krn = sparc_alloc_io(leo + LEO_OFF_LX_KRN, 0,
		 PAGE_SIZE,"leo_lx_krn", fb->space, 0);
	leoinfo->cursor = sparc_alloc_io(leo + LEO_OFF_LX_CURSOR, 0,
		 sizeof(struct leo_cursor),"leo_lx_crsr", fb->space, 0);
	fb->base = (long)sparc_alloc_io(leo + LEO_OFF_SS0, 0,
		 0x800000,"leo_ss0", fb->space, 0);
	
	leoinfo->ld_ss0->unk = 0xffff;
	leoinfo->ld_ss0->unk2 = 0;
	leoinfo->ld_ss0->unk3 = (fb->type.fb_width - 1)	| ((fb->type.fb_height - 1) << 16);
	wl.wl_count = 1;
	wl.wl_list = &wi;
	wi.wi_type = FB_WID_DBL_8;
	wi.wi_index = 0;
	wi.wi_values [0] = 0x2c0;
	leo_wid_put (fb, &wl);
	wi.wi_index = 1;
	wi.wi_values [0] = 0x30;
	leo_wid_put (fb, &wl);
	wi.wi_index = 2;
	wi.wi_values [0] = 0x20;
	leo_wid_put (fb, &wl);
	
	leoinfo->ld_ss1->ss1_misc |= LEO_SS1_MISC_ENABLE;
	
	leoinfo->ld_ss0->fg = 0x30703;
	leoinfo->ld_ss0->planemask = 0xff000000;
	leoinfo->ld_ss0->rop = 0xd0840;
	leoinfo->lc_ss0_usr->extent = (fb->type.fb_width-1) | ((fb->type.fb_height-1) << 11);
	i = leoinfo->lc_ss0_usr->attrs;
	leoinfo->lc_ss0_usr->fill = (0) | ((0) << 11) | ((i & 3) << 29) | ((i & 8) ? 0x80000000 : 0);
	do {
		i = leoinfo->lc_ss0_usr->csr;
	} while (i & 0x20000000);
	
	if (slot == sun_prom_console_id)
		fb_restore_palette = leo_restore_palette;
	
	printk("Cmd Rev %d\n",
		(leoinfo->lc_ss0_krn->rev >> 28));
	
	/* Reset the leo */
	leo_reset(fb);
	
	if (!slot)	
	/* Enable Video */
		leo_unblank (fb);
	else if (slot != sun_prom_console_id)
		leo_blank (fb);
}

extern unsigned char vga_font [];

#define GX_BLITC_START(attr,x,y,count) \
	{ \
		register struct leo_lc_ss0_usr *us = fbinfo[0].info.leo.lc_ss0_usr; \
		register struct leo_ld_ss0 *ss = fbinfo[0].info.leo.ld_ss0; \
		register u32 i; \
		do { \
			i = us->csr; \
		} while (i & 0x20000000); \
		ss->fg = (attr & 0xf) << 24; \
		ss->bg = (attr >> 4) << 24; \
		ss->rop = 0x310040; \
		ss->planemask = 0xff000000; \
		us->fontc2 = 0xFFFFFFFE; \
		us->attrs = 4; \
		us->fontc = 0xFF000000;
#define GX_BLITC_END \
	}

static void leo_blitc(unsigned short charattr, int xoff, int yoff)
{
	unsigned char attrib = CHARATTR_TO_SUNCOLOR(charattr);
	unsigned char *p = &vga_font[((unsigned char)charattr) << 4];
	u32 *u = ((u32 *)fbinfo[0].base) + (yoff << 11) + xoff;
	GX_BLITC_START(attrib, xoff, yoff, 1)
	for (i = 0; i < CHAR_HEIGHT; i++, u += 2048)
		*u = (*p++) << 24;
	GX_BLITC_END
}

static void leo_setw(int xoff, int yoff, unsigned short c, int count)
{
	unsigned char attrib = CHARATTR_TO_SUNCOLOR(c);
	unsigned char *p = &vga_font[((unsigned char)c) << 4];
	register unsigned char *q;
	u32 *u = ((u32 *)fbinfo[0].base) + (yoff << 11) + xoff;
	GX_BLITC_START(attrib, xoff, yoff, count)
	while (count-- > 0) {
		q = p;
		for (i = 0; i < CHAR_HEIGHT; i++, u += 2048)
			*u = (*q++) << 24;
		u += 8 - (CHAR_HEIGHT * 2048);
	}
	GX_BLITC_END
}

static void leo_cpyw(int xoff, int yoff, unsigned short *p, int count)
{
	unsigned char attrib = CHARATTR_TO_SUNCOLOR(*p);
	register unsigned char *q;
	u32 *u = ((u32 *)fbinfo[0].base) + (yoff << 11) + xoff;
	GX_BLITC_START(attrib, xoff, yoff, count)
	while (count-- > 0) {
		q = &vga_font[((unsigned char)*p++) << 4];
		for (i = 0; i < CHAR_HEIGHT; i++, u += 2048)
			*u = (*q++) << 24;
		u += 8 - (CHAR_HEIGHT * 2048);
	}
	GX_BLITC_END
}

static void leo_fill(int attrib, int count, int *boxes)
{
	register struct leo_lc_ss0_usr *us = fbinfo[0].info.leo.lc_ss0_usr;
	register struct leo_ld_ss0 *ss = fbinfo[0].info.leo.ld_ss0;
	register u32 i;
	do {
		i = us->csr;
	} while (i & 0x20000000);
	ss->unk = 0xffff;
	ss->unk2 = 0;
	ss->unk3 = (fbinfo[0].type.fb_width - 1) | ((fbinfo[0].type.fb_height - 1) << 16);
	ss->fg = ((attrib & 0xf)<<24) | 0x030703;
	ss->planemask = 0xff000000;
	ss->rop = 0xd0840;
	while (count-- > 0) {
		us->extent = ((boxes[2] - boxes[0] - 1) & 0x7ff) | (((boxes[3] - boxes[1] - 1) & 0x7ff) << 11);
		i = us->attrs;
		us->fill = (boxes[0] & 0x7ff) | ((boxes[1] & 0x7ff) << 11) | ((i & 3) << 29) | ((i & 8) ? 0x80000000 : 0);
	}
}

__initfunc(void leo_penguin(int x_margin, int y_margin, int ncpus))
{
	suncons_ops.clear_screen();
	/* FIXME: Write this */
}