summaryrefslogtreecommitdiffstats
path: root/release/sysinstall/uc_isa.c
blob: 689ad1b78069178694025122ab4be31318327f02 (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/***************************************************
 * file: userconfig/uc_isa.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.
 *
 * $FreeBSD$
 */

#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <nlist.h>
#include <i386/isa/isa_device.h>

#include "uc_main.h"

void
get_isa_info(struct kernel *kp){
  int total, i, j;
  struct uc_isa *idp;
  struct isa_device *p, *isa_dp;
  struct isa_driver *drv;
  char *name;

  if(kp->nl[ISA_BIOTAB].n_value || kp->nl[ISA_TTYTAB].n_value || kp->nl[ISA_NETTAB].n_value ||
     kp->nl[ISA_NULLTAB].n_value || kp->nl[ISA_WDCTAB].n_value || kp->nl[ISA_FDCTAB].n_value) {

    idp = kp->isa_devp = (struct uc_isa *)malloc(sizeof(struct uc_isa));
    total=0; /* a running total of the number of isa devices */

    for (i=0; i<6; i++) { /* the isa devices */
      if(kp->nl[i].n_value) {
	p = isa_dp = (struct isa_device *)kv_to_u(kp, kp->nl[i].n_value,   /* XXX size? */
						  sizeof(struct isa_device)*30);
	/* build the device list */
	/* `total' keeps a running total of all the devices found */
	for (j=0; p->id_id; j++, p++, total++) {
	  kp->isa_devp = (struct uc_isa *)realloc(kp->isa_devp,
						  sizeof(struct uc_isa)*(total+1));
	  idp=kp->isa_devp+total;

	  drv=(struct isa_driver *)kv_to_u(kp, (u_int)p->id_driver, sizeof(struct isa_driver));
	  name=(char *)kv_to_u(kp, (u_int)drv->name, 64);

	  if (i==ISA_WDCTAB || i==ISA_FDCTAB) { /* special case the disk devices */
	    char n[10];
	    strncpy(n, name, 10);
	    n[strlen(n)-1]=0; /* chop off the trailing 'c' */
	    asprintf(&idp->device, "%s%d", n, j);
	  } else {
	    asprintf(&idp->device, "%s%d", name, p->id_unit);
	  }
	  idp->port=p->id_iobase;
	  idp->irq=p->id_irq;
	  idp->drq=p->id_drq;
	  idp->iomem=(u_int)p->id_maddr & 0xFFFFFF; /* kludge to get pa from kva */
	  idp->iosize=p->id_msize;
	  idp->flags=p->id_flags;
	  idp->alive=p->id_alive;
	  idp->enabled=p->id_enabled;
	  idp->modified=0;
	  if(!kp->incore){
	    idp->idp=p;
	  } else {
	    free(name);
	    free(drv);
	  }
	}
	if(kp->incore){
	  free(isa_dp);
	}
      }
    }

    idp=kp->isa_devp+total;
    bzero(idp, sizeof(struct uc_isa));
  } else {
    kp->isa_devp=0;
  }
}


struct list *
get_isa_devlist(struct kernel *kp){
  struct list *dl;
  struct uc_isa *kdp;

  dl=list_new();

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


struct list *
get_isa_device(struct uc_isa *ip){
  struct list *list;
  char *tmp;

  list=list_new();

  asprintf(&tmp, "%s", ip->device );
  list_append(list, tmp);
  free(tmp);

  asprintf(&tmp, "0x%04x", ip->port );
  list_append(list, tmp);
  free(tmp);

  asprintf(&tmp, "%d", ip->irq>0 ? ffs(ip->irq)-1 : ip->irq);
  list_append(list, tmp);
  free(tmp);

  asprintf(&tmp, "%d", ip->drq );
  list_append(list, tmp);
  free(tmp);

  asprintf(&tmp, "0x%08x", ip->iomem );
  list_append(list, tmp);
  free(tmp);

  asprintf(&tmp, "0x%x", ip->iosize );
  list_append(list, tmp);
  free(tmp);

  asprintf(&tmp, "0x%x", ip->flags );
  list_append(list, tmp);
  free(tmp);

  asprintf(&tmp, "%d", ip->alive );
  list_append(list, tmp);
  free(tmp);

  asprintf(&tmp, "%d", ip->enabled );
  list_append(list, tmp);
  free(tmp);

  return(list);
}

int
isa_setdev(struct kernel *kp, struct list *list){
  int r=1, irq;
  struct uc_isa *ip;

  if(kp->isa_devp)
    for(ip=kp->isa_devp;ip->device;ip++){
      if(strcmp(list->av[0], ip->device)==0){
	ip->modified=1;
	ip->port = strtol(list->av[1], (char **)NULL, 0);
	irq=strtol(list->av[2], (char **)NULL, 0);
	ip->irq=  irq > 0 ? 1 << (irq) : irq;
	ip->drq = strtol(list->av[3], (char **)NULL, 0);
	ip->iomem = strtol(list->av[4], (char **)NULL, 0);
	ip->iosize = strtol(list->av[5], (char **)NULL, 0);
	ip->flags = strtol(list->av[6], (char **)NULL, 0);
	ip->enabled = strtol(list->av[8], (char **)NULL, 0);
	r=0;
	break;
      }
    }
  return(r);
}

void
isa_free(struct kernel *kp, int writeback){
  struct uc_isa *ip;
  for(ip=kp->isa_devp; ip->device; ip++){
    if((!kp->incore) && ip->modified && writeback) {
      /* save any changes */
      ip->idp->id_iobase=ip->port;
      ip->idp->id_irq = ip->irq;
      ip->idp->id_drq = ip->drq;
      ip->idp->id_maddr = (caddr_t)ip->iomem;
      ip->idp->id_msize = ip->iosize;
      ip->idp->id_flags = ip->flags;
      ip->idp->id_enabled = ip->enabled;
    }
    /* and, be free... */
    free(ip->device);
  }
  /* and free the whole ball of wax */
  free(kp->isa_devp);
  kp->isa_devp=0;
}

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