Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au> | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
3fd725ef | 7 | the Free Software Foundation; either version 3 of the License, or |
c906108c SS |
8 | (at your option) any later version. |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
51b318de | 16 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
c906108c SS |
17 | |
18 | */ | |
19 | ||
20 | ||
21 | #ifndef _HW_CORE_C_ | |
22 | #define _HW_CORE_C_ | |
23 | ||
24 | #include "device_table.h" | |
25 | ||
26 | #include "corefile.h" | |
27 | ||
28 | ||
29 | /* DEVICE | |
30 | ||
31 | core - root of the device tree | |
32 | ||
33 | DESCRIPTION | |
34 | ||
35 | The core device positioned at the root of the device tree appears | |
36 | to its child devices as a normal device just like every other | |
37 | device in the tree. | |
38 | ||
39 | Internally it is implemented using a core object. Requests to | |
40 | attach (or detach) address spaces are passed to that core object. | |
41 | Requests to transfer (DMA) data are reflected back down the device | |
42 | tree using the core_map data transfer methods. | |
43 | ||
44 | PROPERTIES | |
45 | ||
46 | None. | |
47 | ||
48 | */ | |
49 | ||
50 | ||
51 | static void | |
52 | hw_core_init_address_callback(device *me) | |
53 | { | |
54 | core *memory = (core*)device_data(me); | |
55 | core_init(memory); | |
56 | } | |
57 | ||
58 | ||
59 | static void | |
60 | hw_core_attach_address_callback(device *me, | |
61 | attach_type attach, | |
62 | int space, | |
63 | unsigned_word addr, | |
64 | unsigned nr_bytes, | |
65 | access_type access, | |
66 | device *client) /*callback/default*/ | |
67 | { | |
68 | core *memory = (core*)device_data(me); | |
69 | if (space != 0) | |
70 | error("core_attach_address_callback() invalid address space\n"); | |
71 | core_attach(memory, | |
72 | attach, | |
73 | space, | |
74 | access, | |
75 | addr, | |
76 | nr_bytes, | |
77 | client); | |
78 | } | |
79 | ||
80 | ||
81 | static unsigned | |
82 | hw_core_dma_read_buffer_callback(device *me, | |
83 | void *dest, | |
84 | int space, | |
85 | unsigned_word addr, | |
86 | unsigned nr_bytes) | |
87 | { | |
88 | core *memory = (core*)device_data(me); | |
89 | return core_map_read_buffer(core_readable(memory), | |
90 | dest, | |
91 | addr, | |
92 | nr_bytes); | |
93 | } | |
94 | ||
95 | ||
96 | static unsigned | |
97 | hw_core_dma_write_buffer_callback(device *me, | |
98 | const void *source, | |
99 | int space, | |
100 | unsigned_word addr, | |
101 | unsigned nr_bytes, | |
102 | int violate_read_only_section) | |
103 | { | |
104 | core *memory = (core*)device_data(me); | |
105 | core_map *map = (violate_read_only_section | |
106 | ? core_readable(memory) | |
107 | : core_writeable(memory)); | |
108 | return core_map_write_buffer(map, | |
109 | source, | |
110 | addr, | |
111 | nr_bytes); | |
112 | } | |
113 | ||
114 | static device_callbacks const hw_core_callbacks = { | |
115 | { hw_core_init_address_callback, }, | |
116 | { hw_core_attach_address_callback, }, | |
117 | { NULL, }, /* IO */ | |
118 | { hw_core_dma_read_buffer_callback, | |
119 | hw_core_dma_write_buffer_callback, }, | |
120 | { NULL, }, /* interrupt */ | |
121 | { generic_device_unit_decode, | |
122 | generic_device_unit_encode, | |
123 | generic_device_address_to_attach_address, | |
124 | generic_device_size_to_attach_size, }, | |
125 | }; | |
126 | ||
127 | ||
128 | static void * | |
129 | hw_core_create(const char *name, | |
130 | const device_unit *unit_address, | |
131 | const char *args) | |
132 | { | |
133 | core *memory = core_create(); | |
134 | return memory; | |
135 | } | |
136 | ||
137 | const device_descriptor hw_core_device_descriptor[] = { | |
138 | { "core", hw_core_create, &hw_core_callbacks }, | |
139 | { NULL }, | |
140 | }; | |
141 | ||
142 | #endif /* _HW_CORE_C_ */ |