ppbconf.c (33181) | ppbconf.c (38061) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 1997 Nicolas Souchu | 2 * Copyright (c) 1997, 1998 Nicolas Souchu |
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 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 21 unchanged lines hidden (view full) --- 32#include <sys/malloc.h> 33 34#include <vm/vm.h> 35#include <vm/pmap.h> 36 37#include <dev/ppbus/ppbconf.h> 38#include <dev/ppbus/ppb_1284.h> 39 | 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 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 21 unchanged lines hidden (view full) --- 32#include <sys/malloc.h> 33 34#include <vm/vm.h> 35#include <vm/pmap.h> 36 37#include <dev/ppbus/ppbconf.h> 38#include <dev/ppbus/ppb_1284.h> 39 |
40static LIST_HEAD(, ppb_data) ppbdata; /* list of existing ppbus */ | 40LIST_HEAD(, ppb_data) ppbdata; /* list of existing ppbus */ |
41 42/* 43 * Add a null driver so that the linker set always exists. 44 */ 45 46static struct ppb_driver nulldriver = { 47 NULL, NULL, "null" 48}; 49DATA_SET(ppbdriver_set, nulldriver); 50 51 52/* 53 * ppb_alloc_bus() 54 * 55 * Allocate area to store the ppbus description. | 41 42/* 43 * Add a null driver so that the linker set always exists. 44 */ 45 46static struct ppb_driver nulldriver = { 47 NULL, NULL, "null" 48}; 49DATA_SET(ppbdriver_set, nulldriver); 50 51 52/* 53 * ppb_alloc_bus() 54 * 55 * Allocate area to store the ppbus description. |
56 * This function is called by ppcattach(). | |
57 */ 58struct ppb_data * 59ppb_alloc_bus(void) 60{ 61 struct ppb_data *ppb; 62 static int ppbdata_initted = 0; /* done-init flag */ 63 64 ppb = (struct ppb_data *) malloc(sizeof(struct ppb_data), --- 67 unchanged lines hidden (view full) --- 132 * 133 * Returns the class id. of the peripherial, -1 otherwise 134 */ 135static int 136ppb_pnp_detect(struct ppb_data *ppb) 137{ 138 char *token, *q, *class = 0; 139 int i, len, error; | 56 */ 57struct ppb_data * 58ppb_alloc_bus(void) 59{ 60 struct ppb_data *ppb; 61 static int ppbdata_initted = 0; /* done-init flag */ 62 63 ppb = (struct ppb_data *) malloc(sizeof(struct ppb_data), --- 67 unchanged lines hidden (view full) --- 131 * 132 * Returns the class id. of the peripherial, -1 otherwise 133 */ 134static int 135ppb_pnp_detect(struct ppb_data *ppb) 136{ 137 char *token, *q, *class = 0; 138 int i, len, error; |
139 int class_id = -1; |
|
140 char str[PPB_PnP_STRING_SIZE+1]; | 140 char str[PPB_PnP_STRING_SIZE+1]; |
141 | |
142 struct ppb_device pnpdev; /* temporary device to perform I/O */ 143 144 /* initialize the pnpdev structure for future use */ 145 bzero(&pnpdev, sizeof(pnpdev)); 146 147 pnpdev.ppb = ppb; 148 | 141 struct ppb_device pnpdev; /* temporary device to perform I/O */ 142 143 /* initialize the pnpdev structure for future use */ 144 bzero(&pnpdev, sizeof(pnpdev)); 145 146 pnpdev.ppb = ppb; 147 |
149#ifdef PnP_DEBUG 150 printf("ppb: <PnP> probing PnP devices on ppbus%d...\n", 151 ppb->ppb_link->adapter_unit); 152#endif | 148 if (bootverbose) 149 printf("ppb: <PnP> probing devices on ppbus %d...\n", 150 ppb->ppb_link->adapter_unit); |
153 | 151 |
152 if (ppb_request_bus(&pnpdev, PPB_DONTWAIT)) { 153 if (bootverbose) 154 printf("ppb: <PnP> cannot allocate ppbus!\n"); 155 return (-1); 156 } 157 |
|
154 ppb_wctr(&pnpdev, nINIT | SELECTIN); 155 156 /* select NIBBLE_1284_REQUEST_ID mode */ 157 if ((error = nibble_1284_mode(&pnpdev, NIBBLE_1284_REQUEST_ID))) { | 158 ppb_wctr(&pnpdev, nINIT | SELECTIN); 159 160 /* select NIBBLE_1284_REQUEST_ID mode */ 161 if ((error = nibble_1284_mode(&pnpdev, NIBBLE_1284_REQUEST_ID))) { |
158#ifdef PnP_DEBUG 159 printf("ppb: 160#endif 161 return (-1); | 162 if (bootverbose) 163 printf("ppb: <PnP> nibble_1284_mode()=%d\n", error); 164 goto end_detect; |
162 } 163 164 len = 0; 165 for (q = str; !(ppb_rstr(&pnpdev) & ERROR); q++) { 166 if ((error = nibble_1284_inbyte(&pnpdev, q))) { | 165 } 166 167 len = 0; 168 for (q = str; !(ppb_rstr(&pnpdev) & ERROR); q++) { 169 if ((error = nibble_1284_inbyte(&pnpdev, q))) { |
167#ifdef PnP_DEBUG 168 printf("ppb: <PnP> nibble_1284_inbyte()=%d\n", error); 169#endif 170 return (-1); | 170 if (bootverbose) 171 printf("ppb: <PnP> nibble_1284_inbyte()=%d\n", 172 error); 173 goto end_detect; |
171 } 172 if (len++ >= PPB_PnP_STRING_SIZE) { 173 printf("ppb: <PnP> not space left!\n"); | 174 } 175 if (len++ >= PPB_PnP_STRING_SIZE) { 176 printf("ppb: <PnP> not space left!\n"); |
174 return (-1); | 177 goto end_detect; |
175 } 176 } 177 *q = '\0'; 178 179 nibble_1284_sync(&pnpdev); 180 | 178 } 179 } 180 *q = '\0'; 181 182 nibble_1284_sync(&pnpdev); 183 |
181#ifdef PnP_DEBUG 182 printf("ppb: 183 for (i = 0; i < len; i++) 184 printf("0x%x ", str[i]); 185 printf("\n"); 186#endif | 184 if (bootverbose) { 185 printf("ppb: <PnP> %d characters: ", len); 186 for (i = 0; i < len; i++) 187 printf("0x%x ", str[i]); 188 printf("\n"); 189 } |
187 188 /* replace ';' characters by '\0' */ 189 for (i = 0; i < len; i++) 190 str[i] = (str[i] == ';') ? '\0' : str[i]; 191 192 if ((token = search_token(str, len, "MFG")) != NULL) 193 printf("ppbus%d: <%s", ppb->ppb_link->adapter_unit, 194 search_token(token, UNKNOWN_LENGTH, ":") + 1); --- 26 unchanged lines hidden (view full) --- 221 search_token(token, UNKNOWN_LENGTH, ":") + 1); 222 223 printf("\n"); 224 225 if (class) 226 /* identify class ident */ 227 for (i = 0; pnp_tokens[i] != NULL; i++) { 228 if (search_token(class, len, pnp_tokens[i]) != NULL) { | 190 191 /* replace ';' characters by '\0' */ 192 for (i = 0; i < len; i++) 193 str[i] = (str[i] == ';') ? '\0' : str[i]; 194 195 if ((token = search_token(str, len, "MFG")) != NULL) 196 printf("ppbus%d: <%s", ppb->ppb_link->adapter_unit, 197 search_token(token, UNKNOWN_LENGTH, ":") + 1); --- 26 unchanged lines hidden (view full) --- 224 search_token(token, UNKNOWN_LENGTH, ":") + 1); 225 226 printf("\n"); 227 228 if (class) 229 /* identify class ident */ 230 for (i = 0; pnp_tokens[i] != NULL; i++) { 231 if (search_token(class, len, pnp_tokens[i]) != NULL) { |
229 return (i); 230 break; | 232 class_id = i; 233 goto end_detect; |
231 } 232 } 233 | 234 } 235 } 236 |
234 return (PPB_PnP_UNKNOWN); | 237 class_id = PPB_PnP_UNKNOWN; 238 239end_detect: 240 ppb_release_bus(&pnpdev); 241 return (class_id); |
235} 236 237/* 238 * ppb_attachdevs() 239 * 240 * Called by ppcattach(), this function probes the ppbus and 241 * attaches found devices. 242 */ --- 57 unchanged lines hidden (view full) --- 300 for (ppb = ppbdata.lh_first; ppb; ppb = ppb->ppb_chain.le_next) 301 if (ppb->ppb_link->base == base_port) 302 break; 303 304 return (ppb); 305} 306 307/* | 242} 243 244/* 245 * ppb_attachdevs() 246 * 247 * Called by ppcattach(), this function probes the ppbus and 248 * attaches found devices. 249 */ --- 57 unchanged lines hidden (view full) --- 307 for (ppb = ppbdata.lh_first; ppb; ppb = ppb->ppb_chain.le_next) 308 if (ppb->ppb_link->base == base_port) 309 break; 310 311 return (ppb); 312} 313 314/* |
315 * ppb_lookup_link() 316 * 317 * Get ppb_data structure pointer according to the unit value 318 * of the corresponding link structure 319 */ 320struct ppb_data * 321ppb_lookup_link(int unit) 322{ 323 struct ppb_data *ppb; 324 325 for (ppb = ppbdata.lh_first; ppb; ppb = ppb->ppb_chain.le_next) 326 if (ppb->ppb_link->adapter_unit == unit) 327 break; 328 329 return (ppb); 330} 331 332/* |
|
308 * ppb_attach_device() 309 * 310 * Called by loadable kernel modules to add a device 311 */ 312int 313ppb_attach_device(struct ppb_device *dev) 314{ 315 struct ppb_data *ppb = dev->ppb; --- 49 unchanged lines hidden (view full) --- 365 default: 366 return (EWOULDBLOCK); 367 break; 368 } 369 370 } else { 371 ppb->ppb_owner = dev; 372 | 333 * ppb_attach_device() 334 * 335 * Called by loadable kernel modules to add a device 336 */ 337int 338ppb_attach_device(struct ppb_device *dev) 339{ 340 struct ppb_data *ppb = dev->ppb; --- 49 unchanged lines hidden (view full) --- 390 default: 391 return (EWOULDBLOCK); 392 break; 393 } 394 395 } else { 396 ppb->ppb_owner = dev; 397 |
398 /* restore the context of the device 399 * The first time, ctx.valid is certainly false 400 * then do not change anything. This is usefull for 401 * drivers that do not set there operating mode 402 * during attachement 403 */ 404 if (dev->ctx.valid) 405 ppb_set_mode(dev, dev->ctx.mode); 406 |
|
373 splx(s); 374 return (0); 375 } 376 } 377 378 return (error); 379} 380 --- 12 unchanged lines hidden (view full) --- 393 if (ppb->ppb_owner != dev) { 394 splx(s); 395 return (EACCES); 396 } 397 398 ppb->ppb_owner = 0; 399 splx(s); 400 | 407 splx(s); 408 return (0); 409 } 410 } 411 412 return (error); 413} 414 --- 12 unchanged lines hidden (view full) --- 427 if (ppb->ppb_owner != dev) { 428 splx(s); 429 return (EACCES); 430 } 431 432 ppb->ppb_owner = 0; 433 splx(s); 434 |
435 /* save the context of the device */ 436 dev->ctx.mode = ppb_get_mode(dev); 437 438 /* ok, now the context of the device is valid */ 439 dev->ctx.valid = 1; 440 |
|
401 /* wakeup waiting processes */ 402 wakeup(ppb); 403 404 return (0); 405} | 441 /* wakeup waiting processes */ 442 wakeup(ppb); 443 444 return (0); 445} |