Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: mmiexample.C | |
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 | // mmiexample.C | |
22 | // simple device model that uses the SAM MMI API. | |
23 | // 2005.05.31 | |
24 | ||
25 | #include <stdio.h> | |
26 | #include <sys/types.h> | |
27 | ||
28 | #include "mmi.h" | |
29 | ||
30 | extern "C" void mmiexample_instance_creator(const char * modname, const char * instancename); | |
31 | extern "C" int mmiexample_access(uint32_t cpuid, void* obj, uint64_t paddr, mmi_bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask); | |
32 | ||
33 | // mmiexample - a simple device that returns monotonically increasing counter values | |
34 | // store resets the counter | |
35 | ||
36 | // "mmiexample" is instantiated using a simple sysconf directive: | |
37 | // sysconf mmiexample example1 # no arguments | |
38 | ||
39 | ||
40 | struct mmiexample_s { | |
41 | int counter; | |
42 | }; // struct mmiexample_s | |
43 | ||
44 | ||
45 | extern "C" void _init() | |
46 | { | |
47 | mmi_register_instance_creator("example", mmiexample_instance_creator); | |
48 | } | |
49 | ||
50 | ||
51 | void mmiexample_instance_creator(const char * modname, const char * instance_name) | |
52 | { | |
53 | printf("%s: Instantiating %s\n", modname, instance_name); | |
54 | ||
55 | // call mmi_argc() and mmi_argv() here to get device node arguments | |
56 | ||
57 | mmiexample_s * instance_data = new mmiexample_s; | |
58 | instance_data->counter = 0; | |
59 | ||
60 | // we currently support only one instance at a hardcoded physical address of 0xdeadbeef0 | |
61 | mmi_map_physio(0xdeadbeef0, 8, (void *)instance_data, mmiexample_access); | |
62 | ||
63 | } // example_instance_creator() | |
64 | ||
65 | ||
66 | ||
67 | ||
68 | int mmiexample_access(uint32_t cpuid, void* obj, uint64_t paddr, mmi_bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask) | |
69 | { | |
70 | mmiexample_s * instance_data = (mmiexample_s *) obj; | |
71 | ||
72 | // should check args like paddr, size etc but for now we assume that a uint64_t is passed in *buf | |
73 | if (wr) { | |
74 | instance_data->counter = (int) *buf; | |
75 | return 0; | |
76 | } else { | |
77 | *buf = (uint64_t) (++ instance_data->counter); | |
78 | return 0; | |
79 | } | |
80 | } | |
81 |