Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / legion / src / devices / mmi / mmi.h
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: mmi.h
5* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
7*
8* The above named program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public
10* License version 2 as published by the Free Software Foundation.
11*
12* The above named program is distributed in the hope that it will be
13* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15* General Public License for more details.
16*
17* You should have received a copy of the GNU General Public
18* License along with this work; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20*
21* ========== Copyright Header End ============================================
22*/
23/*
24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28#ifndef _MMI_H
29#define _MMI_H
30
31#pragma ident "@(#)mmi.h 1.4 06/07/22 SMI"
32
33/*
34 * This header file is from the SAM team. It defines the
35 * MMI device model APIs, allowing the sharing of IO models
36 * between SAM and Legion. Any future additions or revisions
37 * to the MMI APIs will be shared between the two simulators,
38 * so no direct change should be made to this copy.
39 */
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45#include <sys/types.h>
46
47/* opaque type definitions for MMI device models */
48typedef void * mmi_instance_t;
49typedef void * mmi_module_t;
50
51typedef enum {mmi_false=0, mmi_true=1} mmi_bool_t;
52
53/* device operation in SAM
54 *
55 * 1. The simulator reads in the simulation configuration file containing "sysconf" lines at startup
56 * 2. Each sysconf line specifies a module-type name, an instance name and a set of properties in the form name=value
57 * For example:
58 * sysconf mydev dev0 baseaddr=0xffc00040 parent=bus0 debug=true logfile=mydev.0.log
59 * 3. The sysconf parser loads the mydev.so object (unless it is already loaded)
60 * 4. The sysconf parser calls the instance creator function in mydev.so to create the "dev0" instance
61 * 5. The dev0 instance creator retrieves its sysconf arguments using mmi_argc and mmi_argv calls and processes them
62 * 6. The dev0 instance creator maps its device registers into the SAM address space using mmi_map_physio
63 */
64
65/* An MMI device model is a shared object loaded using dlopen().
66 * In SAM, this mechanism requires an _init function in the shared object:
67 *
68 * extern "C" void _init()
69 *
70 * This function must be defined. For example:
71 *
72 * extern "C" void _init() {
73 * // mmi initialization code goes here
74 * }
75
76 * There are alternative means of automatically invoking an initialization function in a shared object
77 * For example, the constructor of a static object in the shared object written using C++
78 *
79 * In any event, SAM does not explicitly call a function in the shared object after dlopen().
80 * The _init() function is implicitly invoked by dlopen().
81 */
82
83/* Functions returning mmi_bool_t return an SUCCESS status (true=no error).
84 * An error typically indicates invalid arguments are being passed
85 */
86
87/* Devices are instantiated by SAM when specified in the config file.
88 * For each device instance, the device model needs to provide an INSTANCE CREATOR function
89 * which performs the instantiation.
90 *
91 * The instance creator function is invoked from SAM
92 * with the modname (device class name) and the instance-name
93 */
94
95typedef void (*mmi_instance_creator) (const char *modname, const char *instance_name);
96
97mmi_bool_t mmi_register_instance_creator(const char * modname, mmi_instance_creator creatorfn);
98
99/* the instance_creator function can retrieve its own handle (mmi_instance_t) by calling the mmi_register_instance
100 * function. In addition, the device-model can register it's implementation-specific instance data. This can be
101 * retrieved (eg in the modinfo, config and interface callbacks) using the mmi_get_instance_data call.
102 * The help string is displayed in response to UI commands for listing all device nodes.
103 *
104 * Putting the mmi_instance_t handle in the instance_data structure can be convenient
105 */
106
107mmi_instance_t mmi_register_instance(const char * modname, const char * instancename, void * instance_data, const char * short_help);
108
109void * mmi_get_instance_data(mmi_instance_t instance);
110
111typedef int (*mmi_instance_cmd_fn) (void * instancedata, int argc, char **argv);
112void mmi_register_instance_cmd(mmi_instance_t instance, const char *helpstr, mmi_instance_cmd_fn fn);
113
114/* Register a function that can respond to the modinfo UI command by printing out relevant module instance information */
115typedef void (*mmi_modinfo_cb) (mmi_instance_t cb_instance);
116
117mmi_bool_t mmi_register_modinfo_cb(mmi_instance_t this_instance, mmi_modinfo_cb modinfo_fn);
118
119
120
121/* These calls use the mmi_instance_t handle provided by the mmi_register_instance function above.
122 * They return the arguments specified on the sysconf line for this device instance
123 */
124int mmi_argc(mmi_instance_t this_instance);
125char * mmi_argv(mmi_instance_t this_instance, int index);
126
127
128
129/* A function of type mmi_access needs to be provided by the device model to handle accesses (load/store) to
130 * device registers in response to instructions executed by the simulated CPU.
131 *
132 * The mmi_map_physio function is used to register this function with the simulator. The device-model provides a pointer
133 * to user data which is returned in the call to the access function. This function should return an error indication (0 for success, some non-zero value for failure
134 */
135typedef int (*mmi_access) (uint32_t cpuid, void* obj, uint64_t paddr, mmi_bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask);
136
137/* These calls lets the instance map/unmap its registers onto the physical address space of the simulated CPUs */
138int mmi_map_physio (uint64_t base, uint64_t size, void* obj, mmi_access access_fn);
139void mmi_unmap_physio(uint64_t base, uint64_t size, void* obj);
140
141
142
143/* Memory access functions for devices: devices can do block read/write into simulated memory using mmi_memread and mmi_memwrite calls */
144void mmi_memread(uint64_t paddr, uint8_t * data, uint64_t size);
145void mmi_memwrite(uint64_t paddr, uint8_t * data, uint64_t size);
146
147
148/* interrupts: interrupts are not directly delivered to CPUs by devices. Instead,
149 * they are passed on up the device hierarchy through a bus and/or a bridge. The bridge model
150 * implements interrupt delivery to the appropriate CPU. We do not address this in MMI
151 */
152
153
154
155/* start/stop functions
156 * device operation can be synchronous (in response to a sparc-cpu action and within a cpu simulation thread)
157 * or asynchronous (within a separate thread). A network controller thread listening on a socket for simulated
158 * network connections is an example of an asynchronous device model.
159 *
160 * When a run or stop command is issued at the UI prompt, an asynchronous thread needs to start/stop in response
161 * (eg start=>create thread; stop=>kill thread).
162 * The start/stop functions provide a way for SAM to communicate these changes in run state to asynchronous devices
163 *
164 * These functions are not needed for synchronous devices (devices that do not create their own simulation threads)
165 */
166typedef void (*mmi_start_stop_cb) (void * userdata);
167void mmi_register_start_stop(mmi_start_stop_cb start_action, mmi_start_stop_cb stop_action, void * userdata);
168
169
170/* checkpointing functions
171 * SAM has a checkpointing feature (dump/restore) which allows a user to dump current simulator state
172 * or to restore (at init-time) from a previous checkpoint.
173 * A module needs to register dump and restore functions with SAM to respond to dump/restore UI actions.
174 * SAM calls the dump and restore functions with the directory in which the device instance should create/find
175 * its state dump. The name of the dump file is <instancename>.dmp
176 * These functions should return a success indication (true=success, false=failure)
177 */
178typedef mmi_bool_t (*mmi_dump_cb)(void * userdata, const char * dirname);
179typedef mmi_bool_t (*mmi_restore_cb)(void * userdata, const char * dirname);
180
181mmi_bool_t mmi_register_dump_restore(void * userdata, mmi_dump_cb dump_fn, mmi_restore_cb restore_fn);
182
183
184
185/* time-related functions
186 * A device may want to model a delay or a periodic process (eg device latency or device internal clock)
187 *
188 * SAM and the MMI interface support a delayed event callback mechanism. The chosen unit of time is
189 * microseconds of simulated time.
190 *
191 * The device model
192 * defines a callback function (void function with two void * parameters)
193 * gets the current time using the mmi_get_time() function.
194 * adds the desired delay to the current time
195 * registers a delayed callback using the mmi_register_event function
196 *
197 * For periodic processes, the event callback function should register itself at time=current+period
198 */
199typedef void (*mmi_event_cb) (void * userdata1, void * userdata2);
200int64_t mmi_get_time(); /* current simulated time in microseconds since reboot */
201mmi_bool_t mmi_register_event(int64_t when, mmi_event_cb event_fn, void * userdata1, void * userdata2);
202
203
204/* Interacting with other devices */
205
206/*
207 * When a device is instantiated/deleted in response to a sysconf directive,
208 * a device module can receive about this config change by registering a config callback
209 * function.
210 *
211 * A config event can be of the type: instance-added, instance-deleted and config-init-done
212 * config-init-done refers to simulated system being initialized and ready to execute instructions.
213 * instance_deleted is deprecated and obsolete. Simulator should not delete a device instance.
214
215 * registering a config callback results in the callback function
216 * being called for config events that have occurred in the past as
217 * well as those that occur subsequently.
218 */
219
220typedef enum {MMI_CONFIG_NEW_MODULE, MMI_CONFIG_DELETE_MODULE, MMI_CONFIG_INIT_DONE} mmi_config_t;
221typedef void (*mmi_config_cb) (void *callback_data, mmi_instance_t target, const char * target_name, mmi_config_t);
222mmi_bool_t mmi_register_config_cb(mmi_instance_t this_instance, mmi_config_cb config_fn);
223
224/* get a device-instance handle by name */
225mmi_instance_t mmi_get_instance(const char * instancename);
226
227/*
228 * register a call-back function with the simulator to respond to mmi_get_interface
229 * calls from other modules
230 */
231typedef void* (*mmi_interface_cb) (void *callback_data, const char *name);
232mmi_bool_t mmi_register_interface_cb(mmi_instance_t this_instance, mmi_interface_cb);
233
234/*
235 * get a named interface from another device instance (eg pcie_device from pcie_bus).
236 * the return value should be typecast to the mutually-agreed-upon interface type
237 */
238void * mmi_get_interface(mmi_instance_t instance, const char * interface_name);
239
240
241
242
243
244
245
246
247/* old mmi functions (for backwards compatibility - eg the SN sync-device model) */
248mmi_bool_t mmi_unregister_instance_creator(mmi_instance_t instance);
249
250/* these have been deprecated in favor of mmi_map_physio (see above) */
251
252
253typedef int (*mmi_io_action) (void *cb_data, uint64_t paddr, uint64_t *buf, int size, uint8_t bytemask, void *cpuptr);
254int mmi_register_io_action (mmi_module_t *module, mmi_io_action ld_handler, mmi_io_action st_handler);
255
256/* interrupt functions - these are described in the MMI documentation */
257int mmi_interrupt_packet (int dest_cpuid, void *src, int src_iscpu, uint64_t *idata);
258int mmi_interrupt_vector (int dest_cpuid, void *src, int src_iscpu, uint32_t vnum, int traptype);
259
260typedef void (*mmi_event_cycle)(void * instance_data, uint64_t repeat);
261void* mmi_register_cb_cycle (mmi_instance_t instance, mmi_event_cycle handler, uint64_t repeat);
262void mmi_unregister_cb_cycle(mmi_instance_t instance, void * intf);
263int mmi_disable_cb_cycle (void * intf);
264int mmi_enable_cb_cycle (void * intf, uint64_t repeat);
265
266
267uint64_t mmi_get_cpufreq();
268
269mmi_bool_t mmi_register_asi_cb_data (mmi_instance_t instance, void *cb_data);
270
271typedef int (*mmi_ld_asi_action) (void *cbd, uint32_t asi, uint64_t vaddr, uint64_t *buf, int size, uint32_t cpuid);
272typedef int (*mmi_st_asi_action) (void *cbd, uint32_t asi, uint64_t vaddr, uint64_t buf, int size,uint32_t cpuid);
273void mmi_register_asi_action (mmi_instance_t instance, uint32_t asi, mmi_ld_asi_action ld_handler, mmi_st_asi_action st_handler);
274
275#ifdef __cplusplus
276}
277#endif
278
279#endif /* _MMI_H */