View | Details | Raw Unified | Return to bug 17219
Collapse All | Expand All

(-)pnpparse.c (-48 / +78 lines)
Lines 36-39 Link Here
36
#include <isa/pnpvar.h>
36
#include <isa/pnpvar.h>
37
37
38
#define	MAXDEP	8
39
38
#define I16(p)	((p)[0] + ((p)[1] << 8))
40
#define I16(p)	((p)[0] + ((p)[1] << 8))
39
#define I32(p)	(I16(p) + (I16(p+2) << 16))
41
#define I32(p)	(I16(p) + (I16(p+2) << 16))
Lines 43-48 Link Here
43
 *
45
 *
44
 * This function exits as soon as it gets an error reading *ANY*
46
 * This function exits as soon as it gets an error reading *ANY*
45
 * Resource Data or ir reaches the end of Resource Data.  In the first
47
 * Resource Data or it reaches the end of Resource Data.
46
 * case the return value will be TRUE, FALSE otherwise.
47
 */
48
 */
48
void
49
void
Lines 53-66 Link Here
53
	int large_len, scanning = len;
54
	int large_len, scanning = len;
54
	u_int32_t id, compat_id;
55
	u_int32_t id, compat_id;
55
	struct isa_config logdev, alt;
56
	struct isa_config *config;
56
	struct isa_config *config;
57
	int priority = 0;
57
	int ncfgs = 1;
58
	int seenalt = 0;
58
	int priorities[1 + MAXDEP];
59
	struct isa_config configs[1 + MAXDEP];
59
	char buf[100];
60
	char buf[100];
61
	int i;
60
62
61
	id = isa_get_logicalid(dev);
63
	id = isa_get_logicalid(dev);
62
	bzero(&logdev, sizeof logdev);
64
	bzero(configs, sizeof configs);
63
	bzero(&alt, sizeof alt);
65
	config = &configs[0];
64
	config = &logdev;
66
	priorities[0] = 0;
65
	resp = resources;
67
	resp = resources;
66
	while (scanning > 0) {
68
	while (scanning > 0) {
Lines 95-99 Link Here
95
				}
97
				}
96
				if (config->ic_nirq == ISA_NIRQ) {
98
				if (config->ic_nirq == ISA_NIRQ) {
97
					device_printf(parent, "too many irqs");
99
					device_printf(parent, "too many irqs\n");
98
					scanning = 0;
100
					scanning = 0;
99
					break;
101
					break;
Lines 111-115 Link Here
111
				}
113
				}
112
				if (config->ic_ndrq == ISA_NDRQ) {
114
				if (config->ic_ndrq == ISA_NDRQ) {
113
					device_printf(parent, "too many drqs");
115
					device_printf(parent, "too many drqs\n");
114
					scanning = 0;
116
					scanning = 0;
115
					break;
117
					break;
Lines 125-136 Link Here
125
					       pnp_eisaformat(id));
127
					       pnp_eisaformat(id));
126
				}
128
				}
127
				if (config == &alt) {
129
				if (ncfgs >= MAXDEP) {
128
					ISA_ADD_CONFIG(parent, dev,
130
					device_printf(parent, "too many dependant configs (%d)\n", MAXDEP);
129
						       priority, config);
130
				} else if (config != &logdev) {
131
					device_printf(parent, "malformed\n");
132
					scanning = 0;
131
					scanning = 0;
133
					break;
132
					break;
134
				}
133
				}
134
				config = &configs[ncfgs];
135
				/*
135
				/*
136
				 * If the priority is not specified,
136
				 * If the priority is not specified,
Lines 139-147 Link Here
139
				 */
139
				 */
140
				if (PNP_SRES_LEN(tag) > 0)
140
				if (PNP_SRES_LEN(tag) > 0)
141
					priority = resinfo[0];
141
					priorities[ncfgs] = resinfo[0];
142
				else
142
				else
143
					priority = 1;
143
					priorities[ncfgs] = 1;
144
				alt = logdev;
144
				ncfgs++;
145
				config = &alt;
146
				break;
145
				break;
147
146
Lines 151-157 Link Here
151
					       pnp_eisaformat(id));
150
					       pnp_eisaformat(id));
152
				}
151
				}
153
				ISA_ADD_CONFIG(parent, dev, priority, config);
152
				config = &configs[0];	/* back to main config */
154
				config = &logdev;
155
				seenalt = 1;
156
				break;
153
				break;
157
154
Lines 168-172 Link Here
168
				}
165
				}
169
				if (config->ic_nport == ISA_NPORT) {
166
				if (config->ic_nport == ISA_NPORT) {
170
					device_printf(parent, "too many ports");
167
					device_printf(parent, "too many ports\n");
171
					scanning = 0;
168
					scanning = 0;
172
					break;
169
					break;
Lines 189-193 Link Here
189
			case PNP_TAG_IO_FIXED:
186
			case PNP_TAG_IO_FIXED:
190
				if (bootverbose) {
187
				if (bootverbose) {
191
					printf("%s: adding io range "
188
					printf("%s: adding fixed io range "
192
					       "%#x-%#x, size=%#x, "
189
					       "%#x-%#x, size=%#x, "
193
					       "align=%#x\n",
190
					       "align=%#x\n",
Lines 199-203 Link Here
199
				}
196
				}
200
				if (config->ic_nport == ISA_NPORT) {
197
				if (config->ic_nport == ISA_NPORT) {
201
					device_printf(parent, "too many ports");
198
					device_printf(parent, "too many ports\n");
202
					scanning = 0;
199
					scanning = 0;
203
					break;
200
					break;
Lines 215-219 Link Here
215
			case PNP_TAG_END:
212
			case PNP_TAG_END:
216
				if (bootverbose) {
213
				if (bootverbose) {
217
					printf("%s: start dependant\n",
214
					printf("%s: end config\n",
218
					       pnp_eisaformat(id));
215
					       pnp_eisaformat(id));
219
				}
216
				}
Lines 223-227 Link Here
223
			default:
220
			default:
224
				/* Skip this resource */
221
				/* Skip this resource */
225
				device_printf(parent, "unexpected tag %d\n",
222
				device_printf(parent, "unexpected small tag %d\n",
226
					      PNP_SRES_NUM(tag));
223
					      PNP_SRES_NUM(tag));
227
				break;
224
				break;
Lines 252-258 Link Here
252
249
253
				/*
250
				/*
254
				 * Trim trailing spaces.
251
				 * Trim trailing spaces and garbage.
255
				 */
252
				 */
256
				while (buf[large_len-1] == ' ')
253
				while (large_len > 0 && buf[large_len - 1] <= ' ')
257
					large_len--;
254
					large_len--;
258
				buf[large_len] = '\0';
255
				buf[large_len] = '\0';
Lines 268-278 Link Here
268
					       I16(resinfo + 1)<<8,
265
					       I16(resinfo + 1)<<8,
269
					       (I16(resinfo + 3)<<8)
266
					       (I16(resinfo + 3)<<8)
270
					       + I16(resinfo + 7) - 1,
267
					       + (I16(resinfo + 7) << 8) - 1,
271
					       I16(resinfo + 7),
268
					       I16(resinfo + 7) << 8,
272
					       I16(resinfo + 5));
269
					       I16(resinfo + 5));
273
				}
270
				}
274
271
275
				if (config->ic_nmem == ISA_NMEM) {
272
				if (config->ic_nmem == ISA_NMEM) {
276
					device_printf(parent, "too many memory ranges");
273
					device_printf(parent, "too many memory ranges\n");
277
					scanning = 0;
274
					scanning = 0;
278
					break;
275
					break;
Lines 285-289 Link Here
285
					+ I16(resinfo + 7) - 1;
282
					+ I16(resinfo + 7) - 1;
286
				config->ic_mem[config->ic_nmem].ir_size =
283
				config->ic_mem[config->ic_nmem].ir_size =
287
					I16(resinfo + 7);
284
					I16(resinfo + 7) << 8;
288
				config->ic_mem[config->ic_nmem].ir_align =
285
				config->ic_mem[config->ic_nmem].ir_align =
289
					I16(resinfo + 5);
286
					I16(resinfo + 5);
Lines 296-300 Link Here
296
			case PNP_TAG_MEMORY32_RANGE:
293
			case PNP_TAG_MEMORY32_RANGE:
297
				if (bootverbose) {
294
				if (bootverbose) {
298
					printf("%s: adding memory range "
295
					printf("%s: adding memory32 range "
299
					       "%#x-%#x, size=%#x, "
296
					       "%#x-%#x, size=%#x, "
300
					       "align=%#x\n",
297
					       "align=%#x\n",
Lines 308-312 Link Here
308
305
309
				if (config->ic_nmem == ISA_NMEM) {
306
				if (config->ic_nmem == ISA_NMEM) {
310
					device_printf(parent, "too many memory ranges");
307
					device_printf(parent, "too many memory ranges\n");
311
					scanning = 0;
308
					scanning = 0;
312
					break;
309
					break;
Lines 334-338 Link Here
334
				}
331
				}
335
				if (bootverbose) {
332
				if (bootverbose) {
336
					printf("%s: adding memory range "
333
					printf("%s: adding fixed memory32 range "
337
					       "%#x-%#x, size=%#x\n",
334
					       "%#x-%#x, size=%#x\n",
338
					       pnp_eisaformat(id),
335
					       pnp_eisaformat(id),
Lines 344-348 Link Here
344
341
345
				if (config->ic_nmem == ISA_NMEM) {
342
				if (config->ic_nmem == ISA_NMEM) {
346
					device_printf(parent, "too many memory ranges");
343
					device_printf(parent, "too many memory ranges\n");
347
					scanning = 0;
344
					scanning = 0;
348
					break;
345
					break;
Lines 362-379 Link Here
362
			default:
359
			default:
363
				/* Skip this resource */
360
				/* Skip this resource */
364
				device_printf(parent, "unexpected tag %d\n",
361
				device_printf(parent, "unexpected large tag %d\n",
365
					      PNP_SRES_NUM(tag));
362
					      PNP_SRES_NUM(tag));
366
			}
363
			}
367
		}
364
		}
368
	}
365
	}
369
366
	if(ncfgs == 1) {
370
	/*
367
		/* Single config without dependants */
371
	 * Some devices (e.g. network cards) don't have start
368
		(void)ISA_ADD_CONFIG(parent, dev, priorities[0], &configs[0]);
372
	 * dependant tags and only have a single configuration. If we
369
		return;
373
	 * finish parsing without seeing an end dependant tag, add the 
370
	}
374
	 * non-dependant configuration to the device.
371
	/* Cycle through dependant configs merging primary details */
375
	 */
372
	for(i = 1; i < ncfgs; i++) {
376
	if (!seenalt)
373
		int j;
377
		ISA_ADD_CONFIG(parent, dev, 1, config);
374
		config = &configs[i];
375
		for(j = 0; j < configs[0].ic_nmem; j++) {
376
			if (config->ic_nmem == ISA_NMEM) {
377
				device_printf(parent, "too many memory ranges\n");
378
				return;
379
			}
380
			config->ic_mem[config->ic_nmem] = configs[0].ic_mem[j];
381
			config->ic_nmem++;
382
		}
383
		for(j = 0; j < configs[0].ic_nport; j++) {
384
			if (config->ic_nport == ISA_NPORT) {
385
				device_printf(parent, "too many port ranges\n");
386
				return;
387
			}
388
			config->ic_port[config->ic_nport] = configs[0].ic_port[j];
389
			config->ic_nport++;
390
		}
391
		for(j = 0; j < configs[0].ic_nirq; j++) {
392
			if (config->ic_nirq == ISA_NIRQ) {
393
				device_printf(parent, "too many irq ranges\n");
394
				return;
395
			}
396
			config->ic_irqmask[config->ic_nirq] = configs[0].ic_irqmask[j];
397
			config->ic_nirq++;
398
		}
399
		for(j = 0; j < configs[0].ic_ndrq; j++) {
400
			if (config->ic_ndrq == ISA_NDRQ) {
401
				device_printf(parent, "too many drq ranges\n");
402
				return;
403
			}
404
			config->ic_drqmask[config->ic_ndrq] = configs[0].ic_drqmask[j];
405
			config->ic_ndrq++;
406
		}
407
		(void)ISA_ADD_CONFIG(parent, dev, priorities[i], &configs[i]);
408
	}
378
}
409
}
379

Return to bug 17219