iPXE
Functions | Variables
timer.c File Reference
#include <string.h>
#include <ipxe/process.h>
#include <ipxe/console.h>
#include <ipxe/keys.h>
#include <ipxe/nap.h>
#include <ipxe/init.h>
#include <ipxe/timer.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
unsigned long currticks (void)
 Get current system time in ticks. More...
 
void udelay (unsigned long usecs)
 Delay for a fixed number of microseconds. More...
 
void mdelay (unsigned long msecs)
 Delay for a fixed number of milliseconds. More...
 
static unsigned int sleep_interruptible (unsigned int secs, int(*interrupted)(void))
 Sleep (possibly interruptibly) for a fixed number of seconds. More...
 
static int keypress_interrupted (void)
 Check if sleep has been interrupted by keypress. More...
 
unsigned int sleep (unsigned int secs)
 Sleep (interruptibly) for a fixed number of seconds. More...
 
void sleep_fixed (unsigned int secs)
 Sleep (uninterruptibly) for a fixed number of seconds. More...
 
static void timer_probe (void)
 Find a working timer. More...
 
struct init_fn timer_init_fn __init_fn (INIT_EARLY)
 Timer initialisation function. More...
 
 REQUIRING_SYMBOL (timer_init_fn)
 
 REQUIRE_OBJECT (config_timer)
 

Variables

static struct timertimer
 Current timer. More...
 

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ currticks()

unsigned long currticks ( void  )

Get current system time in ticks.

Return values
ticksCurrent time, in ticks

Definition at line 42 of file timer.c.

42  {
43 
44  /* Guard against use during early initialisation */
45  if ( ! timer ) {
46  DBGC ( &timer, "TIMER currticks() called before initialisation "
47  "from %p\n", __builtin_return_address ( 0 ) );
48  return 0;
49  }
50 
51  /* Use selected timer */
52  return timer->currticks();
53 }
#define DBGC(...)
Definition: compiler.h:505
A timer.
Definition: timer.h:28
unsigned long(* currticks)(void)
Get current system time in ticks.
Definition: timer.h:42

References timer::currticks, and DBGC.

Referenced by ath5k_attach(), ath5k_poll(), ath_ani_calibrate(), ath_hw_pll_work(), ath_isr(), ath_set_channel(), ath_start_ani(), ath_tx_complete_poll_work(), ath_tx_start_dma(), control_dc_dc(), cs89x0_reset(), cs89x0_transmit(), davicom_media_chk(), davicom_reset(), davicom_transmit(), davicom_wait(), detect_tp(), dhcp_discovery_expired(), dhcp_discovery_rx(), dhcp_proxy_expired(), dhcp_pxebs_expired(), dhcp_set_state(), dhcpv6_tx(), epic100_transmit(), eth_rx_overrun(), getchar_timeout(), hermon_set_port_type(), hunt_mcdi_request_poll(), hunt_poll(), monojob_wait(), net80211_probe_start(), net80211_probe_step(), net80211_rx_frag(), net80211_step_associate(), nv_mgmt_get_version(), peerblk_timestamp(), pxe_menu_prompt_and_select(), random(), retry_poll(), send_test_pkt(), sis900_transmit(), sleep_interruptible(), smc9000_transmit(), start_dhcpv6(), start_timer_fixed(), stop_timer(), sundance_transmit(), t3c515_wait(), tcp_shutdown(), tcp_xmit_sack(), time_exec(), timer_expired(), tlan_transmit(), tulip_reset(), tulip_transmit(), tulip_wait(), w89c840_transmit(), wait_eeprom_ready(), and xenbus_backend_wait().

◆ udelay()

void udelay ( unsigned long  usecs)

Delay for a fixed number of microseconds.

Parameters
usecsNumber of microseconds for which to delay

Definition at line 60 of file timer.c.

60  {
61 
62  /* Guard against use during early initialisation */
63  if ( ! timer ) {
64  DBGC ( &timer, "TIMER udelay() called before initialisation "
65  "from %p\n", __builtin_return_address ( 0 ) );
66  return;
67  }
68 
69  /* Use selected timer */
70  timer->udelay ( usecs );
71 }
#define DBGC(...)
Definition: compiler.h:505
A timer.
Definition: timer.h:28
void(* udelay)(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.h:48

References DBGC, and timer::udelay.

Referenced by __gm_phy_read(), __tg3_set_rx_mode(), __vxge_hw_device_register_poll(), __xm_phy_read(), _tw32_flush(), a3c90x_internal_WaitForEeprom(), amd8111e_read_phy(), ar5008_hw_init_bb(), ar5008_hw_process_ini(), ar5008_hw_rfbus_done(), ar9002_hw_configpcipowersave(), ar9002_olc_init(), ar9003_get_pll_sqsum_dvc(), ar9003_hw_init_bb(), ar9003_hw_init_cal(), ar9003_hw_internal_regulator_apply(), ar9003_hw_rfbus_done(), ar9271_hw_pa_cal(), ar9285_hw_pa_cal(), ath5k_hw_eeprom_read(), ath5k_hw_nic_reset(), ath5k_hw_nic_wakeup(), ath5k_hw_reset(), ath5k_hw_rf5110_calibrate(), ath5k_hw_stop_rx_dma(), ath5k_hw_stop_tx_dma(), ath5k_hw_wake(), ath9k_hw_abort_tx_dma(), ath9k_hw_analog_shift_regwrite(), ath9k_hw_analog_shift_rmw(), ath9k_hw_chip_test(), ath9k_hw_def_set_board_values(), ath9k_hw_init_pll(), ath9k_hw_loadnf(), ath9k_hw_reset(), ath9k_hw_set_power_awake(), ath9k_hw_set_reset(), ath9k_hw_set_reset_power_on(), ath9k_hw_set_reset_reg(), ath9k_hw_stopdmarecv(), ath9k_hw_wait(), atl1e_read_phy_reg(), atl1e_write_phy_reg(), b44_phy_reset(), b44_wait_bit(), bflush(), bnx2_init_chip(), bnx2_read_phy(), bnx2_reset_chip(), bnx2_reset_phy(), bnx2_setup_copper_phy(), bnx2_setup_serdes_phy(), bnx2_write_phy(), deactivate_t509_device(), dm96xx_reset(), dmfe_disable(), dmfe_init_dm910x(), eepro_transmit(), eeprom_rdy(), eisa_device_enabled(), falcon_gmii_wait(), falcon_mdio_read(), falcon_mdio_write(), falcon_reset_xaui(), falcon_reset_xmac(), falcon_setup_nic(), falcon_spi_wait(), falcon_tenxpress_check_c11(), falcon_txc_logic_reset(), fiber_autoneg(), flexboot_nodnic_complete_all_tx(), forcedeth_open(), genesis_mac_init(), gm_phy_write(), hfa384x_docmd_wait(), hfa384x_prepare_bap(), hfa384x_wait_for_event(), hunt_mcdi_request_poll(), i2c_delay(), ifec_mdio_read(), ifec_mdio_write(), ifec_reset(), ifec_scb_cmd_wait(), intelxl_close(), intelxl_enable_ring(), intelxl_open(), is_pmu_set(), isapnp_delay(), jme_check_link(), jme_mdio_read(), jme_mdio_write(), jme_reset_mac_processor(), linda_ib_epb_request(), linda_ib_epb_wait(), linda_init_ib_serdes(), linda_link_state_check(), mdelay(), mentormac_init(), mentormac_reset(), mii_bit_xfer(), mii_rw(), mlx_utils_delay_in_us_priv(), myri10ge_command(), net80211_probe_step(), nii_delay(), nv_mac_reset(), nv_mgmt_acquire_sema(), nv_stop_rx(), nv_stop_tx(), nv_txrx_reset(), phy_read_1bit(), phy_write_1bit(), qib7322_ahb_wait(), qib7322_link_state_check(), read_srom_word(), realtek_mii_read(), realtek_mii_write(), reg_delay(), rhine_mii_autopoll(), rhine_mii_read(), rhine_mii_write(), rhine_reload_eeprom(), rhine_reset(), rtl818x_probe(), rtl818x_spi_write_bit(), rtl8225_read(), rtl8225_write(), sfe4001_init(), sis190_get_mac_addr_from_apc(), sis190_mii_probe_88e1111_fixup(), sis190_phy_task(), sis96x_get_mac_addr(), smc_read_phy_register(), smc_write_phy_register(), smsc95xx_reset(), spi_bit_delay(), spi_wait(), sundance_probe(), t509_enable(), t509_id_read_eeprom(), t509_poll(), t515_poll(), t595_disable(), t595_poll(), t595_reset(), t5x9_disable(), tg3_abort_hw(), tg3_bmcr_reset(), tg3_chip_reset(), tg3_clear_mac_status(), tg3_do_test_dma(), tg3_fiber_aneg_smachine(), tg3_get_invariants(), tg3_init_5401phy_dsp(), tg3_init_bcm8002(), tg3_issue_otp_command(), tg3_nvram_exec_cmd(), tg3_nvram_lock(), tg3_phy_reset(), tg3_poll_fw(), tg3_readphy(), tg3_reset_hw(), tg3_setup_copper_phy(), tg3_setup_fiber_by_hand(), tg3_setup_fiber_hw_autoneg(), tg3_setup_fiber_mii_phy(), tg3_setup_fiber_phy(), tg3_stop_block(), tg3_wait_for_event_ack(), tg3_writephy(), TLan_FinishReset(), TLan_PhyFinishAutoNeg(), tlan_probe(), TLan_ResetAdapter(), update_cr6(), usleep(), velocity_autopoll_start(), velocity_autopoll_stop(), velocity_mii_read(), velocity_mii_write(), velocity_reload_eeprom(), velocity_reset(), vxsetlink(), and xm_phy_write().

◆ mdelay()

void mdelay ( unsigned long  msecs)

Delay for a fixed number of milliseconds.

Parameters
msecsNumber of milliseconds for which to delay

Definition at line 78 of file timer.c.

78  {
79 
80  /* Guard against use during early initialisation */
81  if ( ! timer ) {
82  DBGC ( &timer, "TIMER mdelay() called before initialisation "
83  "from %p\n", __builtin_return_address ( 0 ) );
84  return;
85  }
86 
87  /* Delay for specified number of milliseconds */
88  while ( msecs-- )
89  udelay ( 1000 );
90 }
#define DBGC(...)
Definition: compiler.h:505
A timer.
Definition: timer.h:28
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60

References DBGC, and udelay().

Referenced by __mdio_cmd(), _wgetc(), acpi_poweroff(), amd8111e_wait_tx_ring(), arbel_cmd_wait(), arbel_reset(), ath5k_hw_attach(), ath5k_hw_nic_wakeup(), ath5k_hw_noise_floor_calibration(), ath5k_hw_radio_revision(), ath5k_hw_reset(), ath5k_hw_rf5110_calibrate(), ath5k_hw_rf5110_channel(), atl1e_down(), atl1e_get_permanent_address(), atl1e_phy_commit(), atl1e_phy_init(), atl1e_reset_hw(), atl1e_setup_pcicmd(), axge_probe(), bnx2_fw_sync(), bnx2_probe(), bnx2_reset_chip(), bnx2_set_power_state_0(), bnx2_transmit(), dmfe_init_dm910x(), efab_init_mac(), efi_usb_sync_transfer(), ehci_async_del(), ehci_legacy_claim(), ehci_periodic_del(), ehci_reset(), ehci_root_enable(), ehci_root_open(), ehci_stop(), ena_admin(), ena_reset(), falcon_fini_resources(), falcon_init_sram(), falcon_init_xmac(), falcon_reset(), falcon_tenxpress_phy_init(), golan_cmd_wait(), hermon_cmd_wait(), hermon_reset(), hub_enable(), hub_open(), hunt_clear_udp_tunnel_ports(), hv_wait_for_message(), icplus_read_eeprom(), icplus_reset(), ifec_net_open(), igbvf_close(), igbvf_configure_tx(), intel_disable_ring(), intel_init_eeprom(), intel_read_eeprom(), intel_reset(), intelvf_mbox_msg(), intelvf_mbox_wait(), intelx_reset(), intelxl_admin_command(), intelxl_context_dump(), intelxl_context_line(), intelxl_disable_ring(), intelxl_reset(), intelxlvf_admin_command(), intelxlvf_reset_admin(), intelxlvf_reset_flr(), intelxlvf_reset_wait_active(), intelxlvf_reset_wait_teardown(), jme_disable_rx_engine(), jme_disable_tx_engine(), jme_reload_eeprom(), lan78xx_reset(), linda_trim_ib(), mdio_clause45_reset_mmd(), mdio_clause45_wait_reset_mmds(), mii_reset(), mlx_utils_delay_in_ms_priv(), myson_reload_config(), myson_soft_reset(), myson_wait_idle(), natsemi_reload_config(), natsemi_soft_reset(), netvsc_control(), nv_mgmt_acquire_sema(), nv_mgmt_get_version(), pci_vpd_read_dword(), pci_vpd_write_dword(), phantom_clp_wait(), phantom_init_cmdpeg(), phantom_init_rcvpeg(), phantom_read_test_mem_block(), phantom_wait_for_cmd(), phy_init(), phy_reset(), qib7322_reset(), realtek_reset(), register_usb(), register_usb_hub(), rhine_open(), rndis_wait(), rtc_entropy_check(), rtl818x_init_hw(), rtl8225_rf_init(), rtl8225_rf_set_channel(), rtl8225_rf_set_tx_power(), rtl8225_rf_stop(), rtl8225x_rf_init(), rtl8225z2_rf_init(), rtl8225z2_rf_set_tx_power(), sfe4001_init(), sis190_phy_task(), sis190_read_eeprom(), smc_phy_configure(), smsc75xx_reset(), smscusb_eeprom_wait(), smscusb_mii_wait(), smscusb_otp_power_up(), smscusb_otp_wait(), t509_enable(), tg3_get_eeprom_hw_cfg(), tg3_nvram_read_using_eeprom(), tg3_poll_fw(), threewire_write(), TLan_FinishReset(), TLan_PhyFinishAutoNeg(), TLan_PhyPowerDown(), TLan_PhyPowerUp(), TLan_PhyReset(), TLan_PhyStartLink(), txnic_bgx_spu_init(), txnic_disable_cq(), txnic_disable_rq(), txnic_disable_sq(), uart_transmit(), uhci_async_del(), uhci_periodic_del(), uhci_reset(), uhci_root_enable(), uhci_stop(), undinet_probe(), usb_control(), vpm_reset(), write_grf5101(), write_max2820(), write_sa2400(), xhci_abort(), xhci_command(), xhci_legacy_claim(), xhci_reset(), xhci_root_enable(), xhci_root_open(), and xhci_stop().

◆ sleep_interruptible()

static unsigned int sleep_interruptible ( unsigned int  secs,
int(*)(void)  interrupted 
)
static

Sleep (possibly interruptibly) for a fixed number of seconds.

Parameters
secsNumber of seconds for which to delay
interruptedInterrupt checking method, or NULL
Return values
secsNumber of seconds remaining, if interrupted

Definition at line 99 of file timer.c.

100  {
101  unsigned long start = currticks();
102  unsigned long now;
103 
104  for ( ; secs ; secs-- ) {
105  while ( ( ( now = currticks() ) - start ) < TICKS_PER_SEC ) {
106  step();
107  if ( interrupted && interrupted() )
108  return secs;
109  cpu_nap();
110  }
111  start = now;
112  }
113 
114  return 0;
115 }
#define TICKS_PER_SEC
Number of ticks per second.
Definition: timer.h:15
uint32_t start
Starting offset.
Definition: netvsc.h:12
void cpu_nap(void)
Sleep until next CPU interrupt.
void step(void)
Single-step a single process.
Definition: process.c:98
unsigned long currticks(void)
Get current system time in ticks.
Definition: timer.c:42

References cpu_nap(), currticks(), start, step(), and TICKS_PER_SEC.

Referenced by sleep(), and sleep_fixed().

◆ keypress_interrupted()

static int keypress_interrupted ( void  )
static

Check if sleep has been interrupted by keypress.

Return values
interruptedSleep has been interrupted

Definition at line 122 of file timer.c.

122  {
123 
124  return ( iskey() && ( getchar() == CTRL_C ) );
125 }
#define CTRL_C
Definition: keys.h:20
int getchar(void)
Read a single character from any console.
Definition: console.c:82
int iskey(void)
Check for available input on any console.
Definition: console.c:127

References CTRL_C, getchar(), and iskey().

Referenced by sleep().

◆ sleep()

unsigned int sleep ( unsigned int  secs)

Sleep (interruptibly) for a fixed number of seconds.

Parameters
secsNumber of seconds for which to delay
Return values
secsNumber of seconds remaining, if interrupted

Definition at line 133 of file timer.c.

133  {
134 
135  return sleep_interruptible ( secs, keypress_interrupted );
136 }
static int keypress_interrupted(void)
Check if sleep has been interrupted by keypress.
Definition: timer.c:122
static unsigned int sleep_interruptible(unsigned int secs, int(*interrupted)(void))
Sleep (possibly interruptibly) for a fixed number of seconds.
Definition: timer.c:99

References keypress_interrupted(), and sleep_interruptible().

Referenced by sleep_exec(), and valert().

◆ sleep_fixed()

void sleep_fixed ( unsigned int  secs)

Sleep (uninterruptibly) for a fixed number of seconds.

Parameters
secsNumber of seconds for which to delay

Definition at line 143 of file timer.c.

143  {
144 
145  sleep_interruptible ( secs, NULL );
146 }
static unsigned int sleep_interruptible(unsigned int secs, int(*interrupted)(void))
Sleep (possibly interruptibly) for a fixed number of seconds.
Definition: timer.c:99
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References NULL, and sleep_interruptible().

Referenced by sandev_command().

◆ timer_probe()

static void timer_probe ( void  )
static

Find a working timer.

Definition at line 152 of file timer.c.

152  {
153  int rc;
154 
155  /* Use first working timer */
157  if ( ( timer->probe == NULL ) ||
158  ( ( rc = timer->probe() ) == 0 ) ) {
159  DBGC ( &timer, "TIMER using %s\n", timer->name );
160  return;
161  }
162  DBGC ( &timer, "TIMER could not initialise %s: %s\n",
163  timer->name, strerror ( rc ) );
164  }
165 
166  /* This is a fatal error */
167  DBGC ( &timer, "TIMER found no working timers!\n" );
168  while ( 1 ) {}
169 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
A timer.
Definition: timer.h:28
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
int(* probe)(void)
Probe timer.
Definition: timer.h:36
const char * name
Name.
Definition: timer.h:30
#define TIMERS
Timer table.
Definition: timer.h:52
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References DBGC, for_each_table_entry, timer::name, NULL, timer::probe, rc, strerror(), and TIMERS.

◆ __init_fn()

struct init_fn timer_init_fn __init_fn ( INIT_EARLY  )

Timer initialisation function.

◆ REQUIRING_SYMBOL()

REQUIRING_SYMBOL ( timer_init_fn  )

◆ REQUIRE_OBJECT()

REQUIRE_OBJECT ( config_timer  )

Variable Documentation

◆ timer

struct timer* timer
static

Current timer.

Definition at line 35 of file timer.c.

Referenced by _wgetc(), retry_poll(), and t515_probe().