| 554 | } |
| 555 | |
| 556 | static int |
| 557 | attimer_attach(device_t dev) |
| 558 | { |
| 559 | struct attimer_softc *sc; |
| 560 | rman_res_t s; |
| 561 | int i; |
| 562 | |
| 563 | attimer_sc = sc = device_get_softc(dev); |
| 564 | bzero(sc, sizeof(struct attimer_softc)); |
| 565 | if (!(sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, |
| 566 | &sc->port_rid, IO_TIMER1, IO_TIMER1 + 3, 4, RF_ACTIVE))) |
| 567 | device_printf(dev,"Warning: Couldn't map I/O.\n"); |
| 568 | i8254_intsrc = intr_lookup_source(0); |
| 569 | if (i8254_intsrc != NULL) |
| 570 | i8254_pending = i8254_intsrc->is_pic->pic_source_pending; |
| 571 | resource_int_value(device_get_name(dev), device_get_unit(dev), |
| 572 | "timecounter", &i8254_timecounter); |
| 573 | set_i8254_freq(MODE_STOP, 0); |
| 574 | if (i8254_timecounter) { |
| 575 | sc->tc.tc_get_timecount = i8254_get_timecount; |
| 576 | sc->tc.tc_counter_mask = 0xffff; |
| 577 | sc->tc.tc_frequency = i8254_freq; |
| 578 | sc->tc.tc_name = "i8254"; |
| 579 | sc->tc.tc_quality = 0; |
| 580 | sc->tc.tc_priv = dev; |
| 581 | tc_init(&sc->tc); |
| 582 | } |
| 583 | if (resource_int_value(device_get_name(dev), device_get_unit(dev), |
| 584 | "clock", &i) != 0 || i != 0) { |
| 585 | sc->intr_rid = 0; |
| 586 | while (bus_get_resource(dev, SYS_RES_IRQ, sc->intr_rid, |
| 587 | &s, NULL) == 0 && s != 0) |
| 588 | sc->intr_rid++; |
| 589 | if (!(sc->intr_res = bus_alloc_resource(dev, SYS_RES_IRQ, |
| 590 | &sc->intr_rid, 0, 0, 1, RF_ACTIVE))) { |
| 591 | device_printf(dev,"Can't map interrupt.\n"); |
| 592 | return (0); |
| 593 | } |
| 594 | /* Dirty hack, to make bus_setup_intr to not enable source. */ |
| 595 | i8254_intsrc->is_handlers++; |
| 596 | if ((bus_setup_intr(dev, sc->intr_res, |
| 597 | INTR_MPSAFE | INTR_TYPE_CLK, |
| 598 | (driver_filter_t *)clkintr, NULL, |
| 599 | sc, &sc->intr_handler))) { |
| 600 | device_printf(dev, "Can't setup interrupt.\n"); |
| 601 | i8254_intsrc->is_handlers--; |
| 602 | return (0); |
| 603 | } |
| 604 | i8254_intsrc->is_handlers--; |
| 605 | i8254_intsrc->is_pic->pic_enable_intr(i8254_intsrc); |
| 606 | sc->et.et_name = "i8254"; |
| 607 | sc->et.et_flags = ET_FLAGS_PERIODIC; |
| 608 | if (!i8254_timecounter) |
| 609 | sc->et.et_flags |= ET_FLAGS_ONESHOT; |
| 610 | sc->et.et_quality = 100; |
| 611 | sc->et.et_frequency = i8254_freq; |
| 612 | sc->et.et_min_period = (0x0002LLU << 32) / i8254_freq; |
| 613 | sc->et.et_max_period = (0xfffeLLU << 32) / i8254_freq; |
nothing calls this directly
no test coverage detected