* Calculate nearest frequency supported by hardware timer. */
| 566 | * Calculate nearest frequency supported by hardware timer. |
| 567 | */ |
| 568 | static int |
| 569 | round_freq(struct eventtimer *et, int freq) |
| 570 | { |
| 571 | uint64_t div; |
| 572 | |
| 573 | if (et->et_frequency != 0) { |
| 574 | div = lmax((et->et_frequency + freq / 2) / freq, 1); |
| 575 | if (et->et_flags & ET_FLAGS_POW2DIV) |
| 576 | div = 1 << (flsl(div + div / 2) - 1); |
| 577 | freq = (et->et_frequency + div / 2) / div; |
| 578 | } |
| 579 | if (et->et_min_period > SBT_1S) |
| 580 | panic("Event timer \"%s\" doesn't support sub-second periods!", |
| 581 | et->et_name); |
| 582 | else if (et->et_min_period != 0) |
| 583 | freq = min(freq, SBT2FREQ(et->et_min_period)); |
| 584 | if (et->et_max_period < SBT_1S && et->et_max_period != 0) |
| 585 | freq = max(freq, SBT2FREQ(et->et_max_period)); |
| 586 | return (freq); |
| 587 | } |
| 588 | |
| 589 | /* |
| 590 | * Configure and start event timers (BSP part). |