Changes in kernel/arch/ia32/src/drivers/i8254.c [d99c1d2:da1bafb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/ia32/src/drivers/i8254.c
rd99c1d2 rda1bafb 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 59 #define CLK_CONST 1193180 60 #define MAGIC_NUMBER 1194 61 62 #define LOOPS 150000 63 #define SHIFT 11 61 64 62 65 static irq_t i8254_irq; … … 75 78 * lock. We just release it, call clock() and then reacquire it again. 76 79 */ 77 spinlock_unlock(&irq->lock);80 irq_spinlock_unlock(&irq->lock, false); 78 81 clock(); 79 spinlock_lock(&irq->lock);82 irq_spinlock_lock(&irq->lock, false); 80 83 } 81 84 … … 102 105 } 103 106 104 #define LOOPS 150000105 #define SHIFT 11106 107 void i8254_calibrate_delay_loop(void) 107 108 { 108 uint64_t clk1, clk2;109 uint32_t t1, t2, o1, o2;110 uint8_t not_ok;111 112 113 109 /* 114 110 * One-shot timer. Count-down from 0xffff at 1193180Hz … … 118 114 pio_write_8(CLK_PORT1, 0xff); 119 115 pio_write_8(CLK_PORT1, 0xff); 120 116 117 uint8_t not_ok; 118 uint32_t t1; 119 uint32_t t2; 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 o1 = pio_read_8(CLK_PORT1);139 uint32_t 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 o2 = pio_read_8(CLK_PORT1);145 uint32_t 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 clk1 = get_cycle();151 152 uint64_t clk1 = get_cycle(); 153 153 delay(1 << SHIFT); 154 clk2 = get_cycle();154 uint64_t 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.