1 /*
2  *  Copyright (C) 2004-2009  Anders Gavare.  All rights reserved.
3  *
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions are met:
6  *
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. The name of the author may not be used to endorse or promote products
13  *     derived from this software without specific prior written permission.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  *  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  *  SUCH DAMAGE.
26  *
27  *
28  *  COMMENT: SFB TURBOchannel framebuffer (graphics card)
29  *
30  *  See include/sfbreg.h (and NetBSD's arch/pmax/dev/sfb.c) for more info.
31  *
32  *
33  *  TODO:  This is not really implemented yet. It "happens" to work with
34  *         NetBSD and OpenBSD, but not with Ultrix yet.
35  */
36 
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 
41 #include "devices.h"
42 #include "memory.h"
43 #include "misc.h"
44 
45 #include "thirdparty/sfbreg.h"
46 
47 
48 #define	SFB_XSIZE	1280
49 #define	SFB_YSIZE	1024
50 
51 
52 /*  #define debug fatal  */
53 
54 
55 #define	SFB_REG_SIZE	0x80
56 #define	N_SFB_REGS	(SFB_REG_SIZE / 4)
57 
58 
59 struct sfb_data {
60 	struct vfb_data	*vfb_data;
61 
62 	uint32_t	reg[N_SFB_REGS];
63 };
64 
65 
DEVICE_ACCESS(sfb)66 DEVICE_ACCESS(sfb)
67 {
68 	uint64_t idata = 0, odata = 0;
69 	struct sfb_data *d = (struct sfb_data *) extra;
70 
71 	if (writeflag == MEM_WRITE)
72 		idata = memory_readmax64(cpu, data, len);
73 
74 	if (writeflag==MEM_READ) {
75 		odata = d->reg[(relative_addr >> 2) & (N_SFB_REGS - 1)];
76 		debug("[ sfb: read from addr 0x%x: 0x%llx ]\n",
77 		    (int)relative_addr, (long long)odata);
78 	} else {
79 		d->reg[(relative_addr >> 2) & (N_SFB_REGS - 1)] = idata;
80 		debug("[ sfb: write to addr 0x%x: 0x%llx ]\n",
81 		    (int)relative_addr, (long long)idata);
82 	}
83 
84 	if (writeflag == MEM_READ)
85 		memory_writemax64(cpu, data, len, odata);
86 
87 	return 1;
88 }
89 
90 
91 /*
92  *  dev_sfb_init():
93  */
dev_sfb_init(struct machine * machine,struct memory * mem,uint64_t baseaddr,struct vfb_data * fb)94 void dev_sfb_init(struct machine *machine, struct memory *mem,
95 	uint64_t baseaddr, struct vfb_data *fb)
96 {
97 	struct sfb_data *d;
98 
99 	CHECK_ALLOCATION(d = (struct sfb_data *) malloc(sizeof(struct sfb_data)));
100 	memset(d, 0, sizeof(struct sfb_data));
101 
102 	d->vfb_data = fb;
103 
104 	d->reg[(SFB_VHORIZONTAL - SFB_ASIC_OFFSET) / 4] = SFB_XSIZE >> 2;
105 	d->reg[(SFB_VVERTICAL - SFB_ASIC_OFFSET) / 4]   = SFB_YSIZE;
106 
107 	memory_device_register(mem, "sfb", baseaddr, SFB_REG_SIZE,
108 	    dev_sfb_access, d, DM_DEFAULT, NULL);
109 }
110 
111