Changes in kernel/arch/ia32/src/drivers/i8254.c [da1bafb:d99c1d2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/ia32/src/drivers/i8254.c
rda1bafb rd99c1d2 54 54 #include <ddi/device.h> 55 55 56 #define CLK_PORT1 ((ioport8_t *)0x40)57 #define CLK_PORT4 ((ioport8_t *)0x43)56 #define CLK_PORT1 ((ioport8_t *)0x40) 57 #define CLK_PORT4 ((ioport8_t *)0x43) 58 58 59 #define CLK_CONST 1193180 60 #define MAGIC_NUMBER 1194 61 62 #define LOOPS 150000 63 #define SHIFT 11 59 #define CLK_CONST 1193180 60 #define MAGIC_NUMBER 1194 64 61 65 62 static irq_t i8254_irq; … … 78 75 * lock. We just release it, call clock() and then reacquire it again. 79 76 */ 80 irq_spinlock_unlock(&irq->lock, false);77 spinlock_unlock(&irq->lock); 81 78 clock(); 82 irq_spinlock_lock(&irq->lock, false);79 spinlock_lock(&irq->lock); 83 80 } 84 81 … … 105 102 } 106 103 104 #define LOOPS 150000 105 #define SHIFT 11 107 106 void i8254_calibrate_delay_loop(void) 108 107 { 108 uint64_t clk1, clk2; 109 uint32_t t1, t2, o1, o2; 110 uint8_t not_ok; 111 112 109 113 /* 110 114 * One-shot timer. Count-down from 0xffff at 1193180Hz … … 114 118 pio_write_8(CLK_PORT1, 0xff); 115 119 pio_write_8(CLK_PORT1, 0xff); 116 117 uint8_t not_ok; 118 uint32_t t1; 119 uint32_t t2; 120 120 121 121 do { 122 122 /* will read both status and count */ … … 126 126 t1 |= pio_read_8(CLK_PORT1) << 8; 127 127 } while (not_ok); 128 128 129 129 asm_delay_loop(LOOPS); 130 130 131 131 pio_write_8(CLK_PORT4, 0xd2); 132 132 t2 = pio_read_8(CLK_PORT1); 133 133 t2 |= pio_read_8(CLK_PORT1) << 8; 134 134 135 135 /* 136 136 * We want to determine the overhead of the calibrating mechanism. 137 137 */ 138 138 pio_write_8(CLK_PORT4, 0xd2); 139 uint32_to1 = pio_read_8(CLK_PORT1);139 o1 = pio_read_8(CLK_PORT1); 140 140 o1 |= pio_read_8(CLK_PORT1) << 8; 141 141 142 142 asm_fake_loop(LOOPS); 143 143 144 144 pio_write_8(CLK_PORT4, 0xd2); 145 uint32_to2 = pio_read_8(CLK_PORT1);145 o2 = pio_read_8(CLK_PORT1); 146 146 o2 |= pio_read_8(CLK_PORT1) << 8; 147 147 148 148 CPU->delay_loop_const = 149 149 ((MAGIC_NUMBER * LOOPS) / 1000) / ((t1 - t2) - (o1 - o2)) + 150 150 (((MAGIC_NUMBER * LOOPS) / 1000) % ((t1 - t2) - (o1 - o2)) ? 1 : 0); 151 152 uint64_tclk1 = get_cycle();151 152 clk1 = get_cycle(); 153 153 delay(1 << SHIFT); 154 uint64_tclk2 = get_cycle();154 clk2 = get_cycle(); 155 155 156 156 CPU->frequency_mhz = (clk2 - clk1) >> SHIFT; 157 157 158 158 return; 159 159 }
Note:
See TracChangeset
for help on using the changeset viewer.