Commit | Line | Data |
---|---|---|
451a9c05 AC |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1998, 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 | |
7 | the Free Software Foundation; either version 2 of the License, or | |
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 | |
16 | along with this program; if not, write to the Free Software | |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | ||
19 | */ | |
20 | ||
21 | ||
22 | #ifndef HW_INSTANCES_H | |
23 | #define HW_INSTANCES_H | |
24 | ||
25 | /* Instances: | |
26 | ||
27 | As with IEEE1275, a device can be opened, creating an instance. | |
28 | Instances provide more abstract interfaces to the underlying | |
29 | hardware. For example, the instance methods for a disk may include | |
30 | code that is able to interpret file systems found on disks. Such | |
31 | methods would there for allow the manipulation of files on the | |
32 | disks file system. The operations would be implemented using the | |
33 | basic block I/O model provided by the disk. | |
34 | ||
35 | This model includes methods that faciliate the creation of device | |
36 | instance and (should a given device support it) standard operations | |
37 | on those instances. | |
38 | ||
39 | */ | |
40 | ||
41 | ||
42 | struct hw_instance; | |
43 | ||
44 | ||
45 | typedef void (hw_finish_instance_method) | |
46 | (struct hw *hw, | |
47 | struct hw_instance *); | |
48 | ||
49 | extern void set_hw_finish_instance | |
50 | (struct hw *hw, | |
51 | hw_finish_instance_method *method); | |
52 | ||
53 | ||
54 | /* construct an instance of the hardware */ | |
55 | ||
56 | struct hw_instance *hw_instance_create | |
57 | (struct hw *hw, | |
58 | struct hw_instance *parent, | |
59 | const char *path, | |
60 | const char *args); | |
61 | ||
62 | struct hw_instance *hw_instance_interceed | |
63 | (struct hw_instance *parent, | |
64 | const char *path, | |
65 | const char *args); | |
66 | ||
67 | void hw_instance_delete | |
68 | (struct hw_instance *instance); | |
69 | ||
70 | ||
71 | /* methods applied to an instance of the hw */ | |
72 | ||
73 | typedef int (hw_instance_read_method) | |
74 | (struct hw_instance *instance, | |
75 | void *addr, | |
76 | unsigned_cell len); | |
77 | ||
78 | #define hw_instance_read(instance, addr, len) \ | |
79 | ((instance)->to_instance_read ((instance), (addr), (len))) | |
80 | ||
81 | #define set_hw_instance_read(instance, method) \ | |
82 | ((instance)->to_instance_read = (method)) | |
83 | ||
84 | ||
85 | typedef int (hw_instance_write_method) | |
86 | (struct hw_instance *instance, | |
87 | const void *addr, | |
88 | unsigned_cell len); | |
89 | ||
90 | #define hw_instance_write(instance, addr, len) \ | |
91 | ((instance)->to_instance_write ((instance), (addr), (len))) | |
92 | ||
93 | #define set_hw_instance_write(instance, method) \ | |
94 | ((instance)->to_instance_write = (method)) | |
95 | ||
96 | ||
97 | typedef int (hw_instance_seek_method) | |
98 | (struct hw_instance *instance, | |
99 | unsigned_cell pos_hi, | |
100 | unsigned_cell pos_lo); | |
101 | ||
102 | #define hw_instance_seek(instance, pos_hi, pos_lo) \ | |
103 | ((instance)->to_instance_seek ((instance), (pos_hi), (pos_lo))); | |
104 | ||
105 | #define set_hw_instance_seek(instance, method) \ | |
106 | ((instance)->to_instance_seek = (method)) | |
107 | ||
108 | ||
109 | int hw_instance_call_method | |
110 | (struct hw_instance *instance, | |
111 | const char *method, | |
112 | int n_stack_args, | |
113 | unsigned_cell stack_args[/*n_stack_args + 1(NULL)*/], | |
114 | int n_stack_returns, | |
115 | unsigned_cell stack_returns[/*n_stack_returns + 1(NULL)*/]); | |
116 | ||
117 | ||
118 | ||
119 | /* the definition of the instance */ | |
120 | ||
121 | #define hw_instance_hw(instance) ((instance)->hw_of_instance + 0) | |
122 | ||
123 | #define hw_instance_path(instance) ((instance)->path_of_instance + 0) | |
124 | ||
125 | #define hw_instance_args(instance) ((instance)->args_of_instance) | |
126 | ||
127 | #define hw_instance_data(instance) ((instance)->data_of_instance) | |
128 | ||
129 | #define hw_instance_system(instance) (hw_system (hw_instance_hw (instance))) | |
130 | ||
131 | ||
132 | ||
133 | /* Finally an instance of a hardware device - keep your grubby little | |
134 | mits off of these internals! :-) */ | |
135 | ||
136 | struct hw_instance { | |
137 | ||
138 | void *data_of_instance; | |
139 | char *args_of_instance; | |
140 | char *path_of_instance; | |
141 | ||
142 | /* the device that owns the instance */ | |
143 | struct hw *hw_of_instance; | |
144 | struct hw_instance *sibling_of_instance; | |
145 | ||
146 | /* interposed instance */ | |
147 | struct hw_instance *parent_of_instance; | |
148 | struct hw_instance *child_of_instance; | |
149 | ||
150 | /* methods */ | |
151 | hw_instance_read_method *to_instance_read; | |
152 | hw_instance_write_method *to_instance_write; | |
153 | hw_instance_seek_method *to_instance_seek; | |
154 | ||
155 | }; | |
156 | ||
157 | #endif |