ata-all.c (107449) | ata-all.c (107562) |
---|---|
1/*- 2 * Copyright (c) 1998,1999,2000,2001,2002 S�ren Schmidt <sos@FreeBSD.org> 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 --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * | 1/*- 2 * Copyright (c) 1998,1999,2000,2001,2002 S�ren Schmidt <sos@FreeBSD.org> 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 --- 11 unchanged lines hidden (view full) --- 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * |
28 * $FreeBSD: head/sys/dev/ata/ata-all.c 107449 2002-12-01 14:20:08Z thomas $ | 28 * $FreeBSD: head/sys/dev/ata/ata-all.c 107562 2002-12-03 20:20:44Z sos $ |
29 */ 30 31#include "opt_ata.h" 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/ata.h> 35#include <sys/kernel.h> 36#include <sys/conf.h> --- 45 unchanged lines hidden (view full) --- 82static void bpack(int8_t *, int8_t *, int); 83static void ata_change_mode(struct ata_device *, int); 84static u_int8_t ata_drawersensor(struct ata_device *, int, u_int8_t, u_int8_t); 85 86/* sysctl vars */ 87SYSCTL_NODE(_hw, OID_AUTO, ata, CTLFLAG_RD, 0, "ATA driver parameters"); 88 89/* global vars */ | 29 */ 30 31#include "opt_ata.h" 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/ata.h> 35#include <sys/kernel.h> 36#include <sys/conf.h> --- 45 unchanged lines hidden (view full) --- 82static void bpack(int8_t *, int8_t *, int); 83static void ata_change_mode(struct ata_device *, int); 84static u_int8_t ata_drawersensor(struct ata_device *, int, u_int8_t, u_int8_t); 85 86/* sysctl vars */ 87SYSCTL_NODE(_hw, OID_AUTO, ata, CTLFLAG_RD, 0, "ATA driver parameters"); 88 89/* global vars */ |
90struct intr_config_hook *ata_delayed_attach = NULL; |
|
90devclass_t ata_devclass; 91 92/* local vars */ | 91devclass_t ata_devclass; 92 93/* local vars */ |
93static struct intr_config_hook *ata_delayed_attach = NULL; | |
94static MALLOC_DEFINE(M_ATA, "ATA generic", "ATA driver generic layer"); 95 96/* misc defines */ 97#define DEV_ATAPIALL defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || \ 98 defined(DEV_ATAPIST) || defined(DEV_ATAPICAM) 99 100int 101ata_probe(device_t dev) --- 27 unchanged lines hidden (view full) --- 129 ch->r_bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 130 ATA_BMIOSIZE, RF_ACTIVE); 131 if (bootverbose) 132 ata_printf(ch, -1, "iobase=0x%04x altiobase=0x%04x bmaddr=0x%04x\n", 133 (int)rman_get_start(ch->r_io), 134 (int)rman_get_start(ch->r_altio), 135 (ch->r_bmio) ? (int)rman_get_start(ch->r_bmio) : 0); 136 | 94static MALLOC_DEFINE(M_ATA, "ATA generic", "ATA driver generic layer"); 95 96/* misc defines */ 97#define DEV_ATAPIALL defined(DEV_ATAPICD) || defined(DEV_ATAPIFD) || \ 98 defined(DEV_ATAPIST) || defined(DEV_ATAPICAM) 99 100int 101ata_probe(device_t dev) --- 27 unchanged lines hidden (view full) --- 129 ch->r_bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 130 ATA_BMIOSIZE, RF_ACTIVE); 131 if (bootverbose) 132 ata_printf(ch, -1, "iobase=0x%04x altiobase=0x%04x bmaddr=0x%04x\n", 133 (int)rman_get_start(ch->r_io), 134 (int)rman_get_start(ch->r_altio), 135 (ch->r_bmio) ? (int)rman_get_start(ch->r_bmio) : 0); 136 |
137 ch->lock_func(ch, ATA_LF_LOCK); |
|
137 ata_reset(ch); | 138 ata_reset(ch); |
139 ch->lock_func(ch, ATA_LF_UNLOCK); |
|
138 139 ch->device[MASTER].channel = ch; 140 ch->device[MASTER].unit = ATA_MASTER; 141 ch->device[MASTER].mode = ATA_PIO; 142 ch->device[SLAVE].channel = ch; 143 ch->device[SLAVE].unit = ATA_SLAVE; 144 ch->device[SLAVE].mode = ATA_PIO; 145 TAILQ_INIT(&ch->ata_queue); --- 35 unchanged lines hidden (view full) --- 181 } 182 183 /* 184 * do not attach devices if we are in early boot, this is done later 185 * when interrupts are enabled by a hook into the boot process. 186 * otherwise attach what the probe has found in ch->devices. 187 */ 188 if (!ata_delayed_attach) { | 140 141 ch->device[MASTER].channel = ch; 142 ch->device[MASTER].unit = ATA_MASTER; 143 ch->device[MASTER].mode = ATA_PIO; 144 ch->device[SLAVE].channel = ch; 145 ch->device[SLAVE].unit = ATA_SLAVE; 146 ch->device[SLAVE].mode = ATA_PIO; 147 TAILQ_INIT(&ch->ata_queue); --- 35 unchanged lines hidden (view full) --- 183 } 184 185 /* 186 * do not attach devices if we are in early boot, this is done later 187 * when interrupts are enabled by a hook into the boot process. 188 * otherwise attach what the probe has found in ch->devices. 189 */ 190 if (!ata_delayed_attach) { |
191 ch->lock_func(ch, ATA_LF_LOCK); |
|
189 if (ch->devices & ATA_ATA_SLAVE) 190 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATA_IDENTIFY)) 191 ch->devices &= ~ATA_ATA_SLAVE; 192 if (ch->devices & ATA_ATAPI_SLAVE) 193 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATAPI_IDENTIFY)) 194 ch->devices &= ~ATA_ATAPI_SLAVE; 195 if (ch->devices & ATA_ATA_MASTER) 196 if (ata_getparam(&ch->device[MASTER], ATA_C_ATA_IDENTIFY)) --- 11 unchanged lines hidden (view full) --- 208 if (ch->devices & ATA_ATAPI_MASTER) 209 atapi_attach(&ch->device[MASTER]); 210 if (ch->devices & ATA_ATAPI_SLAVE) 211 atapi_attach(&ch->device[SLAVE]); 212#endif 213#ifdef DEV_ATAPICAM 214 atapi_cam_attach_bus(ch); 215#endif | 192 if (ch->devices & ATA_ATA_SLAVE) 193 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATA_IDENTIFY)) 194 ch->devices &= ~ATA_ATA_SLAVE; 195 if (ch->devices & ATA_ATAPI_SLAVE) 196 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATAPI_IDENTIFY)) 197 ch->devices &= ~ATA_ATAPI_SLAVE; 198 if (ch->devices & ATA_ATA_MASTER) 199 if (ata_getparam(&ch->device[MASTER], ATA_C_ATA_IDENTIFY)) --- 11 unchanged lines hidden (view full) --- 211 if (ch->devices & ATA_ATAPI_MASTER) 212 atapi_attach(&ch->device[MASTER]); 213 if (ch->devices & ATA_ATAPI_SLAVE) 214 atapi_attach(&ch->device[SLAVE]); 215#endif 216#ifdef DEV_ATAPICAM 217 atapi_cam_attach_bus(ch); 218#endif |
219 ch->lock_func(ch, ATA_LF_UNLOCK); |
|
216 } 217 return 0; 218} 219 220int 221ata_detach(device_t dev) 222{ 223 struct ata_channel *ch; 224 int s; 225 226 if (!dev || !(ch = device_get_softc(dev)) || 227 !ch->r_io || !ch->r_altio || !ch->r_irq) 228 return ENXIO; 229 230 /* make sure channel is not busy */ | 220 } 221 return 0; 222} 223 224int 225ata_detach(device_t dev) 226{ 227 struct ata_channel *ch; 228 int s; 229 230 if (!dev || !(ch = device_get_softc(dev)) || 231 !ch->r_io || !ch->r_altio || !ch->r_irq) 232 return ENXIO; 233 234 /* make sure channel is not busy */ |
235 ch->lock_func(ch, ATA_LF_LOCK); |
|
231 ATA_SLEEPLOCK_CH(ch, ATA_CONTROL); 232 233 s = splbio(); 234#ifdef DEV_ATADISK 235 if (ch->devices & ATA_ATA_MASTER && ch->device[MASTER].driver) 236 ad_detach(&ch->device[MASTER], 1); 237 if (ch->devices & ATA_ATA_SLAVE && ch->device[SLAVE].driver) 238 ad_detach(&ch->device[SLAVE], 1); --- 30 unchanged lines hidden (view full) --- 269 bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, ch->r_bmio); 270 bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, ch->r_altio); 271 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, ch->r_io); 272 ch->r_io = NULL; 273 ch->r_altio = NULL; 274 ch->r_bmio = NULL; 275 ch->r_irq = NULL; 276 ATA_UNLOCK_CH(ch); | 236 ATA_SLEEPLOCK_CH(ch, ATA_CONTROL); 237 238 s = splbio(); 239#ifdef DEV_ATADISK 240 if (ch->devices & ATA_ATA_MASTER && ch->device[MASTER].driver) 241 ad_detach(&ch->device[MASTER], 1); 242 if (ch->devices & ATA_ATA_SLAVE && ch->device[SLAVE].driver) 243 ad_detach(&ch->device[SLAVE], 1); --- 30 unchanged lines hidden (view full) --- 274 bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, ch->r_bmio); 275 bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, ch->r_altio); 276 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, ch->r_io); 277 ch->r_io = NULL; 278 ch->r_altio = NULL; 279 ch->r_bmio = NULL; 280 ch->r_irq = NULL; 281 ATA_UNLOCK_CH(ch); |
282 ch->lock_func(ch, ATA_LF_UNLOCK); |
|
277 return 0; 278} 279 280int 281ata_resume(device_t dev) 282{ | 283 return 0; 284} 285 286int 287ata_resume(device_t dev) 288{ |
283 return ata_reinit(device_get_softc(dev)); | 289 struct ata_channel *ch; 290 int error; 291 292 if (!dev || !(ch = device_get_softc(dev))) 293 return ENXIO; 294 295 ch->lock_func(ch, ATA_LF_LOCK); 296 error = ata_reinit(ch); 297 ch->lock_func(ch, ATA_LF_UNLOCK); 298 return error; |
284} 285 286static int 287ataioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *td) 288{ 289 struct ata_cmd *iocmd = (struct ata_cmd *)addr; 290 struct ata_channel *ch; 291 device_t device = devclass_get_device(ata_devclass, iocmd->channel); --- 16 unchanged lines hidden (view full) --- 308 case ATADETACH: 309 error = ata_detach(device); 310 /* should disable channel HW on controller that can SOS XXX */ 311 return error; 312 313 case ATAREINIT: 314 if (!device || !(ch = device_get_softc(device))) 315 return ENXIO; | 299} 300 301static int 302ataioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *td) 303{ 304 struct ata_cmd *iocmd = (struct ata_cmd *)addr; 305 struct ata_channel *ch; 306 device_t device = devclass_get_device(ata_devclass, iocmd->channel); --- 16 unchanged lines hidden (view full) --- 323 case ATADETACH: 324 error = ata_detach(device); 325 /* should disable channel HW on controller that can SOS XXX */ 326 return error; 327 328 case ATAREINIT: 329 if (!device || !(ch = device_get_softc(device))) 330 return ENXIO; |
331 ch->lock_func(ch, ATA_LF_LOCK); |
|
316 ATA_SLEEPLOCK_CH(ch, ATA_ACTIVE); | 332 ATA_SLEEPLOCK_CH(ch, ATA_ACTIVE); |
317 if ((error = ata_reinit(ch))) 318 ATA_UNLOCK_CH(ch); | 333 error = ata_reinit(ch); 334 ch->lock_func(ch, ATA_LF_UNLOCK); |
319 return error; 320 321 case ATAGMODE: 322 if (!device || !(ch = device_get_softc(device))) 323 return ENXIO; 324 325 if ((iocmd->device == MASTER || iocmd->device == -1) && 326 ch->device[MASTER].driver) --- 7 unchanged lines hidden (view full) --- 334 else 335 iocmd->u.mode.mode[SLAVE] = -1; 336 return 0; 337 338 case ATASMODE: 339 if (!device || !(ch = device_get_softc(device))) 340 return ENXIO; 341 | 335 return error; 336 337 case ATAGMODE: 338 if (!device || !(ch = device_get_softc(device))) 339 return ENXIO; 340 341 if ((iocmd->device == MASTER || iocmd->device == -1) && 342 ch->device[MASTER].driver) --- 7 unchanged lines hidden (view full) --- 350 else 351 iocmd->u.mode.mode[SLAVE] = -1; 352 return 0; 353 354 case ATASMODE: 355 if (!device || !(ch = device_get_softc(device))) 356 return ENXIO; 357 |
358 ch->lock_func(ch, ATA_LF_LOCK); |
|
342 if ((iocmd->device == MASTER || iocmd->device == -1) && 343 iocmd->u.mode.mode[MASTER] >= 0 && ch->device[MASTER].param) { 344 ata_change_mode(&ch->device[MASTER],iocmd->u.mode.mode[MASTER]); 345 iocmd->u.mode.mode[MASTER] = ch->device[MASTER].mode; 346 } 347 else 348 iocmd->u.mode.mode[MASTER] = -1; 349 350 if ((iocmd->device == SLAVE || iocmd->device == -1) && 351 iocmd->u.mode.mode[SLAVE] >= 0 && ch->device[SLAVE].param) { 352 ata_change_mode(&ch->device[SLAVE], iocmd->u.mode.mode[SLAVE]); 353 iocmd->u.mode.mode[SLAVE] = ch->device[SLAVE].mode; 354 } 355 else 356 iocmd->u.mode.mode[SLAVE] = -1; | 359 if ((iocmd->device == MASTER || iocmd->device == -1) && 360 iocmd->u.mode.mode[MASTER] >= 0 && ch->device[MASTER].param) { 361 ata_change_mode(&ch->device[MASTER],iocmd->u.mode.mode[MASTER]); 362 iocmd->u.mode.mode[MASTER] = ch->device[MASTER].mode; 363 } 364 else 365 iocmd->u.mode.mode[MASTER] = -1; 366 367 if ((iocmd->device == SLAVE || iocmd->device == -1) && 368 iocmd->u.mode.mode[SLAVE] >= 0 && ch->device[SLAVE].param) { 369 ata_change_mode(&ch->device[SLAVE], iocmd->u.mode.mode[SLAVE]); 370 iocmd->u.mode.mode[SLAVE] = ch->device[SLAVE].mode; 371 } 372 else 373 iocmd->u.mode.mode[SLAVE] = -1; |
374 ch->lock_func(ch, ATA_LF_UNLOCK); |
|
357 return 0; 358 359 case ATAGPARM: 360 if (!device || !(ch = device_get_softc(device))) 361 return ENXIO; 362 363 iocmd->u.param.type[MASTER] = 364 ch->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER); --- 16 unchanged lines hidden (view full) --- 381 case ATAENCSTAT: { 382 struct ata_device *atadev; 383 u_int8_t id1, id2, cnt, div; 384 int fan, temp; 385 386 if (!device || !(ch = device_get_softc(device))) 387 return ENXIO; 388 | 375 return 0; 376 377 case ATAGPARM: 378 if (!device || !(ch = device_get_softc(device))) 379 return ENXIO; 380 381 iocmd->u.param.type[MASTER] = 382 ch->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER); --- 16 unchanged lines hidden (view full) --- 399 case ATAENCSTAT: { 400 struct ata_device *atadev; 401 u_int8_t id1, id2, cnt, div; 402 int fan, temp; 403 404 if (!device || !(ch = device_get_softc(device))) 405 return ENXIO; 406 |
407 ch->lock_func(ch, ATA_LF_LOCK); |
|
389 ATA_SLEEPLOCK_CH(ch, ATA_ACTIVE); 390 391 if (iocmd->device == SLAVE) 392 atadev = &ch->device[SLAVE]; 393 else 394 atadev = &ch->device[MASTER]; 395 396 ata_drawersensor(atadev, 1, 0x4e, 0); 397 id1 = ata_drawersensor(atadev, 0, 0x4f, 0); 398 ata_drawersensor(atadev, 1, 0x4e, 0x80); 399 id2 = ata_drawersensor(atadev, 0, 0x4f, 0); 400 if (id1 != 0xa3 || id2 != 0x5c) { 401 ATA_UNLOCK_CH(ch); | 408 ATA_SLEEPLOCK_CH(ch, ATA_ACTIVE); 409 410 if (iocmd->device == SLAVE) 411 atadev = &ch->device[SLAVE]; 412 else 413 atadev = &ch->device[MASTER]; 414 415 ata_drawersensor(atadev, 1, 0x4e, 0); 416 id1 = ata_drawersensor(atadev, 0, 0x4f, 0); 417 ata_drawersensor(atadev, 1, 0x4e, 0x80); 418 id2 = ata_drawersensor(atadev, 0, 0x4f, 0); 419 if (id1 != 0xa3 || id2 != 0x5c) { 420 ATA_UNLOCK_CH(ch); |
421 ch->lock_func(ch, ATA_LF_UNLOCK); |
|
402 return ENXIO; 403 } 404 405 div = 1 << (((ata_drawersensor(atadev, 0, 0x5d, 0)&0x20)>>3) + 406 ((ata_drawersensor(atadev, 0, 0x47, 0)&0x30)>>4) + 1); 407 cnt = ata_drawersensor(atadev, 0, 0x28, 0); 408 if (cnt == 0xff) 409 fan = 0; --- 4 unchanged lines hidden (view full) --- 414 (ata_drawersensor(atadev, 0, 0x50, 0) & 0x80 ? 5 : 0); 415 416 iocmd->u.enclosure.fan = fan; 417 iocmd->u.enclosure.temp = temp; 418 iocmd->u.enclosure.v05 = ata_drawersensor(atadev, 0, 0x23, 0) * 27; 419 iocmd->u.enclosure.v12 = ata_drawersensor(atadev, 0, 0x24, 0) * 61; 420 421 ATA_UNLOCK_CH(ch); | 422 return ENXIO; 423 } 424 425 div = 1 << (((ata_drawersensor(atadev, 0, 0x5d, 0)&0x20)>>3) + 426 ((ata_drawersensor(atadev, 0, 0x47, 0)&0x30)>>4) + 1); 427 cnt = ata_drawersensor(atadev, 0, 0x28, 0); 428 if (cnt == 0xff) 429 fan = 0; --- 4 unchanged lines hidden (view full) --- 434 (ata_drawersensor(atadev, 0, 0x50, 0) & 0x80 ? 5 : 0); 435 436 iocmd->u.enclosure.fan = fan; 437 iocmd->u.enclosure.temp = temp; 438 iocmd->u.enclosure.v05 = ata_drawersensor(atadev, 0, 0x23, 0) * 27; 439 iocmd->u.enclosure.v12 = ata_drawersensor(atadev, 0, 0x24, 0) * 61; 440 441 ATA_UNLOCK_CH(ch); |
442 ch->lock_func(ch, ATA_LF_UNLOCK); |
|
422 return 0; 423 } 424 425#ifdef DEV_ATADISK 426 case ATARAIDREBUILD: 427 return ata_raid_rebuild(iocmd->channel); 428 429 case ATARAIDCREATE: --- 98 unchanged lines hidden (view full) --- 528} 529 530static void 531ata_boot_attach(void) 532{ 533 struct ata_channel *ch; 534 int ctlr; 535 | 443 return 0; 444 } 445 446#ifdef DEV_ATADISK 447 case ATARAIDREBUILD: 448 return ata_raid_rebuild(iocmd->channel); 449 450 case ATARAIDCREATE: --- 98 unchanged lines hidden (view full) --- 549} 550 551static void 552ata_boot_attach(void) 553{ 554 struct ata_channel *ch; 555 int ctlr; 556 |
536 if (ata_delayed_attach) { 537 config_intrhook_disestablish(ata_delayed_attach); 538 free(ata_delayed_attach, M_TEMP); 539 ata_delayed_attach = NULL; 540 } 541 | |
542 /* 543 * run through all ata devices and look for real ATA & ATAPI devices 544 * using the hints we found in the early probe, this avoids some of 545 * the delays probing of non-exsistent devices can cause. 546 */ 547 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { 548 if (!(ch = devclass_get_softc(ata_devclass, ctlr))) 549 continue; | 557 /* 558 * run through all ata devices and look for real ATA & ATAPI devices 559 * using the hints we found in the early probe, this avoids some of 560 * the delays probing of non-exsistent devices can cause. 561 */ 562 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { 563 if (!(ch = devclass_get_softc(ata_devclass, ctlr))) 564 continue; |
565 ch->lock_func(ch, ATA_LF_LOCK); |
|
550 if (ch->devices & ATA_ATA_SLAVE) 551 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATA_IDENTIFY)) 552 ch->devices &= ~ATA_ATA_SLAVE; 553 if (ch->devices & ATA_ATAPI_SLAVE) 554 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATAPI_IDENTIFY)) 555 ch->devices &= ~ATA_ATAPI_SLAVE; 556 if (ch->devices & ATA_ATA_MASTER) 557 if (ata_getparam(&ch->device[MASTER], ATA_C_ATA_IDENTIFY)) 558 ch->devices &= ~ATA_ATA_MASTER; 559 if (ch->devices & ATA_ATAPI_MASTER) 560 if (ata_getparam(&ch->device[MASTER], ATA_C_ATAPI_IDENTIFY)) 561 ch->devices &= ~ATA_ATAPI_MASTER; | 566 if (ch->devices & ATA_ATA_SLAVE) 567 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATA_IDENTIFY)) 568 ch->devices &= ~ATA_ATA_SLAVE; 569 if (ch->devices & ATA_ATAPI_SLAVE) 570 if (ata_getparam(&ch->device[SLAVE], ATA_C_ATAPI_IDENTIFY)) 571 ch->devices &= ~ATA_ATAPI_SLAVE; 572 if (ch->devices & ATA_ATA_MASTER) 573 if (ata_getparam(&ch->device[MASTER], ATA_C_ATA_IDENTIFY)) 574 ch->devices &= ~ATA_ATA_MASTER; 575 if (ch->devices & ATA_ATAPI_MASTER) 576 if (ata_getparam(&ch->device[MASTER], ATA_C_ATAPI_IDENTIFY)) 577 ch->devices &= ~ATA_ATAPI_MASTER; |
578 ch->lock_func(ch, ATA_LF_UNLOCK); |
|
562 } | 579 } |
563 | |
564#ifdef DEV_ATADISK 565 /* now we know whats there, do the real attach, first the ATA disks */ 566 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { 567 if (!(ch = devclass_get_softc(ata_devclass, ctlr))) 568 continue; | 580#ifdef DEV_ATADISK 581 /* now we know whats there, do the real attach, first the ATA disks */ 582 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { 583 if (!(ch = devclass_get_softc(ata_devclass, ctlr))) 584 continue; |
585 ch->lock_func(ch, ATA_LF_LOCK); |
|
569 if (ch->devices & ATA_ATA_MASTER) 570 ad_attach(&ch->device[MASTER]); 571 if (ch->devices & ATA_ATA_SLAVE) 572 ad_attach(&ch->device[SLAVE]); | 586 if (ch->devices & ATA_ATA_MASTER) 587 ad_attach(&ch->device[MASTER]); 588 if (ch->devices & ATA_ATA_SLAVE) 589 ad_attach(&ch->device[SLAVE]); |
590 ch->lock_func(ch, ATA_LF_UNLOCK); |
|
573 } | 591 } |
574 ata_raid_attach(); | |
575#endif 576 /* then the atapi devices */ 577 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { 578 if (!(ch = devclass_get_softc(ata_devclass, ctlr))) 579 continue; | 592#endif 593 /* then the atapi devices */ 594 for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) { 595 if (!(ch = devclass_get_softc(ata_devclass, ctlr))) 596 continue; |
597 ch->lock_func(ch, ATA_LF_LOCK); |
|
580#if DEV_ATAPIALL 581 if (ch->devices & ATA_ATAPI_MASTER) 582 atapi_attach(&ch->device[MASTER]); 583 if (ch->devices & ATA_ATAPI_SLAVE) 584 atapi_attach(&ch->device[SLAVE]); 585#endif 586#ifdef DEV_ATAPICAM 587 atapi_cam_attach_bus(ch); 588#endif | 598#if DEV_ATAPIALL 599 if (ch->devices & ATA_ATAPI_MASTER) 600 atapi_attach(&ch->device[MASTER]); 601 if (ch->devices & ATA_ATAPI_SLAVE) 602 atapi_attach(&ch->device[SLAVE]); 603#endif 604#ifdef DEV_ATAPICAM 605 atapi_cam_attach_bus(ch); 606#endif |
607 ch->lock_func(ch, ATA_LF_UNLOCK); |
|
589 } | 608 } |
609 if (ata_delayed_attach) { 610 config_intrhook_disestablish(ata_delayed_attach); 611 free(ata_delayed_attach, M_TEMP); 612 ata_delayed_attach = NULL; 613 } 614 ata_raid_attach(); |
|
590} 591 592static void 593ata_intr(void *data) 594{ 595 struct ata_channel *ch = (struct ata_channel *)data; 596 /* 597 * on PCI systems we might share an interrupt line with another 598 * device or our twin ATA channel, so call ch->intr_func to figure 599 * out if it is really an interrupt we should process here 600 */ | 615} 616 617static void 618ata_intr(void *data) 619{ 620 struct ata_channel *ch = (struct ata_channel *)data; 621 /* 622 * on PCI systems we might share an interrupt line with another 623 * device or our twin ATA channel, so call ch->intr_func to figure 624 * out if it is really an interrupt we should process here 625 */ |
601 if (ch->intr_func && ch->intr_func(ch)) | 626 if (!ch->intr_func(ch)) |
602 return; 603 604 /* if drive is busy it didn't interrupt */ 605 if (ATA_INB(ch->r_altio, ATA_ALTSTAT) & ATA_S_BUSY) { 606 DELAY(100); 607 if (!(ATA_INB(ch->r_altio, ATA_ALTSTAT) & ATA_S_DRQ)) 608 return; 609 } --- 23 unchanged lines hidden (view full) --- 633 wakeup((caddr_t)ch); 634 } 635 636 if (ch->active & ATA_CONTROL) { 637 ATA_FORCELOCK_CH(ch, ATA_CONTROL); 638 return; 639 } 640 | 627 return; 628 629 /* if drive is busy it didn't interrupt */ 630 if (ATA_INB(ch->r_altio, ATA_ALTSTAT) & ATA_S_BUSY) { 631 DELAY(100); 632 if (!(ATA_INB(ch->r_altio, ATA_ALTSTAT) & ATA_S_DRQ)) 633 return; 634 } --- 23 unchanged lines hidden (view full) --- 658 wakeup((caddr_t)ch); 659 } 660 661 if (ch->active & ATA_CONTROL) { 662 ATA_FORCELOCK_CH(ch, ATA_CONTROL); 663 return; 664 } 665 |
666 if (ch->active & ATA_WAIT_INTR) { 667 ATA_UNLOCK_CH(ch); 668 return; 669 } 670 |
|
641 if ((ch->flags & ATA_QUEUED) && 642 ATA_INB(ch->r_altio, ATA_ALTSTAT) & ATA_S_SERVICE) { 643 ATA_FORCELOCK_CH(ch, ATA_ACTIVE); 644 if (ata_service(ch) == ATA_OP_CONTINUES) 645 return; 646 } | 671 if ((ch->flags & ATA_QUEUED) && 672 ATA_INB(ch->r_altio, ATA_ALTSTAT) & ATA_S_SERVICE) { 673 ATA_FORCELOCK_CH(ch, ATA_ACTIVE); 674 if (ata_service(ch) == ATA_OP_CONTINUES) 675 return; 676 } |
647 ATA_UNLOCK_CH(ch); | |
648 ch->running = NULL; | 677 ch->running = NULL; |
678 ATA_UNLOCK_CH(ch); 679 ch->lock_func(ch, ATA_LF_UNLOCK); |
|
649 ata_start(ch); 650 return; 651} 652 653void 654ata_start(struct ata_channel *ch) 655{ 656#ifdef DEV_ATADISK 657 struct ad_request *ad_request; 658#endif 659#if DEV_ATAPIALL 660 struct atapi_request *atapi_request; 661#endif 662 int s; 663 | 680 ata_start(ch); 681 return; 682} 683 684void 685ata_start(struct ata_channel *ch) 686{ 687#ifdef DEV_ATADISK 688 struct ad_request *ad_request; 689#endif 690#if DEV_ATAPIALL 691 struct atapi_request *atapi_request; 692#endif 693 int s; 694 |
695 ch->lock_func(ch, ATA_LF_LOCK); |
|
664 if (!ATA_LOCK_CH(ch, ATA_ACTIVE)) 665 return; 666 667 s = splbio(); 668#ifdef DEV_ATADISK 669 /* find & call the responsible driver if anything on the ATA queue */ 670 if (TAILQ_EMPTY(&ch->ata_queue)) { 671 if (ch->devices & (ATA_ATA_MASTER) && ch->device[MASTER].driver) --- 26 unchanged lines hidden (view full) --- 698 ch->running = atapi_request; 699 if (atapi_transfer(atapi_request) == ATA_OP_CONTINUES) { 700 splx(s); 701 return; 702 } 703 } 704#endif 705 ATA_UNLOCK_CH(ch); | 696 if (!ATA_LOCK_CH(ch, ATA_ACTIVE)) 697 return; 698 699 s = splbio(); 700#ifdef DEV_ATADISK 701 /* find & call the responsible driver if anything on the ATA queue */ 702 if (TAILQ_EMPTY(&ch->ata_queue)) { 703 if (ch->devices & (ATA_ATA_MASTER) && ch->device[MASTER].driver) --- 26 unchanged lines hidden (view full) --- 730 ch->running = atapi_request; 731 if (atapi_transfer(atapi_request) == ATA_OP_CONTINUES) { 732 splx(s); 733 return; 734 } 735 } 736#endif 737 ATA_UNLOCK_CH(ch); |
738 ch->lock_func(ch, ATA_LF_UNLOCK); |
|
706 splx(s); 707} 708 709void 710ata_reset(struct ata_channel *ch) 711{ 712 u_int8_t lsb, msb, ostat0, ostat1; 713 u_int8_t stat0 = 0, stat1 = 0; --- 122 unchanged lines hidden (view full) --- 836 ata_printf(ch, -1, "devices=%02x\n", ch->devices); 837} 838 839int 840ata_reinit(struct ata_channel *ch) 841{ 842 int devices, misdev, newdev; 843 | 739 splx(s); 740} 741 742void 743ata_reset(struct ata_channel *ch) 744{ 745 u_int8_t lsb, msb, ostat0, ostat1; 746 u_int8_t stat0 = 0, stat1 = 0; --- 122 unchanged lines hidden (view full) --- 869 ata_printf(ch, -1, "devices=%02x\n", ch->devices); 870} 871 872int 873ata_reinit(struct ata_channel *ch) 874{ 875 int devices, misdev, newdev; 876 |
844 if (!ch->r_io || !ch->r_altio || !ch->r_irq) | 877 ATA_FORCELOCK_CH(ch, ATA_CONTROL); 878 879 if (!ch->r_io || !ch->r_altio || !ch->r_irq) { 880 ATA_UNLOCK_CH(ch); |
845 return ENXIO; | 881 return ENXIO; |
882 } |
|
846 | 883 |
847 ATA_FORCELOCK_CH(ch, ATA_CONTROL); | |
848 ch->running = NULL; 849 devices = ch->devices; 850 ata_printf(ch, -1, "resetting devices ..\n"); 851 ata_reset(ch); 852 853 if ((misdev = devices & ~ch->devices)) { 854#ifdef DEV_ATADISK 855 if (misdev & ATA_ATA_MASTER && ch->device[MASTER].driver) --- 402 unchanged lines hidden (view full) --- 1258 pmode = (mode & ATA_MODE_MASK) - ATA_PIO0; 1259 umode = -1; 1260 wmode = -1; 1261 } 1262 1263 ATA_SLEEPLOCK_CH(atadev->channel, ATA_ACTIVE); 1264 ata_dmainit(atadev, pmode, wmode, umode); 1265 ATA_UNLOCK_CH(atadev->channel); | 884 ch->running = NULL; 885 devices = ch->devices; 886 ata_printf(ch, -1, "resetting devices ..\n"); 887 ata_reset(ch); 888 889 if ((misdev = devices & ~ch->devices)) { 890#ifdef DEV_ATADISK 891 if (misdev & ATA_ATA_MASTER && ch->device[MASTER].driver) --- 402 unchanged lines hidden (view full) --- 1294 pmode = (mode & ATA_MODE_MASK) - ATA_PIO0; 1295 umode = -1; 1296 wmode = -1; 1297 } 1298 1299 ATA_SLEEPLOCK_CH(atadev->channel, ATA_ACTIVE); 1300 ata_dmainit(atadev, pmode, wmode, umode); 1301 ATA_UNLOCK_CH(atadev->channel); |
1266 ata_start(atadev->channel); /* XXX SOS */ | 1302 ata_start(atadev->channel); |
1267} 1268 1269int 1270ata_printf(struct ata_channel *ch, int device, const char * fmt, ...) 1271{ 1272 va_list ap; 1273 int ret; 1274 --- 206 unchanged lines hidden --- | 1303} 1304 1305int 1306ata_printf(struct ata_channel *ch, int device, const char * fmt, ...) 1307{ 1308 va_list ap; 1309 int ret; 1310 --- 206 unchanged lines hidden --- |