Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / devices / dummy_mods / iob / iob.cc
CommitLineData
920dae64
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: iob.cc
4// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6//
7// The above named program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public
9// License version 2 as published by the Free Software Foundation.
10//
11// The above named program is distributed in the hope that it will be
12// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public
17// License along with this work; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19//
20// ========== Copyright Header End ============================================
21/* iob.C
22 * handle IOB (I/O space) T1 addresses for blaze/SAM
23 *
24 * Copyright (c) 2004 by Sun Microsystems, Inc.
25 * All rights reserved.
26 *
27 */
28
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include <errno.h>
34#include <sys/syscall.h> // get exec number
35#include <sys/types.h> // uid_t
36#include <unistd.h> // getuid()
37#include <inttypes.h>
38#include <stdarg.h>
39
40#include <thread.h>
41
42#include "mmi.h"
43#include "ui.h"
44
45struct sam_iob_s {
46 uint64_t startpa;
47 uint64_t endpa;
48 uint64_t sz;
49}; // struct sam_iob.C
50
51
52extern "C" int iob_access(uint32_t cpuid, void* obj, uint64_t paddr, mmi_bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask);
53
54int iob_ld_operation (void *cd, uint64_t paddr, uint64_t *buf, int sz, uint32_t cpuid);
55int iob_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int sz, uint32_t cpuid);
56
57extern "C" void iob_create_instance (const char *modname, const char *instance_name);
58
59
60extern "C" void _init()
61{
62 if (! mmi_register_instance_creator("iob", iob_create_instance) ) {
63 fprintf(stderr, "Cannot register instance creator for iob\n");
64 }
65} // _init()
66
67
68
69void iob_create_instance (const char *modname, const char *instance_name)
70{
71 sam_iob_s * iob_obj = new sam_iob_s;
72
73 mmi_instance_t instance = mmi_register_instance(modname, instance_name, (void *) &iob_obj, "iob dummy device");
74
75 iob_obj->startpa = 0x0;
76 iob_obj->endpa = 0x0;
77 iob_obj->sz = 0;
78
79 // expected syntax: sysconf iob iob1 startpa=<0xblah> endpa=<0xblah>
80 int argc = mmi_argc(instance);
81 int i;
82
83 for (i=0; i<argc; i++) {
84 char * arg = strdup(mmi_argv(instance, i));
85 char * marker;
86 char * lv = strtok_r(arg, "=", &marker);
87 if (strcmp(lv, "startpa") == 0) {
88 errno = 0;
89 char * rv = strtok_r(NULL, "=", &marker);
90 iob_obj->startpa = strtoull(rv, NULL, 0);
91 if (errno) {
92 perror("iob: error parsing startpa");
93 exit(1);
94 }
95 } else if (strcmp(lv, "endpa") == 0) {
96 errno = 0;
97 char * rv = strtok_r(NULL, "=", &marker);
98 iob_obj->endpa = strtoull(rv, NULL, 0);
99 if (errno) {
100 perror("iob: error parsing startpa");
101 exit(1);
102 }
103 } // else - do nothing
104 }
105
106 iob_obj->sz = iob_obj->endpa - iob_obj->startpa + 1;
107 if (mmi_map_physio(iob_obj->startpa, iob_obj->sz, (void *) iob_obj, iob_access)) {
108 fprintf(stderr, " sam iob: unable to register IO interceptor\n");
109 return;
110 }
111}
112
113
114int iob_access(uint32_t cpuid, void* obj, uint64_t paddr, mmi_bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask)
115{
116 if (wr) {
117 return iob_st_operation(obj, paddr, buf, size, cpuid);
118 } else {
119 return iob_ld_operation(obj, paddr, buf, size, cpuid);
120 }
121} // iob_access()
122
123int iob_ld_operation (void *obj, uint64_t paddr, uint64_t *buf, int size, uint32_t cpuid)
124{
125 sam_iob_s * iob_obj = (sam_iob_s *) obj;
126 uint64_t offset = paddr - iob_obj->startpa;
127 // fprintf(stderr, "SAM iob: ld_operation pa 0x%llx size %d cpu %d\n", paddr, size, cpuid);
128 switch (offset) {
129 case 0x0:
130 *buf = 0;
131 break;
132 default:
133 *buf = 0;
134 break;
135 // fprintf(stderr, "SAM iob: ld from invalid paddr 0x%llx\n", paddr);
136 // exit(1);
137 }
138 return 0;
139} // int iob_ld_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t cpuid)
140
141
142int iob_st_operation (void *obj, uint64_t paddr, uint64_t *buf, int size, uint32_t cpuid)
143{
144 // fprintf(stderr, "SAM iob: st_operation pa 0x%llx size %d cpu %d\n", paddr, size, cpuid);
145 sam_iob_s * iob_obj = (sam_iob_s *) obj;
146 uint64_t offset = paddr - iob_obj->startpa;
147 switch (offset) {
148 case 0x800: // case 0x9800000800:
149 // do nothing
150 break;
151 case 0xa00:
152 break;
153 default:
154 fprintf(stderr, "SAM iob: st to invalid paddr 0x%llx\n", paddr);
155 exit(1);
156 }
157 return 0;
158} // int iob_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t cpuid)
159
160
161/////////////////////////////////////////////////
162
163extern "C" void _fini ()
164{
165}
166
167/////////////////////////////////////////////////