Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: mcu.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 | /* mcu.C | |
22 | * handle mcu (Memory Control Unit) N1 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 | ||
44 | struct sam_mcu_s { | |
45 | uint64_t startpa; | |
46 | uint64_t endpa; | |
47 | }; // struct sam_mcu_s | |
48 | ||
49 | int verbose = 0; | |
50 | ||
51 | static int mcu_ld_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid); | |
52 | static int mcu_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid); | |
53 | ||
54 | extern "C" static void mcu_create_instance (const char *modname, const char *instance_name); | |
55 | ||
56 | extern "C" int mcu_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 | ||
60 | extern "C" void _init() | |
61 | { | |
62 | if (! mmi_register_instance_creator("mcu", mcu_create_instance) ) { | |
63 | fprintf(stderr, "ERROR: SAM MCU: Cannot register mcu instance creator\n"); | |
64 | } | |
65 | ||
66 | } // _init() | |
67 | ||
68 | ||
69 | ||
70 | void mcu_create_instance (const char *modname, const char *instance_name) | |
71 | { | |
72 | struct sam_mcu_s * mcu_obj = new sam_mcu_s; | |
73 | ||
74 | mmi_instance_t instance = mmi_register_instance(modname, instance_name, mcu_obj, "SAM MCU model"); | |
75 | ||
76 | mcu_obj->startpa = 0x0; | |
77 | mcu_obj->endpa = 0x0; | |
78 | ||
79 | // expected syntax: sysconf mcu mcu1 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 | mcu_obj->startpa = strtoull(rv, NULL, 0); | |
91 | if (errno) { | |
92 | perror("mcu: 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 | mcu_obj->endpa = strtoull(rv, NULL, 0); | |
99 | if (errno) { | |
100 | perror("mcu: error parsing startpa"); | |
101 | exit(1); | |
102 | } | |
103 | } // else - do nothing | |
104 | } | |
105 | ||
106 | uint64_t sz = (mcu_obj->endpa - mcu_obj->startpa + 1); | |
107 | if (mmi_map_physio(mcu_obj->startpa, sz, (void *) mcu_obj, mcu_access)) { | |
108 | fprintf(stderr, " sam mcu: unable to register IO interceptor\n"); | |
109 | return; | |
110 | } | |
111 | ||
112 | } | |
113 | ||
114 | ||
115 | ||
116 | int mcu_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 mcu_st_operation(obj, paddr, buf, size, cpuid); | |
120 | } else { | |
121 | return mcu_ld_operation(obj, paddr, buf, size, cpuid); | |
122 | } | |
123 | } // mcu_access() | |
124 | ||
125 | int mcu_ld_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid) | |
126 | { | |
127 | if (verbose) fprintf(stderr, "mcu: 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, "mcu: ld from unknown paddr 0x%llx\n", paddr); | |
134 | *buf = 0; | |
135 | } | |
136 | return 0; | |
137 | } // | |
138 | ||
139 | ||
140 | int mcu_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid) | |
141 | { | |
142 | if (verbose) fprintf(stderr, "mcu: 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, "mcu: st to unknown paddr 0x%llx\n", paddr); | |
147 | } | |
148 | return 0; | |
149 | } // int mcu_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid) | |
150 | ||
151 | ||
152 | ||
153 | ///////////////////////////////////////////////// | |
154 | ||
155 | extern "C" void _fini () | |
156 | { | |
157 | } | |
158 | ||
159 | ///////////////////////////////////////////////// |