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)
 
 FILE_SECBOOT (PERMITTED)
 
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  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ currticks()

unsigned long currticks ( void  )

Get current system time in ticks.

Return values
ticksCurrent time, in ticks

Definition at line 43 of file timer.c.

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

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_poll_eq(), hermon_set_port_type(), hunt_mcdi_request_poll(), hunt_poll(), monojob_wait(), neighbour_tx(), neighbour_tx_queue(), net80211_probe_start(), net80211_probe_step(), net80211_rx_frag(), net80211_step_associate(), null_now(), nv_mgmt_get_version(), peerblk_timestamp(), pxe_menu_prompt_and_select(), 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 61 of file timer.c.

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

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(), atl2_hw_finish_ack_(), atl2_hw_reset(), atl_hw_read_mem(), 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(), bnxt_er_task(), bnxt_rst_er_registers(), cgem_mii_wait(), 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(), hermon_cmd_wait(), 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(), rdc_mii_read(), rdc_mii_write(), 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(), wait_resp(), 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 79 of file timer.c.

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

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(), atl_hw_read_mem(), atl_hw_reset(), atl_hw_reset_flb_(), atl_hw_reset_rbl_(), axge_probe(), bios_mp_ipi(), bnx2_fw_sync(), bnx2_probe(), bnx2_reset_chip(), bnx2_set_power_state_0(), bnx2_transmit(), bnxt_get_phy_link(), dmfe_init_dm910x(), dwmac_reset(), dwusb_probe(), 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_wait(), falcon_fini_resources(), falcon_init_sram(), falcon_init_xmac(), falcon_reset(), falcon_tenxpress_phy_init(), golan_cmd_wait(), gve_admin_wait(), gve_reset(), hermon_reset(), hermon_set_port_type(), hub_enable(), hub_open(), hunt_clear_udp_tunnel_ports(), hv_wait_for_message(), ice_dump_tx(), 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(), intelxlvf_admin_command(), intelxlvf_reset_wait(), 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(), mp_max_cpuid(), myson_reload_config(), myson_soft_reset(), myson_wait_idle(), natsemi_reload_config(), natsemi_soft_reset(), netvsc_control(), ns16550_transmit(), nv_mgmt_acquire_sema(), nv_mgmt_get_version(), pci_reset(), 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(), rdc_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(), short_hwrm_cmd_req(), sis190_phy_task(), sis190_read_eeprom(), smc_phy_configure(), smsc75xx_reset(), smscusb_eeprom_wait(), smscusb_mii_wait(), smscusb_otp_power_up(), smscusb_otp_wait(), snpnet_open(), 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(), ucode_update_all(), 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_disable(), 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 100 of file timer.c.

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

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 123 of file timer.c.

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

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 134 of file timer.c.

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

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 144 of file timer.c.

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

References NULL, and sleep_interruptible().

Referenced by sandev_command().

◆ timer_probe()

static void timer_probe ( void  )
static

Find a working timer.

Definition at line 153 of file timer.c.

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

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 36 of file timer.c.

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