3 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 DECLARE_GLOBAL_DATA_PTR;
33 device_t *stdio_devices[] = {NULL, NULL, NULL};
34 char *stdio_names[MAX_FILES] = {"stdin", "stdout", "stderr"};
36 /**************************************************************************
38 **************************************************************************
40 static void drv_system_init(void){
43 memset(&dev, 0, sizeof(dev));
45 strcpy(dev.name, "serial");
46 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
48 dev.putc = serial_putc;
49 dev.puts = serial_puts;
50 dev.getc = serial_getc;
51 dev.tstc = serial_tstc;
53 device_register(&dev);
56 /**************************************************************************
58 **************************************************************************
60 int device_register(device_t * dev){
61 ListInsertItem(devlist, dev, LIST_END);
66 * deregister the device "devname".
67 * returns 0 if success, -1 if device is assigned and 1 if devname not found
69 #ifdef CFG_DEVICE_DEREGISTER
70 int device_deregister(char *devname){
73 char temp_names[3][8];
77 for(i=1; i<=ListNumItems(devlist); i++){
78 dev = ListGetPtrToItem(devlist, i);
80 if(strcmp(dev->name,devname)==0){
86 if(dev_index<0){ /* device not found */
90 /* get stdio devices (ListRemoveItem changes the dev list) */
91 for(l=0; l< MAX_FILES; l++){
92 if(stdio_devices[l] == dev){
93 /* Device is assigned -> report error */
96 memcpy(&temp_names[l][0], stdio_devices[l]->name, sizeof(stdio_devices[l]->name));
99 ListRemoveItem(devlist,NULL,dev_index);
101 /* reassign Device list */
102 for(i=1; i<=ListNumItems(devlist); i++){
103 dev = ListGetPtrToItem(devlist, i);
105 for(l=0; l< MAX_FILES; l++){
106 if(strcmp(dev->name,temp_names[l])==0){
107 stdio_devices[l] = dev;
114 #endif /* CFG_DEVICE_DEREGISTER */
116 int devices_init(void){
117 ulong relocation_offset = gd->reloc_off;
120 /* relocate device name pointers */
121 for(i = 0; i < (sizeof(stdio_names) / sizeof(char *)); ++i){
122 stdio_names[i] = (char *)(((ulong)stdio_names[i]) + relocation_offset);
125 /* Initialize the list */
126 devlist = ListCreate(sizeof(device_t));
129 eputs("Cannot initialize the list of devices!\n");
135 #ifdef CONFIG_NETCONSOLE
142 int devices_done(void){
143 ListDispose(devlist);