OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [common/] [v2_0/] [src/] [iosys.c] - Blame information for rev 565

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      io/iosys.c
4
//
5
//      I/O Subsystem + Device Table support
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):   gthomas
44
// Contributors:  gthomas
45
// Date:        1999-02-04
46
// Purpose:     Device I/O Support
47
// Description: 
48
//
49
//####DESCRIPTIONEND####
50
//
51
//==========================================================================
52
 
53
#include <pkgconf/io.h>
54
#include <cyg/io/io.h>
55
#include <cyg/io/devtab.h>
56
#include <cyg/infra/diag.h>
57
 
58
//extern void cyg_io_init(void) CYGBLD_ATTRIB_CONSTRUCTOR
59
//  CYG_INIT_PRIORITY(CYG_INIT_BEFORE(LIBC));
60
 
61
// Checks that two strings are "equivalent" device names
62
// 'n1' is a string from the user
63
// 'n2' is a name in a device table entry
64
// 'cyg_io_compare()' will return true IFF
65
//    n1 == n2, for all characters
66
//    n2 ends in '/' and matches n1 up to the terminating '/'
67
// 'ptr' will get a pointer to the residual string.
68
static bool
69
cyg_io_compare(const char *n1, const char *n2, const char **ptr)
70
{
71
    while (*n1 && *n2) {
72
        if (*n1++ != *n2++) {
73
            return false;
74
        }
75
    }
76
    if (*n1) {
77
        // See if the devtab name is is a substring
78
        if (*(n2-1) == '/') {
79
            *ptr = n1;
80
            return true;
81
        }
82
    }
83
    if (*n1 || *n2) {
84
        return false;
85
    }
86
    *ptr = n1;
87
    return true;
88
}
89
 
90
//
91
// This function is called during system initialization.  The purpose is
92
// to step through all devices linked into the system, calling their
93
// "init" entry points.  
94
//
95
 
96
void
97
cyg_io_init(void)
98
{
99
    static int _init = false;
100
    cyg_devtab_entry_t *t;
101
    if (_init) return;
102
    for (t = &__DEVTAB__[0]; t != &__DEVTAB_END__; t++) {
103
#ifdef CYGDBG_IO_INIT
104
        diag_printf("Init device '%s'\n", t->name);
105
#endif
106
        if (t->init(t)) {
107
            t->status |= CYG_DEVTAB_STATUS_AVAIL;
108
        } else {
109
            // What to do if device init fails?
110
            // Device not [currently] available
111
            t->status &= ~CYG_DEVTAB_STATUS_AVAIL;
112
        }
113
    }
114
    _init = true;
115
}
116
 
117
//
118
// Look up the devtab entry for a named device and return its handle.
119
// If the device is found and it has a "lookup" function, call that
120
// function to allow the device/driver to perform any necessary
121
// initializations.
122
//
123
 
124
Cyg_ErrNo
125
cyg_io_lookup(const char *name, cyg_io_handle_t *handle)
126
{
127
    cyg_devtab_entry_t *t, *st;
128
    Cyg_ErrNo res;
129
    const char *name_ptr;
130
    for (t = &__DEVTAB__[0]; t != &__DEVTAB_END__; t++) {
131
        if (cyg_io_compare(name, t->name, &name_ptr)) {
132
            // FUTURE: Check 'avail'/'online' here
133
            if (t->dep_name) {
134
                res = cyg_io_lookup(t->dep_name, (cyg_io_handle_t *)&st);
135
                if (res != ENOERR) {
136
                    return res;
137
                }
138
            } else {
139
                st = (cyg_devtab_entry_t *)0;
140
            }
141
            if (t->lookup) {
142
                // This indirection + the name pointer allows the lookup routine
143
                // to return a different 'devtab' handle.  This will provide for
144
                // 'pluggable' devices, file names, etc.
145
                res = (t->lookup)(&t, st, name_ptr);
146
                if (res != ENOERR) {
147
                    return res;
148
                }
149
            }
150
            *handle = (cyg_io_handle_t)t;
151
            return ENOERR;
152
        }
153
    }
154
    return -ENOENT;  // Not found
155
}
156
 
157
//
158
// 'write' data to a device.
159
//
160
 
161
Cyg_ErrNo
162
cyg_io_write(cyg_io_handle_t handle, const void *buf, cyg_uint32 *len)
163
{
164
    cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
165
    // Validate request
166
    if (!t->handlers->write) {
167
        return -EDEVNOSUPP;
168
    }
169
    // Special check.  If length is zero, this just verifies that the 
170
    // 'write' method exists for the given device.
171
    if (NULL != len && 0 == *len) {
172
        return ENOERR;
173
    }
174
    return t->handlers->write(handle, buf, len);
175
}
176
 
177
//
178
// 'read' data from a device.
179
//
180
 
181
Cyg_ErrNo
182
cyg_io_read(cyg_io_handle_t handle, void *buf, cyg_uint32 *len)
183
{
184
    cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
185
    // Validate request
186
    if (!t->handlers->read) {
187
        return -EDEVNOSUPP;
188
    }
189
    // Special check.  If length is zero, this just verifies that the 
190
    // 'read' method exists for the given device.
191
    if (NULL != len && 0 == *len) {
192
        return ENOERR;
193
    }
194
    return t->handlers->read(handle, buf, len);
195
}
196
 
197
Cyg_ErrNo
198
cyg_io_bwrite(cyg_io_handle_t handle, const void *buf, cyg_uint32 *len, cyg_uint32 pos)
199
{
200
    cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
201
    // Validate request
202
    if (!t->handlers->bwrite) {
203
        return -EDEVNOSUPP;
204
    }
205
    // Special check.  If length is zero, this just verifies that the 
206
    // 'bwrite' method exists for the given device.
207
    if (NULL != len && 0 == *len) {
208
        return ENOERR;
209
    }
210
    return t->handlers->bwrite(handle, buf, len, pos);
211
}
212
 
213
//
214
// 'read' data from a device.
215
//
216
 
217
Cyg_ErrNo
218
cyg_io_bread(cyg_io_handle_t handle, void *buf, cyg_uint32 *len, cyg_uint32 pos)
219
{
220
    cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
221
    // Validate request
222
    if (!t->handlers->bread) {
223
        return -EDEVNOSUPP;
224
    }
225
    // Special check.  If length is zero, this just verifies that the 
226
    // 'bread' method exists for the given device.
227
    if (NULL != len && 0 == *len) {
228
        return ENOERR;
229
    }
230
    return t->handlers->bread(handle, buf, len, pos);
231
}
232
 
233
//
234
// Check device for available input or space for output
235
//
236
 
237
cyg_bool
238
cyg_io_select(cyg_io_handle_t handle, cyg_uint32 which, CYG_ADDRWORD info)
239
{
240
    cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
241
    // Validate request
242
    if (!t->handlers->select) {
243
        return -EDEVNOSUPP;
244
    }
245
 
246
    return t->handlers->select( handle, which, info );
247
}
248
 
249
//
250
// Get the configuration of a device.
251
//
252
 
253
Cyg_ErrNo
254
cyg_io_get_config(cyg_io_handle_t handle, cyg_uint32 key, void *buf, cyg_uint32 *len)
255
{
256
    cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
257
    // Validate request
258
    if (!t->handlers->get_config) {
259
        return -EDEVNOSUPP;
260
    }
261
    // Special check.  If length is zero, this just verifies that the 
262
    // 'get_config' method exists for the given device.
263
    if (NULL != len && 0 == *len) {
264
        return ENOERR;
265
    }
266
    return t->handlers->get_config(handle, key, buf, len);
267
}
268
 
269
//
270
// Change the configuration of a device.
271
//
272
 
273
Cyg_ErrNo
274
cyg_io_set_config(cyg_io_handle_t handle, cyg_uint32 key, const void *buf, cyg_uint32 *len)
275
{
276
    cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
277
    // Validate request
278
    if (!t->handlers->set_config) {
279
        return -EDEVNOSUPP;
280
    }
281
    // Special check.  If length is zero, this just verifies that the 
282
    // 'set_config' method exists for the given device.
283
    if (NULL != len && 0 == *len) {
284
        return ENOERR;
285
    }
286
    return t->handlers->set_config(handle, key, buf, len);
287
}
288
 
289
/*---------------------------------------------------------------------------*/
290
// Default functions for devio tables
291
 
292
Cyg_ErrNo cyg_devio_cwrite(cyg_io_handle_t handle, const void *buf, cyg_uint32 *len)
293
{
294
    return -EDEVNOSUPP;
295
}
296
 
297
Cyg_ErrNo cyg_devio_cread(cyg_io_handle_t handle, void *buf, cyg_uint32 *len)
298
{
299
    return -EDEVNOSUPP;
300
}
301
 
302
Cyg_ErrNo cyg_devio_bwrite(cyg_io_handle_t handle, const void *buf,
303
                        cyg_uint32 *len, cyg_uint32 pos)
304
{
305
    return -EDEVNOSUPP;
306
}
307
 
308
Cyg_ErrNo cyg_devio_bread(cyg_io_handle_t handle, void *buf,
309
                       cyg_uint32 *len, cyg_uint32 pos)
310
{
311
    return -EDEVNOSUPP;
312
}
313
 
314
Cyg_ErrNo
315
cyg_devio_select(cyg_io_handle_t handle, cyg_uint32 which, CYG_ADDRWORD info)
316
{
317
    CYG_UNUSED_PARAM(cyg_io_handle_t, handle);
318
    CYG_UNUSED_PARAM(cyg_uint32, which);
319
    CYG_UNUSED_PARAM(CYG_ADDRWORD, info);
320
    return -EDEVNOSUPP;
321
}
322
 
323
Cyg_ErrNo
324
cyg_devio_get_config(cyg_io_handle_t handle, cyg_uint32 key,
325
                     void* buf, cyg_uint32* len)
326
{
327
    CYG_UNUSED_PARAM(cyg_io_handle_t, handle);
328
    CYG_UNUSED_PARAM(cyg_uint32, key);
329
    CYG_UNUSED_PARAM(void*, buf);
330
    CYG_UNUSED_PARAM(cyg_uint32*, len);
331
    return -EDEVNOSUPP;
332
}
333
 
334
Cyg_ErrNo
335
cyg_devio_set_config(cyg_io_handle_t handle, cyg_uint32 key,
336
                     void* buf, cyg_uint32* len)
337
{
338
    CYG_UNUSED_PARAM(cyg_io_handle_t, handle);
339
    CYG_UNUSED_PARAM(cyg_uint32, key);
340
    CYG_UNUSED_PARAM(void*, buf);
341
    CYG_UNUSED_PARAM(cyg_uint32*, len);
342
    return -EDEVNOSUPP;
343
}
344
 
345
/*---------------------------------------------------------------------------*/
346
/* End of io/iosys.c */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.