Deleted Added
full compact
subr_bus.c (61544) subr_bus.c (61640)
1/*-
2 * Copyright (c) 1997,1998 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1997,1998 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/kern/subr_bus.c 61544 2000-06-11 07:19:20Z bde $
26 * $FreeBSD: head/sys/kern/subr_bus.c 61640 2000-06-13 22:28:50Z peter $
27 */
28
29#include "opt_bus.h"
30
31#include <sys/param.h>
32#include <sys/queue.h>
33#include <sys/malloc.h>
34#include <sys/kernel.h>

--- 1168 unchanged lines hidden (view full) ---

1203
1204#endif
1205
1206/*======================================*/
1207/*
1208 * Access functions for device resources.
1209 */
1210
27 */
28
29#include "opt_bus.h"
30
31#include <sys/param.h>
32#include <sys/queue.h>
33#include <sys/malloc.h>
34#include <sys/kernel.h>

--- 1168 unchanged lines hidden (view full) ---

1203
1204#endif
1205
1206/*======================================*/
1207/*
1208 * Access functions for device resources.
1209 */
1210
1211/* Supplied by config(8) in ioconf.c */
1212extern struct config_device config_devtab[];
1213extern int devtab_count;
1214
1215/* Runtime version */
1211/* Runtime version */
1216struct config_device *devtab = config_devtab;
1212static struct config_device *devtab;
1213static int devtab_count = 0;
1217
1218static int
1219resource_new_name(const char *name, int unit)
1220{
1221 struct config_device *new;
1222
1223 new = malloc((devtab_count + 1) * sizeof(*new), M_TEMP, M_NOWAIT);
1224 if (new == NULL)

--- 262 unchanged lines hidden (view full) ---

1487 free(res->u.stringval, M_TEMP);
1488 res->u.stringval = malloc(strlen(value) + 1, M_TEMP, M_NOWAIT);
1489 if (res->u.stringval == NULL)
1490 return ENOMEM;
1491 strcpy(res->u.stringval, value);
1492 return 0;
1493}
1494
1214
1215static int
1216resource_new_name(const char *name, int unit)
1217{
1218 struct config_device *new;
1219
1220 new = malloc((devtab_count + 1) * sizeof(*new), M_TEMP, M_NOWAIT);
1221 if (new == NULL)

--- 262 unchanged lines hidden (view full) ---

1484 free(res->u.stringval, M_TEMP);
1485 res->u.stringval = malloc(strlen(value) + 1, M_TEMP, M_NOWAIT);
1486 if (res->u.stringval == NULL)
1487 return ENOMEM;
1488 strcpy(res->u.stringval, value);
1489 return 0;
1490}
1491
1495
1492/*
1493 * We use the identify routine to get the hints for all the other devices.
1494 * Strings that are all digits or begin with 0x are integers.
1495 *
1496 * hint.aha.0.bus_speedup=1
1497 * hint.aha.1.irq=10
1498 * hint.wl.0.netid=PLUG
1499 * hint.wl.1.netid=XYZZY
1500 */
1496static void
1501static void
1497resource_cfgload(void *dummy __unused)
1502hint_load(char *cp)
1498{
1503{
1499 struct config_resource *res, *cfgres;
1500 int i, j;
1501 int error;
1502 char *name, *resname;
1503 int unit;
1504 resource_type type;
1505 char *stringval;
1506 int config_devtab_count;
1504 char *ep, *op, *walker;
1505 int len;
1506 int val;
1507 char name[20];
1508 int unit;
1509 char resname[255];
1510
1511 for (ep = cp; (*ep != '=') && (*ep != 0); ep++)
1512 ;
1513 len = ep - cp;
1514 if (*ep == '=')
1515 ep++;
1516 if (strncmp(cp, "hint.", 5) != 0)
1517 return;
1518 walker = cp;
1519 walker += 5;
1520 op = walker;
1521 while (*walker && *walker != '.')
1522 walker++;
1523 if (*walker != '.')
1524 return;
1525 if (walker - op > sizeof(name))
1526 return;
1527 strncpy(name, op, walker - op);
1528 name[walker - op] = '\0';
1529 walker++;
1530 op = walker;
1531 while (*walker && *walker != '.')
1532 walker++;
1533 if (*walker != '.')
1534 return;
1535 unit = strtol(op, &walker, 0);
1536 if (*walker != '.')
1537 return;
1538 walker++;
1539 op = walker;
1540 while (*walker && *walker != '=')
1541 walker++;
1542 if (*walker != '=')
1543 return;
1544 if (walker - op > sizeof(resname))
1545 return;
1546 strncpy(resname, op, walker - op);
1547 resname[walker - op] = '\0';
1548 walker++;
1549 if (walker != ep)
1550 return;
1551 if (1 || bootverbose)
1552 printf("Setting %s %d %s to ", name, unit, resname);
1553 val = strtol(ep, &op, 0);
1554 if (*ep != '\0' && *op == '\0') {
1555 resource_set_int(name, unit, resname, val);
1556 if (1 || bootverbose)
1557 printf("%d (int)\n", val);
1558 } else {
1559 resource_set_string(name, unit, resname, ep);
1560 if (1 || bootverbose)
1561 printf("%s (string)\n", ep);
1562 }
1563}
1507
1564
1508 config_devtab_count = devtab_count;
1509 devtab = NULL;
1510 devtab_count = 0;
1565extern char static_hints[];
1511
1566
1512 for (i = 0; i < config_devtab_count; i++) {
1513 name = config_devtab[i].name;
1514 unit = config_devtab[i].unit;
1567static void
1568hints_load(void *dummy __unused)
1569{
1570 char *cp;
1515
1571
1516 for (j = 0; j < config_devtab[i].resource_count; j++) {
1517 cfgres = config_devtab[i].resources;
1518 resname = cfgres[j].name;
1519 type = cfgres[j].type;
1520 error = resource_create(name, unit, resname, type,
1521 &res);
1522 if (error) {
1523 printf("create resource %s%d: error %d\n",
1524 name, unit, error);
1525 continue;
1526 }
1527 if (res->type != type) {
1528 printf("type mismatch %s%d: %d != %d\n",
1529 name, unit, res->type, type);
1530 continue;
1531 }
1532 switch (type) {
1533 case RES_INT:
1534 res->u.intval = cfgres[j].u.intval;
1535 break;
1536 case RES_LONG:
1537 res->u.longval = cfgres[j].u.longval;
1538 break;
1539 case RES_STRING:
1540 if (res->u.stringval)
1541 free(res->u.stringval, M_TEMP);
1542 stringval = cfgres[j].u.stringval;
1543 res->u.stringval = malloc(strlen(stringval) + 1,
1544 M_TEMP, M_NOWAIT);
1545 if (res->u.stringval == NULL)
1546 break;
1547 strcpy(res->u.stringval, stringval);
1548 break;
1549 default:
1550 panic("unknown resource type %d\n", type);
1551 }
1552 }
1572 cp = static_hints;
1573 while (cp) {
1574 hint_load(cp);
1575 while (*cp != 0)
1576 cp++;
1577 cp++;
1578 if (*cp == 0)
1579 break;
1553 }
1580 }
1581 cp = kern_envp;
1582 while (cp) {
1583 hint_load(cp);
1584 while (*cp != 0)
1585 cp++;
1586 cp++;
1587 if (*cp == 0)
1588 break;
1589 }
1554}
1590}
1555SYSINIT(cfgload, SI_SUB_KMEM, SI_ORDER_ANY + 50, resource_cfgload, 0)
1591SYSINIT(cfghints, SI_SUB_KMEM, SI_ORDER_ANY + 60, hints_load, 0)
1556
1592
1557
1558/*======================================*/
1559/*
1560 * Some useful method implementations to make life easier for bus drivers.
1561 */
1562
1563void
1564resource_list_init(struct resource_list *rl)
1565{

--- 754 unchanged lines hidden ---
1593/*======================================*/
1594/*
1595 * Some useful method implementations to make life easier for bus drivers.
1596 */
1597
1598void
1599resource_list_init(struct resource_list *rl)
1600{

--- 754 unchanged lines hidden ---