Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / devices / dummy_mods / ncu / ncu.cc
CommitLineData
920dae64
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: ncu.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/* ncu.C
22 * handle ncu (Memory Control Unit) T1 addresses for blaze/SAM
23 *
24 * Copyright (c) 2004 by Sun Microsystems, Inc.
25 * All rights reserved.
26 *
27 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <errno.h>
33#include <sys/syscall.h> // get exec number
34#include <sys/types.h> // uid_t
35#include <unistd.h> // getuid()
36#include <inttypes.h>
37#include <stdarg.h>
38
39#include <thread.h>
40
41#include "mmi.h"
42#include "ui.h"
43
44struct sam_ncu_s {
45 uint64_t startpa;
46 uint64_t endpa;
47}; // struct sam_ncu_s
48
49int verbose = 0;
50
51static int ncu_ld_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid);
52static int ncu_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid);
53
54extern "C" static void ncu_create_instance (const char *modname, const char *instance_name);
55
56extern "C" int ncu_access(uint32_t cpuid, void* obj, uint64_t paddr, mmi_bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask);
57
58
59
60extern "C" void _init()
61{
62 if (! mmi_register_instance_creator("ncu", ncu_create_instance) ) {
63 fprintf(stderr, "ERROR: SAM NCU: Cannot register ncu instance creator\n");
64 }
65
66} // _init()
67
68
69
70void ncu_create_instance (const char *modname, const char *instance_name)
71{
72 struct sam_ncu_s * ncu_obj = new sam_ncu_s;
73
74 mmi_instance_t instance = mmi_register_instance(modname, instance_name, ncu_obj, "SAM NCU model");
75
76 ncu_obj->startpa = 0x0;
77 ncu_obj->endpa = 0x0;
78
79 // expected syntax: sysconf ncu ncu1 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 ncu_obj->startpa = strtoull(rv, NULL, 0);
91 if (errno) {
92 perror("ncu: 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 ncu_obj->endpa = strtoull(rv, NULL, 0);
99 if (errno) {
100 perror("ncu: error parsing startpa");
101 exit(1);
102 }
103 } // else - do nothing
104 }
105
106 uint64_t sz = (ncu_obj->endpa - ncu_obj->startpa + 1);
107 if (mmi_map_physio(ncu_obj->startpa, sz, (void *) ncu_obj, ncu_access)) {
108 fprintf(stderr, " sam ncu: unable to register IO interceptor\n");
109 return;
110 }
111
112}
113
114
115
116int ncu_access(uint32_t cpuid, void* obj, uint64_t paddr, mmi_bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask)
117{
118 if (wr) {
119 return ncu_st_operation(obj, paddr, buf, size, cpuid);
120 } else {
121 return ncu_ld_operation(obj, paddr, buf, size, cpuid);
122 }
123} // ncu_access()
124
125int ncu_ld_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid)
126{
127 if (verbose) fprintf(stderr, "ncu: ld_operation pa 0x%llx size %d cpu %d\n", paddr, size, v9cpuid);
128 switch (paddr) {
129 case 0x0:
130 *buf = 0;
131 break;
132 default:
133 if (verbose) fprintf(stderr, "ncu: ld from unknown paddr 0x%llx\n", paddr);
134 *buf = 0;
135 }
136 return 0;
137} //
138
139
140int ncu_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid)
141{
142 if (verbose) fprintf(stderr, "ncu: st_operation pa 0x%llx size %d cpu %d\n", paddr, size, v9cpuid);
143 switch (paddr) {
144 break;
145 default:
146 if (verbose) fprintf(stderr, "ncu: st to unknown paddr 0x%llx\n", paddr);
147 }
148 return 0;
149} // int ncu_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid)
150
151
152
153/////////////////////////////////////////////////
154
155extern "C" void _fini ()
156{
157}
158
159/////////////////////////////////////////////////