summaryrefslogtreecommitdiffstats
path: root/release/sysinstall/uc_eisa.c
blob: 11f199bc234ce383ced8946a1fb9f54811f40cf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/***************************************************
 * file: userconfig/uc_eisa.c
 *
 * Copyright (c) 1996 Eric L. Hernes (erich@rrnet.com)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software withough specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $Id: uc_eisa.c,v 1.1 1996/10/03 06:01:37 jkh Exp $
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <nlist.h>
#include <i386/eisa/eisaconf.h>

#include "uc_main.h"

struct eisa_device_node {
  struct  eisa_device dev;
  struct  eisa_device_node *next;
};

/* module prototypes */
static void eisa_fill_in(struct kernel *, struct uc_eisa *, struct eisa_device_node *);

void
get_eisa_info(struct kernel *kp){
  int i, total;
  u_int *ls;
  struct eisa_driver *ed;
  struct uc_eisa *ep, *epc;
  char *name;

  if(kp->nl[EISA_SET].n_value || kp->nl[EISA_LIST].n_value) {
    ep=epc=(struct uc_eisa *)malloc(sizeof(struct uc_eisa));
    if(!kp->incore) {
      if(kp->nl[EISA_SET].n_value) {
	u_int ndev;
	ls=(u_int *)kv_to_u(kp, kp->nl[EISA_SET].n_value, sizeof(u_int)*10); /* XXX, size? */
	ndev=ls[0];
	for(i=1;i<(ndev+1);i++){
	  ep=(struct uc_eisa *)realloc(ep, sizeof(struct uc_eisa)*i);
	  epc = ep+(i-1);
	  ed=(struct eisa_driver *)kv_to_u(kp, ls[i], sizeof(struct eisa_driver));
	  name=(char *)kv_to_u(kp, (u_int)ed->name, 10); /* XXX, size? */
	  asprintf(&epc->device, "%s", name);
	  asprintf(&epc->full_name, "?");
	}
	ep=(struct uc_eisa *)realloc(ep, sizeof(struct uc_eisa)*i);
	epc = ep+(i-1);
	bzero(epc, sizeof(struct uc_eisa));
	kp->eisa_devp=ep;
      } else { /*  not incore and no symbol, we have no EISA devs... */
	kp->eisa_devp=(struct uc_eisa *)0;
      }
    } else {
      /* if we're incore, we can get data from _eisa_dev_list, */
      /* which should be much more useful, but I'll need a machine */
      /* to test :( */
      if(kp->nl[EISA_LIST].n_value) {
	u_int t;
	struct eisa_device_node *edn;

	t=kv_dref_p(kp, kp->nl[EISA_LIST].n_value);
	total=0;
	while(t) {
	  edn=(struct eisa_device_node *)
	    kv_to_u(kp, t,sizeof(struct eisa_device_node));
	  ep=(struct uc_eisa *)realloc(ep, sizeof(struct uc_eisa)*(total+1));
	  epc=ep+total;
	  eisa_fill_in(kp, epc, edn);
	  t=(u_int)edn->next;
	  free(edn);
	  total++;
	}

	ep=(struct uc_eisa *)realloc(ep, sizeof(struct uc_eisa)*(total+1));
	epc=ep+total;
	bzero(epc, sizeof(struct uc_eisa));
	kp->eisa_devp=ep;
      } else {
	kp->eisa_devp=(struct uc_eisa *)0;
      }
    }
  } else {
    kp->eisa_devp=(struct uc_eisa *)0;
  }
}

struct list *
get_eisa_devlist(struct kernel *kp){
  struct list *dl;
  struct uc_eisa *kdp;

  dl=list_new();

  for(kdp=kp->eisa_devp; kdp->device; kdp++){
    list_append(dl, kdp->device);
  }
  return(dl);
}


struct list *
get_eisa_device(struct uc_eisa *ep){
  struct list *list;
  list=list_new();

  list_append(list, ep->device);
  list_append(list, ep->full_name);

  return(list);
}


static void
eisa_fill_in(struct kernel *kp, struct uc_eisa *epc, struct eisa_device_node *edn){
  struct eisa_driver *edrv;
  char *n;

  edrv=(struct eisa_driver *)kv_to_u(kp, (u_int)edn->dev.driver,
				     sizeof(struct eisa_driver));

  n=(char *)kv_to_u(kp, (u_int)edrv->name, 20);
  asprintf(&epc->device, "%s%d", n, edn->dev.unit);
  free(n);

  n=(char *)kv_to_u(kp, (u_int)edn->dev.full_name, 40); /*XXX*/
  asprintf(&epc->full_name, "%s", n);
  free(n);
  free(edrv);
}

void
eisa_free(struct kernel *kp, int writeback){
  struct uc_eisa *ep;

  for(ep=kp->eisa_devp;ep->device;ep++){
    free(ep->device);
    free(ep->full_name);
  }
  free(kp->eisa_devp);
  kp->eisa_devp=0;
}

/* end of userconfig/uc_eisa.c */
OpenPOWER on IntegriCloud