Annotation of Gnu-Mach/chips/busses.c, revision 1.1.1.3

1.1       root        1: /* 
                      2:  * Mach Operating System
                      3:  * Copyright (c) 1993-1989 Carnegie Mellon University
                      4:  * All Rights Reserved.
                      5:  * 
                      6:  * Permission to use, copy, modify and distribute this software and its
                      7:  * documentation is hereby granted, provided that both the copyright
                      8:  * notice and this permission notice appear in all copies of the
                      9:  * software, derivative works or modified versions, and any portions
                     10:  * thereof, and that both notices appear in supporting documentation.
                     11:  * 
                     12:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     13:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                     14:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     15:  * 
                     16:  * Carnegie Mellon requests users of this software to return to
                     17:  * 
                     18:  *  Software Distribution Coordinator  or  [email protected]
                     19:  *  School of Computer Science
                     20:  *  Carnegie Mellon University
                     21:  *  Pittsburgh PA 15213-3890
                     22:  * 
                     23:  * any improvements or extensions that they make and grant Carnegie Mellon
                     24:  * the rights to redistribute these changes.
                     25:  */
                     26: /*
                     27:  *     File: busses.c
                     28:  *     Author: Alessandro Forin, Carnegie Mellon University
                     29:  *     Date:   4/90
                     30:  *
                     31:  *     Generic autoconfiguration functions,
                     32:  *     usable to probe and attach devices
                     33:  *     on any bus that suits the generic bus
                     34:  *     structure, such as VME, TURBOChannel,
                     35:  *     and all the VAX busses.
                     36:  *
                     37:  */
                     38: 
1.1.1.2   root       39: #include <string.h>
                     40: #include <kern/printf.h>
1.1       root       41: #include <mach/boolean.h>
                     42: #include <mach/std_types.h>
                     43: #include <chips/busses.h>
                     44: 
                     45: 
                     46: 
                     47: 
                     48: /*
                     49:  * configure_bus_master
                     50:  *
                     51:  *     Given the name of a bus_ctlr, look it up in the
                     52:  *     init table.  If found, probe it.  If there can be
                     53:  *     slaves attached, walk the device's init table
                     54:  *     for those that might be attached to this controller.
                     55:  *     Call the 'slave' function on each one to see if
                     56:  *     ok, then the 'attach' one.
                     57:  *
                     58:  * Returns 0 if the controller is not there.
                     59:  *
                     60:  */
                     61: boolean_t configure_bus_master(
1.1.1.3 ! root       62:        const char      *name,
1.1       root       63:        vm_offset_t      virt,
                     64:        vm_offset_t      phys,
                     65:        int              adpt_no,
1.1.1.3 ! root       66:        const char      *bus_name)
1.1       root       67: {
1.1.1.3 ! root       68:        struct bus_device *device;
        !            69:        struct bus_ctlr *master;
        !            70:        struct bus_driver *driver;
1.1       root       71: 
1.1.1.3 ! root       72:        boolean_t             found = FALSE;
1.1       root       73: 
                     74:        /*
                     75:         * Match the name in the table, then pick the entry that has the
                     76:         * right adaptor number, or one that has it wildcarded.  Entries
                     77:         * already allocated are marked alive, skip them. 
                     78:         */
                     79:        for (master = bus_master_init; master->driver; master++) {
                     80:                if (master->alive)
                     81:                        continue;
                     82:                if (((master->adaptor == adpt_no) || (master->adaptor == '?')) &&
                     83:                    (strcmp(master->name, name) == 0)) {
1.1.1.3 ! root       84:                        found = TRUE;
1.1       root       85:                        break;
                     86:                }
                     87:        }
                     88: 
                     89:        if (!found)
                     90:                return FALSE;
                     91: 
                     92:        /*
                     93:         * Found a match, probe it 
                     94:         */
                     95:        driver = master->driver;
                     96:        if ((*driver->probe) (virt, master) == 0)
                     97:                return FALSE;
                     98: 
                     99:        master->alive = 1;
                    100:        master->adaptor = adpt_no;
                    101: 
                    102:        /*
                    103:         * Remember which controller this device is attached to 
                    104:         */
                    105:        driver->minfo[master->unit] = master;
                    106: 
                    107:        printf("%s%d: at %s%d\n", master->name, master->unit, bus_name, adpt_no);
                    108: 
                    109:        /*
                    110:         * Now walk all devices to check those that might be attached to this
                    111:         * controller.  We match the unallocated ones that have the right
                    112:         * controller number, or that have a widcarded controller number. 
                    113:         */
                    114:        for (device = bus_device_init; device->driver; device++) {
                    115:                int     ctlr;
                    116:                if (device->alive || device->driver != driver ||
                    117:                    (device->adaptor != '?' && device->adaptor != adpt_no))
                    118:                        continue;
                    119:                ctlr = device->ctlr;
                    120:                if (ctlr == '?') device->ctlr = master->unit;
                    121:                /*
                    122:                 * A matching entry. See if the slave-probing routine is
                    123:                 * happy. 
                    124:                 */
                    125:                if ((device->ctlr != master->unit) ||
                    126:                    ((*driver->slave) (device, virt) == 0)) {
                    127:                        device->ctlr = ctlr;
                    128:                        continue;
                    129:                }
                    130: 
                    131:                device->alive = 1;
                    132:                device->adaptor = adpt_no;
                    133:                device->ctlr = master->unit;
                    134: 
                    135:                /*
                    136:                 * Save a backpointer to the controller 
                    137:                 */
                    138:                device->mi = master;
                    139: 
                    140:                /*
                    141:                 * ..and to the device 
                    142:                 */
                    143:                driver->dinfo[device->unit] = device;
                    144: 
                    145:                if (device->slave >= 0)
                    146:                        printf(" %s%d: at %s%d slave %d",
                    147:                               device->name, device->unit,
                    148:                               driver->mname, master->unit, device->slave);
                    149:                else
                    150:                        printf(" %s%d: at %s%d",
                    151:                               device->name, device->unit,
                    152:                               driver->mname, master->unit);
                    153: 
                    154:                /*
                    155:                 * Now attach this slave 
                    156:                 */
                    157:                (*driver->attach) (device);
                    158:                printf("\n");
                    159:        }
                    160:        return TRUE;
                    161: }
                    162: 
                    163: /*
                    164:  * configure_bus_device
                    165:  *
                    166:  *     Given the name of a bus_device, look it up in the
                    167:  *     init table.  If found, probe it.  If it is present,
                    168:  *     call the driver's 'attach' function.
                    169:  *
                    170:  * Returns 0 if the device is not there.
                    171:  *
                    172:  */
                    173: boolean_t configure_bus_device( 
1.1.1.3 ! root      174:        const char      *name,
1.1       root      175:        vm_offset_t      virt,
                    176:        vm_offset_t      phys,
                    177:        int              adpt_no,
1.1.1.3 ! root      178:        const char      *bus_name)
1.1       root      179: {
1.1.1.3 ! root      180:        struct bus_device *device;
        !           181:        struct bus_driver *driver;
1.1       root      182: 
1.1.1.3 ! root      183:        boolean_t             found = FALSE;
1.1       root      184: 
                    185:        /*
                    186:         * Walk all devices to find one with the right name
                    187:         * and adaptor number (or wildcard).  The entry should
                    188:         * be unallocated, and also the slave number should
                    189:         * be wildcarded.
                    190:         */
                    191:        for (device = bus_device_init; device->driver; device++) {
                    192:                if (device->alive)
                    193:                        continue;
                    194:                if (((device->adaptor == adpt_no) || (device->adaptor == '?')) &&
                    195:                    (device->slave == -1) &&
                    196:                    ((!device->phys_address) ||
                    197:                     ((device->phys_address == phys) && (device->address == virt))) &&
                    198:                    (strcmp(device->name, name) == 0)) {
1.1.1.3 ! root      199:                        found = TRUE;
1.1       root      200:                        break;
                    201:                }
                    202:        }
                    203: 
                    204:        if (!found)
                    205:                return FALSE;
                    206: 
                    207:        /*
                    208:         * Found an entry, probe the device
                    209:         */
                    210:        driver = device->driver;
                    211:        if ((*driver->probe) (virt, (struct bus_ctlr *)device) == 0)
                    212:                return FALSE;
                    213: 
                    214:        device->alive = 1;
                    215:        device->adaptor = adpt_no;
                    216: 
                    217:        printf("%s%d: at %s%d", device->name, device->unit, bus_name, adpt_no);
                    218: 
                    219:        /*
                    220:         * Remember which driver this device is attached to 
                    221:         */
                    222:        driver->dinfo[device->unit] = device;
                    223: 
                    224:        /*
                    225:         * Attach the device
                    226:         */
                    227:        (*driver->attach) (device);
                    228:        printf("\n");
                    229: 
                    230:        return TRUE;
                    231: }
                    232: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.