Quellcode durchsuchen

Merge branch 'xl0-timer'

tags/v0.9.4
Michael Brown vor 16 Jahren
Ursprung
Commit
3e781eb87f
70 geänderte Dateien mit 412 neuen und 398 gelöschten Zeilen
  1. 1
    0
      src/arch/i386/Makefile
  2. 53
    160
      src/arch/i386/core/i386_timer.c
  3. 12
    0
      src/arch/i386/core/nap.c
  4. 57
    0
      src/arch/i386/drivers/timer_bios.c
  5. 69
    0
      src/arch/i386/drivers/timer_rdtsc.c
  6. 0
    55
      src/arch/i386/firmware/pcbios/bios.c
  7. 3
    4
      src/arch/i386/firmware/pcbios/gateA20.c
  8. 3
    0
      src/arch/i386/include/bits/errfile.h
  9. 8
    0
      src/arch/i386/include/bits/timer2.h
  10. 0
    12
      src/arch/i386/include/latch.h
  11. 10
    0
      src/config.h
  12. 11
    0
      src/core/config.c
  13. 1
    1
      src/core/getkey.c
  14. 1
    13
      src/core/misc.c
  15. 1
    1
      src/core/random.c
  16. 1
    1
      src/core/serial.c
  17. 88
    15
      src/core/timer.c
  18. 0
    1
      src/drivers/bitbash/bitbash.c
  19. 1
    1
      src/drivers/bitbash/i2c_bit.c
  20. 1
    1
      src/drivers/bitbash/spi_bit.c
  21. 1
    1
      src/drivers/bus/eisa.c
  22. 1
    1
      src/drivers/bus/isapnp.c
  23. 0
    1
      src/drivers/bus/mca.c
  24. 0
    1
      src/drivers/infiniband/arbel.c
  25. 0
    1
      src/drivers/infiniband/hermon.c
  26. 1
    1
      src/drivers/net/3c509.c
  27. 0
    1
      src/drivers/net/3c515.c
  28. 0
    1
      src/drivers/net/3c595.c
  29. 0
    1
      src/drivers/net/3c5x9.c
  30. 4
    3
      src/drivers/net/3c90x.c
  31. 0
    1
      src/drivers/net/amd8111e.c
  32. 0
    1
      src/drivers/net/bnx2.c
  33. 0
    1
      src/drivers/net/dmfe.c
  34. 0
    1
      src/drivers/net/e1000/e1000.h
  35. 1
    1
      src/drivers/net/e1000/e1000_osdep.h
  36. 0
    1
      src/drivers/net/eepro.c
  37. 8
    5
      src/drivers/net/eepro100.c
  38. 9
    7
      src/drivers/net/epic100.c
  39. 0
    1
      src/drivers/net/etherfabric.c
  40. 0
    1
      src/drivers/net/forcedeth.c
  41. 0
    1
      src/drivers/net/ipoib.c
  42. 0
    1
      src/drivers/net/mlx_ipoib/mt23108_imp.c
  43. 0
    1
      src/drivers/net/mlx_ipoib/mt25218_imp.c
  44. 1
    1
      src/drivers/net/mtnic.c
  45. 1
    1
      src/drivers/net/natsemi.c
  46. 0
    1
      src/drivers/net/pcnet32.c
  47. 0
    1
      src/drivers/net/prism2.c
  48. 0
    1
      src/drivers/net/r8169.c
  49. 1
    1
      src/drivers/net/rtl8139.c
  50. 0
    1
      src/drivers/net/sis900.c
  51. 0
    1
      src/drivers/net/smc9000.c
  52. 0
    1
      src/drivers/net/sundance.c
  53. 0
    1
      src/drivers/net/tg3.c
  54. 0
    1
      src/drivers/net/tlan.c
  55. 12
    9
      src/drivers/net/via-rhine.c
  56. 0
    2
      src/drivers/net/via-velocity.h
  57. 4
    5
      src/drivers/net/w89c840.c
  58. 1
    1
      src/drivers/nvs/spi.c
  59. 1
    1
      src/drivers/nvs/threewire.c
  60. 1
    1
      src/hci/mucurses/kb.c
  61. 1
    1
      src/hci/shell_banner.c
  62. 1
    1
      src/include/etherboot.h
  63. 0
    1
      src/include/gpxe/dhcp.h
  64. 0
    1
      src/include/gpxe/tcp.h
  65. 32
    0
      src/include/gpxe/timer.h
  66. 0
    61
      src/include/timer.h
  67. 7
    1
      src/include/unistd.h
  68. 1
    1
      src/net/retry.c
  69. 1
    1
      src/net/tcp.c
  70. 1
    0
      src/net/udp/dhcp.c

+ 1
- 0
src/arch/i386/Makefile Datei anzeigen

@@ -7,6 +7,7 @@ ISOLINUX_BIN	= /usr/lib/syslinux/isolinux.bin
7 7
 SRCDIRS		+= arch/i386/core arch/i386/transitions arch/i386/prefix
8 8
 SRCDIRS		+= arch/i386/firmware/pcbios
9 9
 SRCDIRS		+= arch/i386/image
10
+SRCDIRS		+= arch/i386/drivers
10 11
 SRCDIRS		+= arch/i386/drivers/bus
11 12
 SRCDIRS		+= arch/i386/drivers/net
12 13
 SRCDIRS		+= arch/i386/drivers/disk

+ 53
- 160
src/arch/i386/core/i386_timer.c Datei anzeigen

@@ -1,18 +1,58 @@
1
-/* A couple of routines to implement a low-overhead timer for drivers */
2
-
3
- /*
1
+/*
2
+ * arch/i386/core/i386_timer.c
3
+ *
4
+ * Use the "System Timer 2" to implement the udelay callback in
5
+ * the BIOS timer driver. Also used to calibrate the clock rate
6
+ * in the RTDSC timer driver.
7
+ * 
4 8
  * This program is free software; you can redistribute it and/or
5 9
  * modify it under the terms of the GNU General Public License as
6 10
  * published by the Free Software Foundation; either version 2, or (at
7 11
  * your option) any later version.
8 12
  */
9 13
 
10
-#include	"timer.h"
11
-#include	"latch.h"
12
-#include	<io.h>
13
-#include	<gpxe/init.h>
14
+#include <stddef.h>
15
+#include <bits/timer2.h>
16
+#include <gpxe/timer.h>
17
+#include <io.h>
18
+
19
+/* Timers tick over at this rate */
20
+#define TIMER2_TICK_RATE	1193180U
21
+
22
+/* Parallel Peripheral Controller Port B */
23
+#define	PPC_PORTB	0x61
24
+
25
+/* Meaning of the port bits */
26
+#define	PPCB_T2OUT	0x20	/* Bit 5 */
27
+#define	PPCB_SPKR	0x02	/* Bit 1 */
28
+#define	PPCB_T2GATE	0x01	/* Bit 0 */
29
+
30
+/* Ports for the 8254 timer chip */
31
+#define	TIMER2_PORT	0x42
32
+#define	TIMER_MODE_PORT	0x43
33
+
34
+/* Meaning of the mode bits */
35
+#define	TIMER0_SEL	0x00
36
+#define	TIMER1_SEL	0x40
37
+#define	TIMER2_SEL	0x80
38
+#define	READBACK_SEL	0xC0
39
+
40
+#define	LATCH_COUNT	0x00
41
+#define	LOBYTE_ACCESS	0x10
42
+#define	HIBYTE_ACCESS	0x20
43
+#define	WORD_ACCESS	0x30
44
+
45
+#define	MODE0		0x00
46
+#define	MODE1		0x02
47
+#define	MODE2		0x04
48
+#define	MODE3		0x06
49
+#define	MODE4		0x08
50
+#define	MODE5		0x0A
14 51
 
15
-void __load_timer2(unsigned int ticks)
52
+#define	BINARY_COUNT	0x00
53
+#define	BCD_COUNT	0x01
54
+
55
+static void load_timer2(unsigned int ticks)
16 56
 {
17 57
 	/*
18 58
 	 * Now let's take care of PPC channel 2
@@ -35,162 +75,15 @@ void __load_timer2(unsigned int ticks)
35 75
 	outb(ticks >> 8, TIMER2_PORT);
36 76
 }
37 77
 
38
-static int __timer2_running(void)
78
+static int timer2_running(void)
39 79
 {
40 80
 	return ((inb(PPC_PORTB) & PPCB_T2OUT) == 0);
41 81
 }
42 82
 
43
-#if !defined(CONFIG_TSC_CURRTICKS)
44
-static void setup_timers(void)
45
-{
46
-	return;
47
-}
48
-
49
-void load_timer2(unsigned int ticks)
50
-{
51
-	return __load_timer2(ticks);
52
-}
53
-
54
-int timer2_running(void)
55
-{
56
-	return __timer2_running();
57
-}
58
-
59
-void ndelay(unsigned int nsecs)
60
-{
61
-	waiton_timer2((nsecs * CLOCK_TICK_RATE)/1000000000);
62
-}
63
-void udelay(unsigned int usecs)
64
-{
65
-	waiton_timer2((usecs * TICKS_PER_MS)/1000);
66
-}
67
-#endif /* !defined(CONFIG_TSC_CURRTICKS) */
68
-
69
-#if defined(CONFIG_TSC_CURRTICKS)
70
-
71
-#define rdtsc(low,high) \
72
-     __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
73
-
74
-#define rdtscll(val) \
75
-     __asm__ __volatile__ ("rdtsc" : "=A" (val))
76
-
77
-
78
-/* Number of clock ticks to time with the rtc */
79
-#define LATCH 0xFF
80
-
81
-#define LATCHES_PER_SEC ((CLOCK_TICK_RATE + (LATCH/2))/LATCH)
82
-#define TICKS_PER_LATCH ((LATCHES_PER_SEC + (TICKS_PER_SEC/2))/TICKS_PER_SEC)
83
-
84
-static void sleep_latch(void)
83
+void i386_timer2_udelay(unsigned int usecs)
85 84
 {
86
-	__load_timer2(LATCH);
87
-	while(__timer2_running());
85
+		load_timer2((usecs * TIMER2_TICK_RATE)/USECS_IN_SEC);
86
+		while (timer2_running())
87
+			;
88 88
 }
89 89
 
90
-/* ------ Calibrate the TSC ------- 
91
- * Time how long it takes to excute a loop that runs in known time.
92
- * And find the convertion needed to get to CLOCK_TICK_RATE
93
- */
94
-
95
-
96
-static unsigned long long calibrate_tsc(void)
97
-{
98
-	unsigned long startlow, starthigh;
99
-	unsigned long endlow, endhigh;
100
-	
101
-	rdtsc(startlow,starthigh);
102
-	sleep_latch();
103
-	rdtsc(endlow,endhigh);
104
-
105
-	/* 64-bit subtract - gcc just messes up with long longs */
106
-	__asm__("subl %2,%0\n\t"
107
-		"sbbl %3,%1"
108
-		:"=a" (endlow), "=d" (endhigh)
109
-		:"g" (startlow), "g" (starthigh),
110
-		"0" (endlow), "1" (endhigh));
111
-	
112
-	/* Error: ECPUTOOFAST */
113
-	if (endhigh)
114
-		goto bad_ctc;
115
-	
116
-	endlow *= TICKS_PER_LATCH;
117
-	return endlow;
118
-
119
-	/*
120
-	 * The CTC wasn't reliable: we got a hit on the very first read,
121
-	 * or the CPU was so fast/slow that the quotient wouldn't fit in
122
-	 * 32 bits..
123
-	 */
124
-bad_ctc:
125
-	printf("bad_ctc\n");
126
-	return 0;
127
-}
128
-
129
-static unsigned long clocks_per_tick;
130
-static void setup_timers(void)
131
-{
132
-	if (!clocks_per_tick) {
133
-		clocks_per_tick = calibrate_tsc();
134
-		/* Display the CPU Mhz to easily test if the calibration was bad */
135
-		printf("CPU %ld Mhz\n", (clocks_per_tick/1000 * TICKS_PER_SEC)/1000);
136
-	}
137
-}
138
-
139
-unsigned long currticks(void)
140
-{
141
-	unsigned long clocks_high, clocks_low;
142
-	unsigned long currticks;
143
-	/* Read the Time Stamp Counter */
144
-	rdtsc(clocks_low, clocks_high);
145
-
146
-	/* currticks = clocks / clocks_per_tick; */
147
-	__asm__("divl %1"
148
-		:"=a" (currticks)
149
-		:"r" (clocks_per_tick), "0" (clocks_low), "d" (clocks_high));
150
-
151
-
152
-	return currticks;
153
-}
154
-
155
-static unsigned long long timer_timeout;
156
-static int __timer_running(void)
157
-{
158
-	unsigned long long now;
159
-	rdtscll(now);
160
-	return now < timer_timeout;
161
-}
162
-
163
-void udelay(unsigned int usecs)
164
-{
165
-	unsigned long long now;
166
-	rdtscll(now);
167
-	timer_timeout = now + usecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000));
168
-	while(__timer_running());
169
-}
170
-void ndelay(unsigned int nsecs)
171
-{
172
-	unsigned long long now;
173
-	rdtscll(now);
174
-	timer_timeout = now + nsecs * ((clocks_per_tick * TICKS_PER_SEC)/(1000*1000*1000));
175
-	while(__timer_running());
176
-}
177
-
178
-void load_timer2(unsigned int timer2_ticks)
179
-{
180
-	unsigned long long now;
181
-	unsigned long clocks;
182
-	rdtscll(now);
183
-	clocks = timer2_ticks * ((clocks_per_tick * TICKS_PER_SEC)/CLOCK_TICK_RATE);
184
-	timer_timeout = now + clocks;
185
-}
186
-
187
-int timer2_running(void)
188
-{
189
-	return __timer_running();
190
-}
191
-
192
-#endif /* RTC_CURRTICKS */
193
-
194
-struct init_fn timer_init_fn __init_fn ( INIT_NORMAL ) = {
195
-	.initialise = setup_timers,
196
-};

+ 12
- 0
src/arch/i386/core/nap.c Datei anzeigen

@@ -0,0 +1,12 @@
1
+
2
+#include <realmode.h>
3
+#include <bios.h>
4
+
5
+/**************************************************************************
6
+ * Save power by halting the CPU until the next interrupt
7
+ **************************************************************************/
8
+void cpu_nap ( void ) {
9
+	__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
10
+					   "hlt\n\t"
11
+					   "cli\n\t" ) : : );
12
+}

+ 57
- 0
src/arch/i386/drivers/timer_bios.c Datei anzeigen

@@ -0,0 +1,57 @@
1
+/*
2
+ * Etherboot routines for PCBIOS firmware.
3
+ *
4
+ * Body of routines taken from old pcbios.S
5
+ */
6
+
7
+#include <gpxe/init.h>
8
+#include <gpxe/timer.h>
9
+#include <stdio.h>
10
+#include <realmode.h>
11
+#include <bios.h>
12
+#include <bits/timer2.h>
13
+
14
+/* A bit faster actually, but we don't care. */
15
+#define	TIMER2_TICKS_PER_SEC	18
16
+
17
+/*
18
+ * Use direct memory access to BIOS variables, longword 0040:006C (ticks
19
+ * today) and byte 0040:0070 (midnight crossover flag) instead of calling
20
+ * timeofday BIOS interrupt.
21
+ */
22
+
23
+static tick_t bios_currticks ( void ) {
24
+	static int days = 0;
25
+	uint32_t ticks;
26
+	uint8_t midnight;
27
+
28
+	/* Re-enable interrupts so that the timer interrupt can occur */
29
+	__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
30
+					   "nop\n\t"
31
+					   "nop\n\t"
32
+					   "cli\n\t" ) : : );
33
+
34
+	get_real ( ticks, BDA_SEG, 0x006c );
35
+	get_real ( midnight, BDA_SEG, 0x0070 );
36
+
37
+	if ( midnight ) {
38
+		midnight = 0;
39
+		put_real ( midnight, BDA_SEG, 0x0070 );
40
+		days += 0x1800b0;
41
+	}
42
+
43
+	return ( (days + ticks) * (USECS_IN_SEC / TIMER2_TICKS_PER_SEC) );
44
+}
45
+
46
+static int bios_ts_init(void)
47
+{
48
+	DBG("BIOS timer installed\n");
49
+	return 0;
50
+}
51
+
52
+struct timer bios_ts __timer ( 02 ) = {
53
+	.init = bios_ts_init,
54
+	.udelay = i386_timer2_udelay,
55
+	.currticks = bios_currticks,
56
+};
57
+

+ 69
- 0
src/arch/i386/drivers/timer_rdtsc.c Datei anzeigen

@@ -0,0 +1,69 @@
1
+
2
+#include <gpxe/init.h>
3
+#include <gpxe/timer.h>
4
+#include <errno.h>
5
+#include <stdio.h>
6
+#include <bits/cpu.h>
7
+#include <bits/timer2.h>
8
+#include <io.h>
9
+
10
+
11
+#define rdtsc(low,high) \
12
+     __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
13
+
14
+#define rdtscll(val) \
15
+     __asm__ __volatile__ ("rdtsc" : "=A" (val))
16
+
17
+
18
+/* Measure how many clocks we get in one microsecond */
19
+static inline uint64_t calibrate_tsc(void)
20
+{
21
+
22
+	uint64_t rdtsc_start;
23
+	uint64_t rdtsc_end;
24
+
25
+	rdtscll(rdtsc_start);
26
+	i386_timer2_udelay(USECS_IN_MSEC);
27
+	rdtscll(rdtsc_end);
28
+	
29
+	return (rdtsc_end - rdtsc_start) / USECS_IN_MSEC;
30
+}
31
+
32
+static uint32_t clocks_per_usec = 0;
33
+
34
+/* We measure time in microseconds. */
35
+static tick_t rdtsc_currticks(void)
36
+{
37
+	uint64_t clocks;
38
+
39
+	/* Read the Time Stamp Counter */
40
+	rdtscll(clocks);
41
+
42
+	return clocks / clocks_per_usec;
43
+}
44
+
45
+static int rdtsc_ts_init(void)
46
+{
47
+
48
+	struct cpuinfo_x86 cpu_info;
49
+
50
+	get_cpuinfo(&cpu_info);
51
+	if (cpu_info.features & X86_FEATURE_TSC) {
52
+		clocks_per_usec= calibrate_tsc();
53
+		if (clocks_per_usec) {
54
+			DBG("RDTSC ticksource installed. CPU running at %ld Mhz\n",
55
+				clocks_per_usec);
56
+			return 0;
57
+		}
58
+	}
59
+
60
+	DBG("RDTSC ticksource not available on this machine.\n");
61
+	return -ENODEV;
62
+}
63
+
64
+struct timer rdtsc_ts __timer (01) = {
65
+	.init = rdtsc_ts_init,
66
+	.udelay = generic_currticks_udelay,
67
+	.currticks = rdtsc_currticks,
68
+};
69
+

+ 0
- 55
src/arch/i386/firmware/pcbios/bios.c Datei anzeigen

@@ -1,55 +0,0 @@
1
-/* Etherboot routines for PCBIOS firmware.
2
- *
3
- * Body of routines taken from old pcbios.S
4
- */
5
-
6
-#include <stdint.h>
7
-#include <realmode.h>
8
-#include <bios.h>
9
-
10
-#define CF ( 1 << 0 )
11
-
12
-/**************************************************************************
13
-CURRTICKS - Get Time
14
-Use direct memory access to BIOS variables, longword 0040:006C (ticks
15
-today) and byte 0040:0070 (midnight crossover flag) instead of calling
16
-timeofday BIOS interrupt.
17
-**************************************************************************/
18
-#if defined(CONFIG_TSC_CURRTICKS)
19
-#undef CONFIG_BIOS_CURRTICKS
20
-#else
21
-#define CONFIG_BIOS_CURRTICKS 1
22
-#endif
23
-#if defined(CONFIG_BIOS_CURRTICKS)
24
-unsigned long currticks ( void ) {
25
-	static uint32_t days = 0;
26
-	uint32_t ticks;
27
-	uint8_t midnight;
28
-
29
-	/* Re-enable interrupts so that the timer interrupt can occur
30
-	 */
31
-	__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
32
-					   "nop\n\t"
33
-					   "nop\n\t"
34
-					   "cli\n\t" ) : : );
35
-
36
-	get_real ( ticks, BDA_SEG, 0x006c );
37
-	get_real ( midnight, BDA_SEG, 0x0070 );
38
-
39
-	if ( midnight ) {
40
-		midnight = 0;
41
-		put_real ( midnight, BDA_SEG, 0x0070 );
42
-		days += 0x1800b0;
43
-	}
44
-	return ( days + ticks );
45
-}
46
-#endif	/* CONFIG_BIOS_CURRTICKS */
47
-
48
-/**************************************************************************
49
-CPU_NAP - Save power by halting the CPU until the next interrupt
50
-**************************************************************************/
51
-void cpu_nap ( void ) {
52
-	__asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
53
-					   "hlt\n\t"
54
-					   "cli\n\t" ) : : );
55
-}

+ 3
- 4
src/arch/i386/firmware/pcbios/gateA20.c Datei anzeigen

@@ -1,8 +1,7 @@
1 1
 #include <stdio.h>
2
-#include "realmode.h"
3
-#include "timer.h"
4
-#include "latch.h"
5
-#include "bios.h"
2
+#include <realmode.h>
3
+#include <bios.h>
4
+#include <gpxe/timer.h>
6 5
 
7 6
 #define K_RDWR		0x60		/* keyboard data & cmds (read/write) */
8 7
 #define K_STATUS	0x64		/* keyboard status */

+ 3
- 0
src/arch/i386/include/bits/errfile.h Datei anzeigen

@@ -26,6 +26,9 @@
26 26
 #define ERRFILE_undionly	 ( ERRFILE_ARCH | ERRFILE_NET | 0x00030000 )
27 27
 #define ERRFILE_undirom		 ( ERRFILE_ARCH | ERRFILE_NET | 0x00040000 )
28 28
 
29
+#define ERRFILE_timer_rdtsc    ( ERRFILE_ARCH | ERRFILE_DRIVER | 0x00000000 )
30
+#define ERRFILE_timer_bios     ( ERRFILE_ARCH | ERRFILE_DRIVER | 0x00010000 )
31
+
29 32
 /** @} */
30 33
 
31 34
 #endif /* _BITS_ERRFILE_H */

+ 8
- 0
src/arch/i386/include/bits/timer2.h Datei anzeigen

@@ -0,0 +1,8 @@
1
+#ifndef BITS_TIMER2_H
2
+#define BITS_TIMER2_H
3
+
4
+#include <stddef.h>
5
+
6
+void i386_timer2_udelay(unsigned int usecs);
7
+
8
+#endif

+ 0
- 12
src/arch/i386/include/latch.h Datei anzeigen

@@ -1,12 +0,0 @@
1
-#ifndef LATCH_H
2
-#define LATCH_H
3
-
4
-#define	TICKS_PER_SEC		18
5
-
6
-/* For different calibrators of the TSC move the declaration of
7
- * sleep_latch and the definitions of it's length here...
8
- */
9
-
10
-extern unsigned long currticks ( void );
11
-
12
-#endif /* LATCH_H */

+ 10
- 0
src/config.h Datei anzeigen

@@ -51,6 +51,16 @@
51 51
 
52 52
 /* @END serial.h */
53 53
 
54
+/* @BEGIN general.h
55
+ *
56
+ * Timer configuration
57
+ *
58
+ */
59
+#define TIMER_BIOS		/* 18Hz BIOS timer */
60
+#define TIMER_RDTSC		/* CPU TimeStamp Counter timer */
61
+
62
+/* @END general.h */
63
+
54 64
 /* @BEGIN isa.h
55 65
  *
56 66
  * ISA probe address configuration

+ 11
- 0
src/core/config.c Datei anzeigen

@@ -74,6 +74,17 @@ REQUIRE_OBJECT ( pc_kbd );
74 74
 REQUIRE_OBJECT ( syslog );
75 75
 #endif
76 76
 
77
+/*
78
+ * Timers
79
+ */
80
+
81
+#ifdef TIMER_BIOS
82
+REQUIRE_OBJECT ( timer_bios );
83
+#endif
84
+
85
+#ifdef TIMER_RDTSC
86
+REQUIRE_OBJECT ( timer_rdtsc );
87
+#endif
77 88
 /*
78 89
  * Drag in all requested protocols
79 90
  *

+ 1
- 1
src/core/getkey.c Datei anzeigen

@@ -17,9 +17,9 @@
17 17
  */
18 18
 
19 19
 #include <console.h>
20
-#include <latch.h>
21 20
 #include <gpxe/process.h>
22 21
 #include <gpxe/keys.h>
22
+#include <gpxe/timer.h>
23 23
 
24 24
 /** @file
25 25
  *

+ 1
- 13
src/core/misc.c Datei anzeigen

@@ -4,20 +4,8 @@ MISC Support Routines
4 4
 
5 5
 #include <stdlib.h>
6 6
 #include <byteswap.h>
7
-#include <latch.h>
8 7
 #include <gpxe/in.h>
9
-
10
-/**************************************************************************
11
-SLEEP
12
-**************************************************************************/
13
-unsigned int sleep(unsigned int secs)
14
-{
15
-	unsigned long tmo;
16
-
17
-	for (tmo = currticks()+secs*TICKS_PER_SEC; currticks() < tmo; ) {
18
-	}
19
-	return 0;
20
-}
8
+#include <gpxe/timer.h>
21 9
 
22 10
 /**************************************************************************
23 11
 INET_ATON - Convert an ascii x.x.x.x to binary form

+ 1
- 1
src/core/random.c Datei anzeigen

@@ -5,7 +5,7 @@
5 5
  */
6 6
 
7 7
 #include <stdlib.h>
8
-#include <latch.h>
8
+#include <gpxe/timer.h>
9 9
 
10 10
 static int32_t rnd_seed = 0;
11 11
 

+ 1
- 1
src/core/serial.c Datei anzeigen

@@ -15,7 +15,7 @@
15 15
 #include "console.h"
16 16
 #include <gpxe/init.h>
17 17
 #include "io.h"
18
-#include "timer.h"
18
+#include <unistd.h>
19 19
 #include "config/serial.h"
20 20
 
21 21
 /* Set default values if none specified */

+ 88
- 15
src/core/timer.c Datei anzeigen

@@ -1,27 +1,100 @@
1
-/* A couple of routines to implement a low-overhead timer for drivers */
2
-
3
- /*
1
+/*
2
+ * core/timer.c
3
+ *
4
+ * Copyright (C) 2007 Alexey Zaytsev <alexey.zaytsev@gmail.com>
5
+ *
4 6
  * This program is free software; you can redistribute it and/or
5 7
  * modify it under the terms of the GNU General Public License as
6
- * published by the Free Software Foundation; either version 2, or (at
7
- * your option) any later version.
8
+ * published by the Free Software Foundation; either version 2 of the
9
+ * License, or any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful, but
12
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
8 19
  */
9 20
 
10
-#include	"timer.h"
21
+#include <stddef.h>
22
+#include <assert.h>
23
+#include <gpxe/init.h>
24
+#include <gpxe/timer.h>
25
+#include <stdio.h>
11 26
 
12
-/* Machine Independant timer helper functions */
27
+static struct timer ts_table[0]
28
+	__table_start ( struct timer, timers );
29
+static struct timer ts_table_end[0]
30
+	__table_end ( struct timer, timers );
13 31
 
14
-void mdelay(unsigned int msecs)
32
+
33
+static struct timer *used_ts = NULL;
34
+
35
+/*
36
+ * This function may be used in custom timer driver.
37
+ *
38
+ * This udelay implementation works well if you've got a
39
+ * fast currticks().
40
+ */
41
+void generic_currticks_udelay(unsigned int usecs)
15 42
 {
16
-	unsigned int i;
17
-	for(i = 0; i < msecs; i++) {
18
-		udelay(1000);
19
-	}
43
+	tick_t t;
44
+
45
+	t = currticks();
46
+	while (t + usecs > currticks())
47
+		; /* xxx: Relax the cpu some way. */
20 48
 }
21 49
 
22
-void waiton_timer2(unsigned int ticks)
50
+
51
+static void timer_init(void)
23 52
 {
24
-	load_timer2(ticks);
25
-	while(timer2_running()) {
53
+	struct timer *ts;
54
+
55
+	for (ts = ts_table; ts < ts_table_end; ts++) {
56
+		if (ts->init && ts->init() >= 0) {
57
+			used_ts = ts;
58
+			break;
59
+		}
26 60
 	}
61
+
62
+	assert(used_ts);
27 63
 }
64
+
65
+struct init_fn ts_init_fn __init_fn ( INIT_NORMAL ) = {
66
+	.initialise = timer_init,
67
+};
68
+
69
+/* Functions for public use. */
70
+
71
+tick_t currticks(void)
72
+{
73
+	tick_t ct;
74
+	assert(used_ts);
75
+
76
+	ct = used_ts->currticks();
77
+	DBG("currticks: %ld seconds and %06ld microseconds\n", ct/USECS_IN_SEC, ct%USECS_IN_SEC);
78
+
79
+	return ct;
80
+}
81
+
82
+void udelay(unsigned int usecs)
83
+{
84
+	used_ts->udelay(usecs);
85
+}
86
+
87
+void mdelay(unsigned int msecs)
88
+{
89
+	while(msecs--)
90
+		used_ts->udelay(USECS_IN_MSEC);
91
+}
92
+
93
+unsigned int sleep(unsigned int secs)
94
+{
95
+	while (secs--)
96
+		mdelay(MSECS_IN_SEC);
97
+
98
+	return 0;
99
+}
100
+

+ 0
- 1
src/drivers/bitbash/bitbash.c Datei anzeigen

@@ -16,7 +16,6 @@
16 16
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18 18
 
19
-#include <timer.h>
20 19
 #include <gpxe/bitbash.h>
21 20
 
22 21
 /** @file

+ 1
- 1
src/drivers/bitbash/i2c_bit.c Datei anzeigen

@@ -20,7 +20,7 @@
20 20
 #include <stdint.h>
21 21
 #include <errno.h>
22 22
 #include <assert.h>
23
-#include <timer.h>
23
+#include <unistd.h>
24 24
 #include <gpxe/bitbash.h>
25 25
 #include <gpxe/i2c.h>
26 26
 

+ 1
- 1
src/drivers/bitbash/spi_bit.c Datei anzeigen

@@ -22,7 +22,7 @@
22 22
 #include <byteswap.h>
23 23
 #include <errno.h>
24 24
 #include <assert.h>
25
-#include <timer.h>
25
+#include <unistd.h>
26 26
 #include <gpxe/bitbash.h>
27 27
 #include <gpxe/spi_bit.h>
28 28
 

+ 1
- 1
src/drivers/bus/eisa.c Datei anzeigen

@@ -4,7 +4,7 @@
4 4
 #include <stdio.h>
5 5
 #include <errno.h>
6 6
 #include <io.h>
7
-#include <timer.h>
7
+#include <unistd.h>
8 8
 #include <gpxe/eisa.h>
9 9
 
10 10
 static struct eisa_driver eisa_drivers[0]

+ 1
- 1
src/drivers/bus/isapnp.c Datei anzeigen

@@ -61,7 +61,7 @@
61 61
 #include <stdio.h>
62 62
 #include <errno.h>
63 63
 #include <io.h>
64
-#include <timer.h>
64
+#include <unistd.h>
65 65
 #include <gpxe/isapnp.h>
66 66
 
67 67
 /**

+ 0
- 1
src/drivers/bus/mca.c Datei anzeigen

@@ -11,7 +11,6 @@
11 11
 #include <stdio.h>
12 12
 #include <errno.h>
13 13
 #include <io.h>
14
-#include <timer.h>
15 14
 #include <gpxe/mca.h>
16 15
 
17 16
 static struct mca_driver mca_drivers[0]

+ 0
- 1
src/drivers/infiniband/arbel.c Datei anzeigen

@@ -26,7 +26,6 @@
26 26
 #include <strings.h>
27 27
 #include <unistd.h>
28 28
 #include <errno.h>
29
-#include <timer.h>
30 29
 #include <byteswap.h>
31 30
 #include <gpxe/pci.h>
32 31
 #include <gpxe/malloc.h>

+ 0
- 1
src/drivers/infiniband/hermon.c Datei anzeigen

@@ -24,7 +24,6 @@
24 24
 #include <strings.h>
25 25
 #include <unistd.h>
26 26
 #include <errno.h>
27
-#include <timer.h>
28 27
 #include <byteswap.h>
29 28
 #include <gpxe/pci.h>
30 29
 #include <gpxe/malloc.h>

+ 1
- 1
src/drivers/net/3c509.c Datei anzeigen

@@ -9,7 +9,7 @@
9 9
 #include <string.h>
10 10
 #include <errno.h>
11 11
 #include <io.h>
12
-#include <timer.h>
12
+#include <unistd.h>
13 13
 #include <gpxe/device.h>
14 14
 #include <gpxe/isa.h>
15 15
 #include "3c509.h"

+ 0
- 1
src/drivers/net/3c515.c Datei anzeigen

@@ -50,7 +50,6 @@
50 50
 #include "nic.h"
51 51
 #include <gpxe/isapnp.h>
52 52
 #include <gpxe/isa.h> /* for ISA_ROM */
53
-#include "timer.h"
54 53
 #include <gpxe/ethernet.h>
55 54
 
56 55
 static void t3c515_wait(unsigned int nticks)

+ 0
- 1
src/drivers/net/3c595.c Datei anzeigen

@@ -30,7 +30,6 @@
30 30
 #include <gpxe/pci.h>
31 31
 #include <gpxe/ethernet.h>
32 32
 #include "3c595.h"
33
-#include "timer.h"
34 33
 
35 34
 static struct nic_operations t595_operations;
36 35
 

+ 0
- 1
src/drivers/net/3c5x9.c Datei anzeigen

@@ -28,7 +28,6 @@ $Id$
28 28
 #include "etherboot.h"
29 29
 #include "nic.h"
30 30
 #include <gpxe/isa.h>
31
-#include "timer.h"
32 31
 #include "3c509.h"
33 32
 
34 33
 static enum { none, bnc, utp } connector = none;	/* for 3C509 */

+ 4
- 3
src/drivers/net/3c90x.c Datei anzeigen

@@ -43,7 +43,6 @@
43 43
 #include "nic.h"
44 44
 #include <gpxe/pci.h>
45 45
 #include <gpxe/ethernet.h>
46
-#include "timer.h"
47 46
 
48 47
 static struct nic_operations a3c90x_operations;
49 48
 
@@ -498,6 +497,7 @@ a3c90x_transmit(struct nic *nic __unused, const char *d, unsigned int t,
498 497
 
499 498
     unsigned char status;
500 499
     unsigned i, retries;
500
+    tick_t ct;
501 501
 
502 502
     for (retries=0; retries < XMIT_RETRIES ; retries++)
503 503
 	{
@@ -540,9 +540,10 @@ a3c90x_transmit(struct nic *nic __unused, const char *d, unsigned int t,
540 540
 	    ;
541 541
 
542 542
 	/** Wait for NIC Transmit to Complete **/
543
-	load_timer2(10*TICKS_PER_MS);	/* Give it 10 ms */
543
+	ct = currticks();
544
+
544 545
 	while (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0004) &&
545
-		timer2_running())
546
+		ct + 10*USECS_IN_MSEC < currticks());
546 547
 		;
547 548
 
548 549
 	if (!(inw(INF_3C90X.IOAddr + regCommandIntStatus_w)&0x0004))

+ 0
- 1
src/drivers/net/amd8111e.c Datei anzeigen

@@ -33,7 +33,6 @@
33 33
 #include "mii.h"
34 34
 #include <gpxe/pci.h>
35 35
 #include <gpxe/ethernet.h>
36
-#include "timer.h"
37 36
 #include "string.h"
38 37
 #include "stdint.h"
39 38
 #include "amd8111e.h"

+ 0
- 1
src/drivers/net/bnx2.c Datei anzeigen

@@ -18,7 +18,6 @@
18 18
 #include <errno.h>
19 19
 #include <gpxe/pci.h>
20 20
 #include <gpxe/ethernet.h>
21
-#include "timer.h"
22 21
 #include "string.h"
23 22
 #include "bnx2.h"
24 23
 #include "bnx2_fw.h"

+ 0
- 1
src/drivers/net/dmfe.c Datei anzeigen

@@ -43,7 +43,6 @@
43 43
 /* to get the PCI support functions, if this is a PCI NIC */
44 44
 #include <gpxe/pci.h>
45 45
 #include <gpxe/ethernet.h>
46
-#include "timer.h"
47 46
 
48 47
 /* #define EDEBUG 1 */
49 48
 #ifdef EDEBUG

+ 0
- 1
src/drivers/net/e1000/e1000.h Datei anzeigen

@@ -36,7 +36,6 @@
36 36
 #include <stdio.h>
37 37
 #include <io.h>
38 38
 #include <errno.h>
39
-#include <timer.h>
40 39
 #include <byteswap.h>
41 40
 #include <gpxe/pci.h>
42 41
 #include <gpxe/malloc.h>

+ 1
- 1
src/drivers/net/e1000/e1000_osdep.h Datei anzeigen

@@ -39,7 +39,7 @@
39 39
 #include <stdio.h>
40 40
 #include <io.h>
41 41
 #include <errno.h>
42
-#include <timer.h>
42
+#include <unistd.h>
43 43
 #include <byteswap.h>
44 44
 #include <gpxe/pci.h>
45 45
 #include <gpxe/if_ether.h>

+ 0
- 1
src/drivers/net/eepro.c Datei anzeigen

@@ -35,7 +35,6 @@ has 34 pins, the top row of 2 are not used.
35 35
 #include <errno.h>
36 36
 #include "nic.h"
37 37
 #include <gpxe/isa.h>
38
-#include "timer.h"
39 38
 #include <gpxe/ethernet.h>
40 39
 
41 40
 /* Different 82595 chips */

+ 8
- 5
src/drivers/net/eepro100.c Datei anzeigen

@@ -107,7 +107,6 @@
107 107
 #include "nic.h"
108 108
 #include <gpxe/ethernet.h>
109 109
 #include <gpxe/pci.h>
110
-#include "timer.h"
111 110
 
112 111
 static int ioaddr;
113 112
 
@@ -408,6 +407,7 @@ static void eepro100_transmit(struct nic *nic, const char *d, unsigned int t, un
408 407
 	} hdr;
409 408
 	unsigned short status;
410 409
 	int s1, s2;
410
+	tick_t ct;
411 411
 
412 412
 	status = inw(ioaddr + SCBStatus);
413 413
 	/* Acknowledge all of the current interrupt sources ASAP. */
@@ -445,8 +445,10 @@ static void eepro100_transmit(struct nic *nic, const char *d, unsigned int t, un
445 445
 	wait_for_cmd_done(ioaddr + SCBCmd);
446 446
 
447 447
 	s1 = inw (ioaddr + SCBStatus);
448
-	load_timer2(10*TICKS_PER_MS);		/* timeout 10 ms for transmit */
449
-	while (!txfd.status && timer2_running())
448
+
449
+	ct = currticks();
450
+	/* timeout 10 ms for transmit */
451
+	while (!txfd.status && ct + 10*USECS_IN_MSEC)
450 452
 		/* Wait */;
451 453
 	s2 = inw (ioaddr + SCBStatus);
452 454
 
@@ -606,6 +608,7 @@ static int eepro100_probe ( struct nic *nic, struct pci_device *pci ) {
606 608
 	int read_cmd, ee_size;
607 609
 	int options;
608 610
 	int rx_mode;
611
+	tick_t ct;
609 612
 
610 613
 	/* we cache only the first few words of the EEPROM data
611 614
 	   be careful not to access beyond this array */
@@ -749,8 +752,8 @@ static int eepro100_probe ( struct nic *nic, struct pci_device *pci ) {
749 752
 
750 753
 	whereami ("started TX thingy (config, iasetup).");
751 754
 
752
-	load_timer2(10*TICKS_PER_MS);
753
-	while (!txfd.status && timer2_running())
755
+	ct = currticks();
756
+	while (!txfd.status && ct + 10*USECS_IN_MSEC < currticks())
754 757
 		/* Wait */;
755 758
 
756 759
 	/* Read the status register once to disgard stale data */

+ 9
- 7
src/drivers/net/epic100.c Datei anzeigen

@@ -8,7 +8,6 @@
8 8
 #include <gpxe/pci.h>
9 9
 #include <gpxe/ethernet.h>
10 10
 #include "nic.h"
11
-#include "timer.h"
12 11
 #include "console.h"
13 12
 #include "epic100.h"
14 13
 
@@ -310,6 +309,7 @@ epic100_transmit(struct nic *nic, const char *destaddr, unsigned int type,
310 309
     unsigned short nstype;
311 310
     unsigned char *txp;
312 311
     int entry;
312
+    tick_t ct;
313 313
 
314 314
     /* Calculate the next Tx descriptor entry. */
315 315
     entry = cur_tx % TX_RING_SIZE;
@@ -339,18 +339,20 @@ epic100_transmit(struct nic *nic, const char *destaddr, unsigned int type,
339 339
      * set the base address with the "ownership"
340 340
      * bits last.
341 341
      */
342
-    
342
+   
343 343
     tx_ring[entry].buflength |= cpu_to_le32(len);
344
-    tx_ring[entry].status = cpu_to_le32(len << 16) | 
344
+    tx_ring[entry].status = cpu_to_le32(len << 16) |
345 345
 	    cpu_to_le32(TRING_OWN);	/* Pass ownership to the chip. */
346 346
 
347 347
     cur_tx++;
348 348
 
349 349
     /* Trigger an immediate transmit demand. */
350
-    outl(CR_QUEUE_TX, command); 
351
-    
352
-    load_timer2(10*TICKS_PER_MS);         /* timeout 10 ms for transmit */
353
-    while ((le32_to_cpu(tx_ring[entry].status) & (TRING_OWN)) && timer2_running())
350
+    outl(CR_QUEUE_TX, command);
351
+
352
+    ct = currticks();
353
+    /* timeout 10 ms for transmit */
354
+    while ((le32_to_cpu(tx_ring[entry].status) & (TRING_OWN)) &&
355
+		ct + 10*USECS_IN_MSEC < currticks())
354 356
 	/* Wait */;
355 357
 
356 358
     if ((le32_to_cpu(tx_ring[entry].status) & TRING_OWN) != 0)

+ 0
- 1
src/drivers/net/etherfabric.c Datei anzeigen

@@ -24,7 +24,6 @@
24 24
 #include <gpxe/i2c.h>
25 25
 #include <gpxe/spi.h>
26 26
 #include <gpxe/nvo.h>
27
-#include "timer.h"
28 27
 #define dma_addr_t unsigned long
29 28
 #include "etherfabric.h"
30 29
 

+ 0
- 1
src/drivers/net/forcedeth.c Datei anzeigen

@@ -51,7 +51,6 @@
51 51
 #include <gpxe/pci.h>
52 52
 /* Include timer support functions */
53 53
 #include <gpxe/ethernet.h>
54
-#include "timer.h"
55 54
 #include "mii.h"
56 55
 
57 56
 #define drv_version "v1.2"

+ 0
- 1
src/drivers/net/ipoib.c Datei anzeigen

@@ -22,7 +22,6 @@
22 22
 #include <string.h>
23 23
 #include <byteswap.h>
24 24
 #include <errno.h>
25
-#include "timer.h"
26 25
 #include <gpxe/if_arp.h>
27 26
 #include <gpxe/iobuf.h>
28 27
 #include <gpxe/netdevice.h>

+ 0
- 1
src/drivers/net/mlx_ipoib/mt23108_imp.c Datei anzeigen

@@ -37,7 +37,6 @@ static void be_to_cpu_buf(void *buf, int size)
37 37
 	}
38 38
 }
39 39
 
40
-#include "timer.h"
41 40
 #include "cmdif_mt23108.c"
42 41
 #include "cmdif_comm.c"
43 42
 #include "ib_mt23108.c"

+ 0
- 1
src/drivers/net/mlx_ipoib/mt25218_imp.c Datei anzeigen

@@ -37,7 +37,6 @@ static void be_to_cpu_buf(void *buf, int size)
37 37
 	}
38 38
 }
39 39
 
40
-#include "timer.h"
41 40
 #include "cmdif_mt25218.c"
42 41
 #include "cmdif_comm.c"
43 42
 #include "ib_mt25218.c"

+ 1
- 1
src/drivers/net/mtnic.c Datei anzeigen

@@ -37,7 +37,7 @@
37 37
 #include <gpxe/umalloc.h>
38 38
 #include <bits/byteswap.h>
39 39
 #include <little_bswap.h>
40
-#include <timer.h>
40
+#include <unistd.h>
41 41
 #include <gpxe/pci.h>
42 42
 #include <gpxe/ethernet.h>
43 43
 #include <gpxe/netdevice.h>

+ 1
- 1
src/drivers/net/natsemi.c Datei anzeigen

@@ -63,8 +63,8 @@
63 63
 #include <stdio.h>
64 64
 #include <io.h>
65 65
 #include <errno.h>
66
-#include <timer.h>
67 66
 #include <byteswap.h>
67
+#include <unistd.h>
68 68
 #include <gpxe/pci.h>
69 69
 #include <gpxe/if_ether.h>
70 70
 #include <gpxe/ethernet.h>

+ 0
- 1
src/drivers/net/pcnet32.c Datei anzeigen

@@ -43,7 +43,6 @@
43 43
 #include "nic.h"
44 44
 #include <gpxe/pci.h>
45 45
 #include <gpxe/ethernet.h>
46
-#include "timer.h"
47 46
 #include "mii.h"
48 47
 
49 48
 /* void hex_dump(const char *data, const unsigned int len); */

+ 0
- 1
src/drivers/net/prism2.c Datei anzeigen

@@ -62,7 +62,6 @@ static const char hardcoded_ssid[] = "";
62 62
  * quicker to convert code from the Linux Prism2 driver.
63 63
  */
64 64
 #include <errno.h>
65
-#include "timer.h"
66 65
 #define __le16_to_cpu(x) (x)
67 66
 #define __le32_to_cpu(x) (x)
68 67
 #define __cpu_to_le16(x) (x)

+ 0
- 1
src/drivers/net/r8169.c Datei anzeigen

@@ -49,7 +49,6 @@
49 49
 #include <gpxe/pci.h>
50 50
 #include <gpxe/ethernet.h>
51 51
 #include <gpxe/malloc.h>
52
-#include "timer.h"
53 52
 
54 53
 #define drv_version "v1.6"
55 54
 #define drv_date "03-27-2004"

+ 1
- 1
src/drivers/net/rtl8139.c Datei anzeigen

@@ -71,7 +71,7 @@
71 71
 #include <stdio.h>
72 72
 #include <io.h>
73 73
 #include <errno.h>
74
-#include <timer.h>
74
+#include <unistd.h>
75 75
 #include <byteswap.h>
76 76
 #include <gpxe/pci.h>
77 77
 #include <gpxe/if_ether.h>

+ 0
- 1
src/drivers/net/sis900.c Datei anzeigen

@@ -46,7 +46,6 @@
46 46
 #include "etherboot.h"
47 47
 #include <gpxe/pci.h>
48 48
 #include "nic.h"
49
-#include "timer.h"
50 49
 
51 50
 #include "sis900.h"
52 51
 

+ 0
- 1
src/drivers/net/smc9000.c Datei anzeigen

@@ -40,7 +40,6 @@
40 40
 #include "etherboot.h"
41 41
 #include "nic.h"
42 42
 #include <gpxe/isa.h>
43
-#include "timer.h"
44 43
 #include "smc9000.h"
45 44
 
46 45
 # define _outb outb

+ 0
- 1
src/drivers/net/sundance.c Datei anzeigen

@@ -46,7 +46,6 @@
46 46
 #include "nic.h"
47 47
 /* to get the PCI support functions, if this is a PCI NIC */
48 48
 #include <gpxe/pci.h>
49
-#include "timer.h"
50 49
 #include "mii.h"
51 50
 
52 51
 #define drv_version "v1.12"

+ 0
- 1
src/drivers/net/tg3.c Datei anzeigen

@@ -17,7 +17,6 @@
17 17
 #include <errno.h>
18 18
 #include <gpxe/pci.h>
19 19
 #include <gpxe/ethernet.h>
20
-#include "timer.h"
21 20
 #include "string.h"
22 21
 #include "tg3.h"
23 22
 

+ 0
- 1
src/drivers/net/tlan.c Datei anzeigen

@@ -42,7 +42,6 @@
42 42
 #include "nic.h"
43 43
 #include <gpxe/pci.h>
44 44
 #include <gpxe/ethernet.h>
45
-#include "timer.h"
46 45
 #include "tlan.h"
47 46
 
48 47
 #define drv_version "v1.4"

+ 12
- 9
src/drivers/net/via-rhine.c Datei anzeigen

@@ -50,7 +50,6 @@ static const char *version = "rhine.c v1.0.2 2004-10-29\n";
50 50
 #include "nic.h"
51 51
 #include <gpxe/pci.h>
52 52
 #include <gpxe/ethernet.h>
53
-#include "timer.h"
54 53
 
55 54
 /* define all ioaddr */
56 55
 
@@ -785,6 +784,7 @@ ReadMII (int byMIIIndex, int ioaddr)
785 784
     char byMIIAdrbak;
786 785
     char byMIICRbak;
787 786
     char byMIItemp;
787
+    tick_t ct;
788 788
 
789 789
     byMIIAdrbak = inb (byMIIAD);
790 790
     byMIICRbak = inb (byMIICR);
@@ -799,8 +799,8 @@ ReadMII (int byMIIIndex, int ioaddr)
799 799
     byMIItemp = inb (byMIICR);
800 800
     byMIItemp = byMIItemp & 0x40;
801 801
 
802
-    load_timer2(2*TICKS_PER_MS);
803
-    while (byMIItemp != 0 && timer2_running())
802
+    ct = currticks();
803
+    while (byMIItemp != 0 && ct + 2*USECS_IN_MSEC < currticks())
804 804
     {
805 805
 	byMIItemp = inb (byMIICR);
806 806
 	byMIItemp = byMIItemp & 0x40;
@@ -825,6 +825,7 @@ WriteMII (char byMIISetByte, char byMIISetBit, char byMIIOP, int ioaddr)
825 825
     char byMIIAdrbak;
826 826
     char byMIICRbak;
827 827
     char byMIItemp;
828
+    tick_t ct;
828 829
 
829 830
 
830 831
     byMIIAdrbak = inb (byMIIAD);
@@ -840,8 +841,8 @@ WriteMII (char byMIISetByte, char byMIISetBit, char byMIIOP, int ioaddr)
840 841
     byMIItemp = inb (byMIICR);
841 842
     byMIItemp = byMIItemp & 0x40;
842 843
 
843
-    load_timer2(2*TICKS_PER_MS);
844
-    while (byMIItemp != 0 && timer2_running())
844
+    ct = currticks();
845
+    while (byMIItemp != 0 && ct + 2*USECS_IN_MSEC < currticks())
845 846
     {
846 847
 	byMIItemp = inb (byMIICR);
847 848
 	byMIItemp = byMIItemp & 0x40;
@@ -870,8 +871,8 @@ WriteMII (char byMIISetByte, char byMIISetBit, char byMIIOP, int ioaddr)
870 871
     byMIItemp = inb (byMIICR);
871 872
     byMIItemp = byMIItemp & 0x20;
872 873
 
873
-    load_timer2(2*TICKS_PER_MS);
874
-    while (byMIItemp != 0 && timer2_running())
874
+    ct = currticks();
875
+    while (byMIItemp != 0 && ct + 2*USECS_IN_MSEC < currticks())
875 876
     {
876 877
 	byMIItemp = inb (byMIICR);
877 878
 	byMIItemp = byMIItemp & 0x20;
@@ -1345,6 +1346,7 @@ rhine_transmit (struct nic *nic,
1345 1346
     unsigned char CR1bak;
1346 1347
     unsigned char CR0bak;
1347 1348
     unsigned int nstype;
1349
+    tick_t ct;
1348 1350
 
1349 1351
 
1350 1352
     /*printf ("rhine_transmit\n"); */
@@ -1385,9 +1387,10 @@ rhine_transmit (struct nic *nic,
1385 1387
     outb (CR1bak, byCR1);
1386 1388
     do
1387 1389
     {
1388
-        load_timer2(10*TICKS_PER_MS);
1390
+	ct = currticks();
1389 1391
         /* Wait until transmit is finished or timeout*/
1390
-        while((tp->tx_ring[entry].tx_status.bits.own_bit !=0) && timer2_running())
1392
+        while((tp->tx_ring[entry].tx_status.bits.own_bit !=0) &&
1393
+		ct + 10*USECS_IN_MSEC < currticks())
1391 1394
         ;
1392 1395
 
1393 1396
         if(tp->tx_ring[entry].tx_status.bits.terr == 0)

+ 0
- 2
src/drivers/net/via-velocity.h Datei anzeigen

@@ -24,8 +24,6 @@
24 24
  *       Copyright (c) 2006 by Timothy Legge <tlegge@rogers.com>
25 25
  */
26 26
 
27
-#include "timer.h"
28
-
29 27
 #ifndef VELOCITY_H
30 28
 #define VELOCITY_H
31 29
 

+ 4
- 5
src/drivers/net/w89c840.c Datei anzeigen

@@ -81,7 +81,6 @@
81 81
 #include "nic.h"
82 82
 #include <gpxe/pci.h>
83 83
 #include <gpxe/ethernet.h>
84
-#include "timer.h"
85 84
 
86 85
 static const char *w89c840_version = "driver Version 0.94 - December 12, 2003";
87 86
 
@@ -113,7 +112,7 @@ static const char *w89c840_version = "driver Version 0.94 - December 12, 2003";
113 112
 
114 113
 /* Operational parameters that usually are not changed. */
115 114
 /* Time in jiffies before concluding the transmitter is hung. */
116
-#define TX_TIMEOUT  (10*TICKS_PER_MS)
115
+#define TX_TIMEOUT  (10*USECS_IN_MSEC)
117 116
 
118 117
 #define PKT_BUF_SZ  1536  /* Size of each temporary Rx buffer.*/
119 118
 
@@ -487,6 +486,7 @@ static void w89c840_transmit(
487 486
     /* send the packet to destination */
488 487
     unsigned entry;
489 488
     int transmit_status;
489
+    tick_t ct;
490 490
 
491 491
     /* Caution: the write order is important here, set the field
492 492
        with the "ownership" bits last. */
@@ -535,8 +535,7 @@ static void w89c840_transmit(
535 535
     /* Now wait for TX to complete. */
536 536
     transmit_status = w840private.tx_ring[entry].status;
537 537
 
538
-    load_timer2(TX_TIMEOUT);
539
-
538
+    ct = currticks();
540 539
     {
541 540
 #if defined W89C840_DEBUG
542 541
         u32 intr_stat = 0;
@@ -547,7 +546,7 @@ static void w89c840_transmit(
547 546
 	      decode_interrupt(intr_stat);
548 547
 #endif
549 548
 
550
-                while ( (transmit_status & DescOwn) && timer2_running()) {
549
+                while ( (transmit_status & DescOwn) && ct + TX_TIMEOUT < currticks()) {
551 550
 
552 551
                     transmit_status = w840private.tx_ring[entry].status;
553 552
                 }

+ 1
- 1
src/drivers/nvs/spi.c Datei anzeigen

@@ -18,7 +18,7 @@
18 18
 
19 19
 #include <stddef.h>
20 20
 #include <errno.h>
21
-#include <timer.h>
21
+#include <unistd.h>
22 22
 #include <gpxe/spi.h>
23 23
 
24 24
 /** @file

+ 1
- 1
src/drivers/nvs/threewire.c Datei anzeigen

@@ -18,7 +18,7 @@
18 18
 
19 19
 #include <stddef.h>
20 20
 #include <assert.h>
21
-#include <timer.h>
21
+#include <unistd.h>
22 22
 #include <gpxe/threewire.h>
23 23
 
24 24
 /** @file

+ 1
- 1
src/hci/mucurses/kb.c Datei anzeigen

@@ -1,6 +1,6 @@
1 1
 #include <curses.h>
2 2
 #include <stddef.h>
3
-#include <timer.h>
3
+#include <unistd.h>
4 4
 #include "mucurses.h"
5 5
 
6 6
 /** @file

+ 1
- 1
src/hci/shell_banner.c Datei anzeigen

@@ -18,8 +18,8 @@
18 18
 
19 19
 #include <stdio.h>
20 20
 #include <console.h>
21
-#include <latch.h>
22 21
 #include <gpxe/features.h>
22
+#include <gpxe/timer.h>
23 23
 #include <gpxe/shell_banner.h>
24 24
 
25 25
 /** @file

+ 1
- 1
src/include/etherboot.h Datei anzeigen

@@ -12,8 +12,8 @@
12 12
 #include <stdio.h>
13 13
 #include <unistd.h>
14 14
 #include <strings.h>
15
-#include <latch.h>
16 15
 #include <console.h>
16
+#include <gpxe/timer.h>
17 17
 #include <gpxe/if_arp.h>
18 18
 #include <gpxe/if_ether.h>
19 19
 

+ 0
- 1
src/include/gpxe/dhcp.h Datei anzeigen

@@ -12,7 +12,6 @@
12 12
 #include <gpxe/in.h>
13 13
 #include <gpxe/refcnt.h>
14 14
 #include <gpxe/tables.h>
15
-#include <latch.h>
16 15
 
17 16
 struct net_device;
18 17
 struct job_interface;

+ 0
- 1
src/include/gpxe/tcp.h Datei anzeigen

@@ -9,7 +9,6 @@
9 9
  *
10 10
  */
11 11
 
12
-#include "latch.h"
13 12
 #include <gpxe/tcpip.h>
14 13
 
15 14
 /**

+ 32
- 0
src/include/gpxe/timer.h Datei anzeigen

@@ -0,0 +1,32 @@
1
+#ifndef	GPXE_TIMER_H
2
+#define GPXE_TIMER_H
3
+
4
+#include <stddef.h>
5
+
6
+typedef uint32_t tick_t;
7
+
8
+#define MSECS_IN_SEC (1000)
9
+#define USECS_IN_SEC (1000*1000)
10
+#define USECS_IN_MSEC (1000)
11
+
12
+#define	TICKS_PER_SEC	USECS_IN_SEC
13
+
14
+tick_t currticks(void);
15
+
16
+void generic_currticks_udelay(unsigned int usecs);
17
+
18
+struct timer {
19
+	/* Returns zero on successful initialisation. */
20
+	int (*init) (void);
21
+
22
+	/* Return the current time, int mictoseconds since the beginning. */
23
+	tick_t (*currticks) (void);
24
+
25
+	/* Sleep for a few useconds. */
26
+	void (*udelay) (unsigned int useconds);
27
+};
28
+
29
+#define __timer(order) __table (struct timer, timers, order)
30
+
31
+#endif	/* GPXE_TIMER_H */
32
+

+ 0
- 61
src/include/timer.h Datei anzeigen

@@ -1,61 +0,0 @@
1
-/* Defines for routines to implement a low-overhead timer for drivers */
2
-
3
- /*
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License as
6
- * published by the Free Software Foundation; either version 2, or (at
7
- * your option) any later version.
8
- */
9
-
10
-#ifndef	TIMER_H
11
-#define TIMER_H
12
-
13
-/* Ports for the 8254 timer chip */
14
-#define	TIMER2_PORT	0x42
15
-#define	TIMER_MODE_PORT	0x43
16
-
17
-/* Meaning of the mode bits */
18
-#define	TIMER0_SEL	0x00
19
-#define	TIMER1_SEL	0x40
20
-#define	TIMER2_SEL	0x80
21
-#define	READBACK_SEL	0xC0
22
-
23
-#define	LATCH_COUNT	0x00
24
-#define	LOBYTE_ACCESS	0x10
25
-#define	HIBYTE_ACCESS	0x20
26
-#define	WORD_ACCESS	0x30
27
-
28
-#define	MODE0		0x00
29
-#define	MODE1		0x02
30
-#define	MODE2		0x04
31
-#define	MODE3		0x06
32
-#define	MODE4		0x08
33
-#define	MODE5		0x0A
34
-
35
-#define	BINARY_COUNT	0x00
36
-#define	BCD_COUNT	0x01
37
-
38
-/* Timers tick over at this rate */
39
-#define CLOCK_TICK_RATE	1193180U
40
-#define	TICKS_PER_MS	(CLOCK_TICK_RATE/1000)
41
-
42
-/* Parallel Peripheral Controller Port B */
43
-#define	PPC_PORTB	0x61
44
-
45
-/* Meaning of the port bits */
46
-#define	PPCB_T2OUT	0x20	/* Bit 5 */
47
-#define	PPCB_SPKR	0x02	/* Bit 1 */
48
-#define	PPCB_T2GATE	0x01	/* Bit 0 */
49
-
50
-/* Ticks must be between 0 and 65535 (0 == 65536)
51
-   because it is a 16 bit counter */
52
-extern void load_timer2(unsigned int ticks);
53
-extern inline int timer2_running(void);
54
-extern void waiton_timer2(unsigned int ticks);
55
-
56
-extern void ndelay(unsigned int nsecs);
57
-extern void udelay(unsigned int usecs);
58
-extern void mdelay(unsigned int msecs);
59
-
60
-
61
-#endif	/* TIMER_H */

+ 7
- 1
src/include/unistd.h Datei anzeigen

@@ -4,7 +4,7 @@
4 4
 #include <stddef.h>
5 5
 #include <stdarg.h>
6 6
 
7
-extern unsigned int sleep ( unsigned int seconds );
7
+unsigned int sleep ( unsigned int seconds );
8 8
 extern int execv ( const char *command, char * const argv[] );
9 9
 
10 10
 /**
@@ -22,4 +22,10 @@ extern int execv ( const char *command, char * const argv[] );
22 22
 		rc;							\
23 23
 	} )
24 24
 
25
+void udelay(unsigned int usecs);
26
+void mdelay(unsigned int msecs);
27
+
28
+#define usleep(x) udelay(x)
29
+
30
+
25 31
 #endif /* _UNISTD_H */

+ 1
- 1
src/net/retry.c Datei anzeigen

@@ -17,7 +17,7 @@
17 17
  */
18 18
 
19 19
 #include <stddef.h>
20
-#include <latch.h>
20
+#include <gpxe/timer.h>
21 21
 #include <gpxe/list.h>
22 22
 #include <gpxe/process.h>
23 23
 #include <gpxe/init.h>

+ 1
- 1
src/net/tcp.c Datei anzeigen

@@ -4,7 +4,7 @@
4 4
 #include <assert.h>
5 5
 #include <errno.h>
6 6
 #include <byteswap.h>
7
-#include <timer.h>
7
+#include <gpxe/timer.h>
8 8
 #include <gpxe/iobuf.h>
9 9
 #include <gpxe/malloc.h>
10 10
 #include <gpxe/retry.h>

+ 1
- 0
src/net/udp/dhcp.c Datei anzeigen

@@ -33,6 +33,7 @@
33 33
 #include <gpxe/ip.h>
34 34
 #include <gpxe/uuid.h>
35 35
 #include <gpxe/dhcp.h>
36
+#include <gpxe/timer.h>
36 37
 
37 38
 /** @file
38 39
  *

Laden…
Abbrechen
Speichern