1 /*
2  *  Copyright (C) 2003-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: Color plane mask, used in the DECstation 3100 machine
29  *
30  *  Just a one-byte thingy, but the way things work now this has to
31  *  be a separate device. :-/
32  */
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 
38 #include "devices.h"
39 #include "memory.h"
40 #include "misc.h"
41 
42 
43 struct colorplanemask_data {
44 	unsigned char	*color_plane_mask;
45 };
46 
47 
DEVICE_ACCESS(colorplanemask)48 DEVICE_ACCESS(colorplanemask)
49 {
50 	struct colorplanemask_data *d = (struct colorplanemask_data *) extra;
51 
52 	switch (relative_addr) {
53 
54 	case 0x00:
55 		if (writeflag == MEM_WRITE) {
56 			*d->color_plane_mask = data[0];
57 		} else {
58 			debug("[ colorplanemask: read isn't actually "
59 			    "supported ]\n");
60 			data[0] = *d->color_plane_mask;
61 		}
62 		break;
63 
64 	default:
65 		if (writeflag == MEM_WRITE) {
66 			debug("[ colorplanemask: unimplemented write "
67 			    "to address 0x%x, data=0x%02x ]\n",
68 			    (int)relative_addr, data[0]);
69 		} else {
70 			debug("[ colorplanemask: unimplemented read "
71 			    "from address 0x%x ]\n", (int)relative_addr);
72 		}
73 	}
74 
75 	/*  Pretend it was ok:  */
76 	return 1;
77 }
78 
79 
80 /*
81  *  dev_colorplanemask_init():
82  */
dev_colorplanemask_init(struct memory * mem,uint64_t baseaddr,unsigned char * color_plane_mask)83 void dev_colorplanemask_init(struct memory *mem, uint64_t baseaddr,
84 	unsigned char *color_plane_mask)
85 {
86 	struct colorplanemask_data *d;
87 
88 	CHECK_ALLOCATION(d = (struct colorplanemask_data *)
89 	    malloc(sizeof(struct colorplanemask_data)));
90 	memset(d, 0, sizeof(struct colorplanemask_data));
91 
92 	d->color_plane_mask = color_plane_mask;
93 
94 	memory_device_register(mem, "colorplanemask", baseaddr,
95 	    DEV_COLORPLANEMASK_LENGTH, dev_colorplanemask_access,
96 	    (void *)d, DM_DEFAULT, NULL);
97 }
98 
99