Linux Device Drivers

This documentation is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

For more details see the file COPYING in the source distribution of Linux.


Table of Contents

1. Driver Basics
Driver Entry and Exit points
Atomic and pointer manipulation
Delaying, scheduling, and timer routines
Wait queues and Wake events
High-resolution timers
Workqueues and Kevents
Internal Functions
Kernel objects manipulation
Kernel utility functions
Device Resource Management
2. Device drivers infrastructure
The Basic Device Driver-Model Structures
Device Drivers Base
Device Drivers Power Management
Device Drivers ACPI Support
Device drivers PnP support
Userspace IO devices
3. Parallel Port Devices
parport_yield — relinquish a parallel port temporarily
parport_yield_blocking — relinquish a parallel port temporarily
parport_wait_event — wait for an event on a parallel port
parport_wait_peripheral — wait for status lines to change in 35ms
parport_negotiate — negotiate an IEEE 1284 mode
parport_write — write a block of data to a parallel port
parport_read — read a block of data from a parallel port
parport_set_timeout — set the inactivity timeout for a device
parport_register_driver — register a parallel port device driver
parport_unregister_driver — deregister a parallel port device driver
parport_get_port — increment a port's reference count
parport_put_port — decrement a port's reference count
parport_register_port — register a parallel port
parport_announce_port — tell device drivers about a parallel port
parport_remove_port — deregister a parallel port
parport_register_device — register a device on a parallel port
parport_unregister_device — deregister a device on a parallel port
parport_find_number — find a parallel port by number
parport_find_base — find a parallel port by base address
parport_claim — claim access to a parallel port device
parport_claim_or_block — claim access to a parallel port device
parport_release — give up access to a parallel port device
parport_open — find a device by canonical device number
parport_close — close a device opened with parport_open
4. Message-based devices
Fusion message devices
I2O message devices
5. Sound Devices
snd_register_device — Register the ALSA device file for the card
snd_printk — printk wrapper
snd_printd — debug printk
snd_BUG — give a BUG warning message and stack trace
snd_BUG_ON — debugging check macro
snd_printdd — debug printk
register_sound_special_device — register a special sound node
register_sound_mixer — register a mixer device
register_sound_midi — register a midi device
register_sound_dsp — register a DSP device
unregister_sound_special — unregister a special sound device
unregister_sound_mixer — unregister a mixer
unregister_sound_midi — unregister a midi device
unregister_sound_dsp — unregister a DSP device
snd_pcm_playback_ready — check whether the playback buffer is available
snd_pcm_capture_ready — check whether the capture buffer is available
snd_pcm_playback_data — check whether any data exists on the playback buffer
snd_pcm_playback_empty — check whether the playback buffer is empty
snd_pcm_capture_empty — check whether the capture buffer is empty
snd_pcm_format_cpu_endian — Check the PCM format is CPU-endian
snd_pcm_lib_alloc_vmalloc_buffer — allocate virtual DMA buffer
snd_pcm_lib_alloc_vmalloc_32_buffer — allocate 32-bit-addressable buffer
snd_pcm_new_stream — create a new PCM stream
snd_pcm_new — create a new PCM instance
snd_device_new — create an ALSA device component
snd_device_free — release the device from the card
snd_device_register — register the device
snd_iprintf — printf on the procfs buffer
snd_info_get_line — read one line from the procfs buffer
snd_info_get_str — parse a string token
snd_info_create_module_entry — create an info entry for the given module
snd_info_create_card_entry — create an info entry for the given card
snd_card_proc_new — create an info entry for the given card
snd_info_free_entry — release the info entry
snd_info_register — register the info entry
snd_rawmidi_receive — receive the input data from the device
snd_rawmidi_transmit_empty — check whether the output buffer is empty
snd_rawmidi_transmit_peek — copy data from the internal buffer
snd_rawmidi_transmit_ack — acknowledge the transmission
snd_rawmidi_transmit — copy from the buffer to the device
snd_rawmidi_new — create a rawmidi instance
snd_rawmidi_set_ops — set the rawmidi operators
snd_request_card — try to load the card module
snd_lookup_minor_data — get user data of a registered device
snd_register_device_for_dev — Register the ALSA device file for the card
snd_unregister_device — unregister the device on the given card
copy_to_user_fromio — copy data from mmio-space to user-space
copy_from_user_toio — copy data from user-space to mmio-space
snd_pcm_lib_preallocate_free_for_all — release all pre-allocated buffers on the pcm
snd_pcm_lib_preallocate_pages — pre-allocation for the given DMA type
snd_pcm_lib_preallocate_pages_for_all — pre-allocation for continuous memory type (all substreams)
snd_pcm_sgbuf_ops_page — get the page struct at the given offset
snd_pcm_lib_malloc_pages — allocate the DMA buffer
snd_pcm_lib_free_pages — release the allocated DMA buffer.
snd_pcm_lib_free_vmalloc_buffer — free vmalloc buffer
snd_pcm_lib_get_vmalloc_page — map vmalloc buffer offset to page struct
snd_card_create — create and initialize a soundcard structure
snd_card_disconnect — disconnect all APIs from the file-operations (user space)
snd_card_set_id — set card identification name
snd_card_register — register the soundcard
snd_component_add — add a component string
snd_card_file_add — add the file to the file list of the card
snd_card_file_remove — remove the file from the file list
snd_power_wait — wait until the power-state is changed.
snd_dma_program — program an ISA DMA transfer
snd_dma_disable — stop the ISA DMA transfer
snd_dma_pointer — return the current pointer to DMA transfer buffer in bytes
snd_ctl_new1 — create a control instance from the template
snd_ctl_free_one — release the control instance
snd_ctl_add — add the control instance to the card
snd_ctl_replace — replace the control instance of the card
snd_ctl_remove — remove the control from the card and release it
snd_ctl_remove_id — remove the control of the given id and release it
snd_ctl_activate_id — activate/inactivate the control of the given id
snd_ctl_rename_id — replace the id of a control on the card
snd_ctl_find_numid — find the control instance with the given number-id
snd_ctl_find_id — find the control instance with the given id
snd_ctl_enum_info — fills the info structure for an enumerated control
snd_pcm_set_ops — set the PCM operators
snd_pcm_set_sync — set the PCM sync id
snd_interval_refine — refine the interval value of configurator
snd_interval_ratnum — refine the interval value
snd_interval_list — refine the interval value from the list
snd_pcm_hw_rule_add — add the hw-constraint rule
snd_pcm_hw_constraint_integer — apply an integer constraint to an interval
snd_pcm_hw_constraint_minmax — apply a min/max range constraint to an interval
snd_pcm_hw_constraint_list — apply a list of constraints to a parameter
snd_pcm_hw_constraint_ratnums — apply ratnums constraint to a parameter
snd_pcm_hw_constraint_ratdens — apply ratdens constraint to a parameter
snd_pcm_hw_constraint_msbits — add a hw constraint msbits rule
snd_pcm_hw_constraint_step — add a hw constraint step rule
snd_pcm_hw_constraint_pow2 — add a hw constraint power-of-2 rule
snd_pcm_hw_param_value — return params field var value
snd_pcm_hw_param_first — refine config space and return minimum value
snd_pcm_hw_param_last — refine config space and return maximum value
snd_pcm_lib_ioctl — a generic PCM ioctl callback
snd_pcm_period_elapsed — update the pcm status for the next period
snd_hwdep_new — create a new hwdep instance
snd_pcm_stop — try to stop all running streams in the substream group
snd_pcm_suspend — trigger SUSPEND to all linked streams
snd_pcm_suspend_all — trigger SUSPEND to all substreams in the given pcm
snd_malloc_pages — allocate pages with the given size
snd_free_pages — release the pages
snd_dma_alloc_pages — allocate the buffer area according to the given type
snd_dma_alloc_pages_fallback — allocate the buffer area according to the given type with fallback
snd_dma_free_pages — release the allocated buffer
snd_dma_get_reserved_buf — get the reserved buffer for the given device
snd_dma_reserve_buf — reserve the buffer
6. 16x50 UART Driver
uart_handle_dcd_change — handle a change of carrier detect state
uart_handle_cts_change — handle a change of clear-to-send state
uart_update_timeout — update per-port FIFO timeout.
uart_get_baud_rate — return baud rate for a particular port
uart_get_divisor — return uart clock divisor
uart_parse_options — Parse serial port baud/parity/bits/flow contro.
uart_set_options — setup the serial console parameters
uart_register_driver — register a driver with the uart core layer
uart_unregister_driver — remove a driver from the uart core layer
uart_add_one_port — attach a driver-defined port structure
uart_remove_one_port — detach a driver defined port structure
serial8250_suspend_port — suspend one serial port
serial8250_resume_port — resume one serial port
serial8250_register_port — register a serial port
serial8250_unregister_port — remove a 16x50 serial port at runtime
7. Frame Buffer Library
Frame Buffer Memory
Frame Buffer Colormap
Frame Buffer Video Mode Database
Frame Buffer Macintosh Video Mode Database
Frame Buffer Fonts
8. Input Subsystem
Input core
Multitouch Library
Polled input devices
Matrix keyboars/keypads
Sparse keymap support
9. Serial Peripheral Interface (SPI)
struct spi_device — Master side proxy for an SPI slave device
struct spi_driver — Host side protocol driver
spi_unregister_driver — reverse effect of spi_register_driver
struct spi_master — interface to SPI master controller
struct spi_transfer — a read/write buffer pair
struct spi_message — one multi-segment SPI transaction
spi_write — SPI synchronous write
spi_read — SPI synchronous read
spi_w8r8 — SPI synchronous 8 bit write followed by 8 bit read
spi_w8r16 — SPI synchronous 8 bit write followed by 16 bit read
struct spi_board_info — board-specific template for a SPI device
spi_register_board_info — register SPI devices for a given board
spi_register_driver — register a SPI driver
spi_alloc_device — Allocate a new SPI device
spi_add_device — Add spi_device allocated with spi_alloc_device
spi_new_device — instantiate one new SPI device
spi_alloc_master — allocate SPI master controller
spi_register_master — register SPI master controller
spi_unregister_master — unregister SPI master controller
spi_busnum_to_master — look up master associated with bus_num
spi_setup — setup SPI mode and clock rate
spi_async — asynchronous SPI transfer
spi_async_locked — version of spi_async with exclusive bus usage
spi_sync — blocking/synchronous SPI data transfers
spi_sync_locked — version of spi_sync with exclusive bus usage
spi_bus_lock — obtain a lock for exclusive SPI bus usage
spi_bus_unlock — release the lock for exclusive SPI bus usage
spi_write_then_read — SPI synchronous write followed by read
10. I2C and SMBus Subsystem
struct i2c_driver — represent an I2C device driver
struct i2c_client — represent an I2C slave device
struct i2c_board_info — template for device creation
I2C_BOARD_INFO — macro used to list an i2c device and its address
struct i2c_msg — an I2C transaction segment beginning with START
i2c_register_board_info — statically declare I2C devices
i2c_verify_client — return parameter as i2c_client, or NULL
i2c_lock_adapter — Get exclusive access to an I2C bus segment
i2c_unlock_adapter — Release exclusive access to an I2C bus segment
i2c_new_device — instantiate an i2c device
i2c_unregister_device — reverse effect of i2c_new_device
i2c_new_dummy — return a new i2c device bound to a dummy driver
i2c_add_adapter — declare i2c adapter, use dynamic bus number
i2c_add_numbered_adapter — declare i2c adapter, use static bus number
i2c_del_adapter — unregister I2C adapter
i2c_del_driver — unregister I2C driver
i2c_use_client — increments the reference count of the i2c client structure
i2c_release_client — release a use of the i2c client structure
i2c_transfer — execute a single or combined I2C message
i2c_master_send — issue a single I2C message in master transmit mode
i2c_master_recv — issue a single I2C message in master receive mode
i2c_smbus_read_byte — SMBus receive byte protocol
i2c_smbus_write_byte — SMBus send byte protocol
i2c_smbus_read_byte_data — SMBus read byte protocol
i2c_smbus_write_byte_data — SMBus write byte protocol
i2c_smbus_read_word_data — SMBus read word protocol
i2c_smbus_write_word_data — SMBus write word protocol
i2c_smbus_process_call — SMBus process call protocol
i2c_smbus_read_block_data — SMBus block read protocol
i2c_smbus_write_block_data — SMBus block write protocol
i2c_smbus_xfer — execute SMBus protocol operations

Chapter 1. Driver Basics

Driver Entry and Exit points

Name

module_init — driver initialization entry point

Synopsis

module_init (x); 
x;
 

Arguments

x

function to be run at kernel boot time or module insertion

Description

module_init will either be called during do_initcalls (if builtin) or at module insertion time (if a module). There can only be one per module.


Name

module_exit — driver exit entry point

Synopsis

module_exit (x); 
x;
 

Arguments

x

function to be run when driver is removed

Description

module_exit will wrap the driver clean-up code with cleanup_module when used with rmmod when the driver is a module. If the driver is statically compiled into the kernel, module_exit has no effect. There can only be one per module.

Atomic and pointer manipulation

Name

atomic_read — read atomic variable

Synopsis

int atomic_read (v); 
const atomic_t * v;
 

Arguments

v

pointer of type atomic_t

Description

Atomically reads the value of v.


Name

atomic_set — set atomic variable

Synopsis

void atomic_set (v,  
 i); 
atomic_t * v;
int i;
 

Arguments

v

pointer of type atomic_t

i

required value

Description

Atomically sets the value of v to i.


Name

atomic_add — add integer to atomic variable

Synopsis

void atomic_add (i,  
 v); 
int i;
atomic_t * v;
 

Arguments

i

integer value to add

v

pointer of type atomic_t

Description

Atomically adds i to v.


Name

atomic_sub — subtract integer from atomic variable

Synopsis

void atomic_sub (i,  
 v); 
int i;
atomic_t * v;
 

Arguments

i

integer value to subtract

v

pointer of type atomic_t

Description

Atomically subtracts i from v.


Name

atomic_sub_and_test — subtract value from variable and test result

Synopsis

int atomic_sub_and_test (i,  
 v); 
int i;
atomic_t * v;
 

Arguments

i

integer value to subtract

v

pointer of type atomic_t

Description

Atomically subtracts i from v and returns true if the result is zero, or false for all other cases.


Name

atomic_inc — increment atomic variable

Synopsis

void atomic_inc (v); 
atomic_t * v;
 

Arguments

v

pointer of type atomic_t

Description

Atomically increments v by 1.


Name

atomic_dec — decrement atomic variable

Synopsis

void atomic_dec (v); 
atomic_t * v;
 

Arguments

v

pointer of type atomic_t

Description

Atomically decrements v by 1.


Name

atomic_dec_and_test — decrement and test

Synopsis

int atomic_dec_and_test (v); 
atomic_t * v;
 

Arguments

v

pointer of type atomic_t

Description

Atomically decrements v by 1 and returns true if the result is 0, or false for all other cases.


Name

atomic_inc_and_test — increment and test

Synopsis

int atomic_inc_and_test (v); 
atomic_t * v;
 

Arguments

v

pointer of type atomic_t

Description

Atomically increments v by 1 and returns true if the result is zero, or false for all other cases.


Name

atomic_add_negative — add and test if negative

Synopsis

int atomic_add_negative (i,  
 v); 
int i;
atomic_t * v;
 

Arguments

i

integer value to add

v

pointer of type atomic_t

Description

Atomically adds i to v and returns true if the result is negative, or false when result is greater than or equal to zero.


Name

atomic_add_return — add integer and return

Synopsis

int atomic_add_return (i,  
 v); 
int i;
atomic_t * v;
 

Arguments

i

integer value to add

v

pointer of type atomic_t

Description

Atomically adds i to v and returns i + v


Name

atomic_sub_return — subtract integer and return

Synopsis

int atomic_sub_return (i,  
 v); 
int i;
atomic_t * v;
 

Arguments

i

integer value to subtract

v

pointer of type atomic_t

Description

Atomically subtracts i from v and returns v - i


Name

atomic_add_unless — add unless the number is already a given value

Synopsis

int atomic_add_unless (v,  
 a,  
 u); 
atomic_t * v;
int a;
int u;
 

Arguments

v

pointer of type atomic_t

a

the amount to add to v...

u

...unless v is equal to u.

Description

Atomically adds a to v, so long as v was not already u. Returns non-zero if v was not u, and zero otherwise.


Name

atomic_inc_short — increment of a short integer

Synopsis

short int atomic_inc_short (v); 
short int * v;
 

Arguments

v

pointer to type int

Description

Atomically adds 1 to v Returns the new value of u


Name

atomic_or_long — OR of two long integers

Synopsis

void atomic_or_long (v1,  
 v2); 
unsigned long * v1;
unsigned long v2;
 

Arguments

v1

pointer to type unsigned long

v2

pointer to type unsigned long

Description

Atomically ORs v1 and v2 Returns the result of the OR

Delaying, scheduling, and timer routines

Name

struct task_cputime — collected CPU time counts

Synopsis

struct task_cputime {
  cputime_t utime;
  cputime_t stime;
  unsigned long long sum_exec_runtime;
};  

Members

utime

time spent in user mode, in cputime_t units

stime

time spent in kernel mode, in cputime_t units

sum_exec_runtime

total time spent on the CPU, in nanoseconds

Description

This structure groups together three kinds of CPU time that are tracked for threads and thread groups. Most things considering CPU time want to group these counts together and treat all three of them in parallel.


Name

struct thread_group_cputimer — thread group interval timer counts

Synopsis

struct thread_group_cputimer {
  struct task_cputime cputime;
  int running;
  spinlock_t lock;
};  

Members

cputime

thread group interval timers.

running

non-zero when there are timers running and cputime receives updates.

lock

lock for fields in this struct.

Description

This structure contains the version of task_cputime, above, that is used for thread group CPU timer calculations.


Name

pid_alive — check that a task structure is not stale

Synopsis

int pid_alive (p); 
struct task_struct * p;
 

Arguments

p

Task structure to be checked.

Description

Test if a process is not yet dead (at most zombie state) If pid_alive fails, then pointers within the task structure can be stale and must not be dereferenced.


Name

is_global_init — check if a task structure is init

Synopsis

int is_global_init (tsk); 
struct task_struct * tsk;
 

Arguments

tsk

Task structure to be checked.

Description

Check if a task structure is the first user space task the kernel created.


Name

wake_up_process — Wake up a specific process

Synopsis

int wake_up_process (p); 
struct task_struct * p;
 

Arguments

p

The process to be woken up.

Description

Attempt to wake up the nominated process and move it to the set of runnable processes. Returns 1 if the process was woken up, 0 if it was already running.

It may be assumed that this function implies a write memory barrier before changing the task state if and only if any tasks are woken up.


Name

preempt_notifier_register — tell me when current is being preempted & rescheduled

Synopsis

void preempt_notifier_register (notifier); 
struct preempt_notifier * notifier;
 

Arguments

notifier

notifier struct to register


Name

preempt_notifier_unregister — no longer interested in preemption notifications

Synopsis

void preempt_notifier_unregister (notifier); 
struct preempt_notifier * notifier;
 

Arguments

notifier

notifier struct to unregister

Description

This is safe to call from within a preemption notifier.


Name

__wake_up — wake up threads blocked on a waitqueue.

Synopsis

void __wake_up (q,  
 mode,  
 nr_exclusive,  
 key); 
wait_queue_head_t * q;
unsigned int mode;
int nr_exclusive;
void * key;
 

Arguments

q

the waitqueue

mode

which threads

nr_exclusive

how many wake-one or wake-many threads to wake up

key

is directly passed to the wakeup function

Description

It may be assumed that this function implies a write memory barrier before changing the task state if and only if any tasks are woken up.


Name

__wake_up_sync_key — wake up threads blocked on a waitqueue.

Synopsis

void __wake_up_sync_key (q,  
 mode,  
 nr_exclusive,  
 key); 
wait_queue_head_t * q;
unsigned int mode;
int nr_exclusive;
void * key;
 

Arguments

q

the waitqueue

mode

which threads

nr_exclusive

how many wake-one or wake-many threads to wake up

key

opaque value to be passed to wakeup targets

Description

The sync wakeup differs that the waker knows that it will schedule away soon, so while the target thread will be woken up, it will not be migrated to another CPU - ie. the two threads are 'synchronized' with each other. This can prevent needless bouncing between CPUs.

On UP it can prevent extra preemption.

It may be assumed that this function implies a write memory barrier before changing the task state if and only if any tasks are woken up.


Name

complete — signals a single thread waiting on this completion

Synopsis

void complete (x); 
struct completion * x;
 

Arguments

x

holds the state of this particular completion

Description

This will wake up a single thread waiting on this completion. Threads will be awakened in the same order in which they were queued.

See also complete_all, wait_for_completion and related routines.

It may be assumed that this function implies a write memory barrier before changing the task state if and only if any tasks are woken up.


Name

complete_all — signals all threads waiting on this completion

Synopsis

void complete_all (x); 
struct completion * x;
 

Arguments

x

holds the state of this particular completion

Description

This will wake up all threads waiting on this particular completion event.

It may be assumed that this function implies a write memory barrier before changing the task state if and only if any tasks are woken up.


Name

wait_for_completion — waits for completion of a task

Synopsis

void __sched wait_for_completion (x); 
struct completion * x;
 

Arguments

x

holds the state of this particular completion

Description

This waits to be signaled for completion of a specific task. It is NOT interruptible and there is no timeout.

See also similar routines (i.e. wait_for_completion_timeout) with timeout and interrupt capability. Also see complete.


Name

wait_for_completion_timeout — waits for completion of a task (w/timeout)

Synopsis

unsigned long __sched wait_for_completion_timeout (x,  
 timeout); 
struct completion * x;
unsigned long timeout;
 

Arguments

x

holds the state of this particular completion

timeout

timeout value in jiffies

Description

This waits for either a completion of a specific task to be signaled or for a specified timeout to expire. The timeout is in jiffies. It is not interruptible.


Name

wait_for_completion_interruptible — waits for completion of a task (w/intr)

Synopsis

int __sched wait_for_completion_interruptible (x); 
struct completion * x;
 

Arguments

x

holds the state of this particular completion

Description

This waits for completion of a specific task to be signaled. It is interruptible.


Name

wait_for_completion_interruptible_timeout — waits for completion (w/(to,intr))

Synopsis

long __sched wait_for_completion_interruptible_timeout (x,  
 timeout); 
struct completion * x;
unsigned long timeout;
 

Arguments

x

holds the state of this particular completion

timeout

timeout value in jiffies

Description

This waits for either a completion of a specific task to be signaled or for a specified timeout to expire. It is interruptible. The timeout is in jiffies.


Name

wait_for_completion_killable — waits for completion of a task (killable)

Synopsis

int __sched wait_for_completion_killable (x); 
struct completion * x;
 

Arguments

x

holds the state of this particular completion

Description

This waits to be signaled for completion of a specific task. It can be interrupted by a kill signal.


Name

wait_for_completion_killable_timeout — waits for completion of a task (w/(to,killable))

Synopsis

long __sched wait_for_completion_killable_timeout (x,  
 timeout); 
struct completion * x;
unsigned long timeout;
 

Arguments

x

holds the state of this particular completion

timeout

timeout value in jiffies

Description

This waits for either a completion of a specific task to be signaled or for a specified timeout to expire. It can be interrupted by a kill signal. The timeout is in jiffies.


Name

try_wait_for_completion — try to decrement a completion without blocking

Synopsis

bool try_wait_for_completion (x); 
struct completion * x;
 

Arguments

x

completion structure

Returns

0 if a decrement cannot be done without blocking 1 if a decrement succeeded.

If a completion is being used as a counting completion, attempt to decrement the counter without blocking. This enables us to avoid waiting if the resource the completion is protecting is not available.


Name

completion_done — Test to see if a completion has any waiters

Synopsis

bool completion_done (x); 
struct completion * x;
 

Arguments

x

completion structure

Returns

0 if there are waiters (wait_for_completion in progress) 1 if there are no waiters.


Name

task_nice — return the nice value of a given task.

Synopsis

int task_nice (p); 
const struct task_struct * p;
 

Arguments

p

the task in question.


Name

sched_setscheduler — change the scheduling policy and/or RT priority of a thread.

Synopsis

int sched_setscheduler (p,  
 policy,  
 param); 
struct task_struct * p;
int policy;
const struct sched_param * param;
 

Arguments

p

the task in question.

policy

new policy.

param

structure containing the new RT priority.

Description

NOTE that the task may be already dead.


Name

yield — yield the current processor to other threads.

Synopsis

void __sched yield (void); 
void;
 

Arguments

void

no arguments

Description

This is a shortcut for kernel-space yielding - it marks the thread runnable and calls sys_sched_yield.


Name

yield_to — yield the current processor to another thread in your thread group, or accelerate that thread toward the processor it's on.

Synopsis

bool __sched yield_to (p,  
 preempt); 
struct task_struct * p;
bool preempt;
 

Arguments

p

target task

preempt

whether task preemption is allowed or not

Description

It's the caller's job to ensure that the target task struct can't go away on us before we can do any checks.

Returns true if we indeed boosted the target task.


Name

DECLARE_COMPLETION — declare and initialize a completion structure

Synopsis

DECLARE_COMPLETION (work); 
work;
 

Arguments

work

identifier for the completion structure

Description

This macro declares and initializes a completion structure. Generally used for static declarations. You should use the _ONSTACK variant for automatic variables.


Name

DECLARE_COMPLETION_ONSTACK — declare and initialize a completion structure

Synopsis

DECLARE_COMPLETION_ONSTACK (work); 
work;
 

Arguments

work

identifier for the completion structure

Description

This macro declares and initializes a completion structure on the kernel stack.


Name

init_completion — Initialize a dynamically allocated completion

Synopsis

void init_completion (x); 
struct completion * x;
 

Arguments

x

completion structure that is to be initialized

Description

This inline function will initialize a dynamically created completion structure.


Name

INIT_COMPLETION — reinitialize a completion structure

Synopsis

INIT_COMPLETION (x); 
x;
 

Arguments

x

completion structure to be reinitialized

Description

This macro should be used to reinitialize a completion structure so it can be reused. This is especially important after complete_all is used.


Name

__round_jiffies — function to round jiffies to a full second

Synopsis

unsigned long __round_jiffies (j,  
 cpu); 
unsigned long j;
int cpu;
 

Arguments

j

the time in (absolute) jiffies that should be rounded

cpu

the processor number on which the timeout will happen

Description

__round_jiffies rounds an absolute time in the future (in jiffies) up or down to (approximately) full seconds. This is useful for timers for which the exact time they fire does not matter too much, as long as they fire approximately every X seconds.

By rounding these timers to whole seconds, all such timers will fire at the same time, rather than at various times spread out. The goal of this is to have the CPU wake up less, which saves power.

The exact rounding is skewed for each processor to avoid all processors firing at the exact same time, which could lead to lock contention or spurious cache line bouncing.

The return value is the rounded version of the j parameter.


Name

__round_jiffies_relative — function to round jiffies to a full second

Synopsis

unsigned long __round_jiffies_relative (j,  
 cpu); 
unsigned long j;
int cpu;
 

Arguments

j

the time in (relative) jiffies that should be rounded

cpu

the processor number on which the timeout will happen

Description

__round_jiffies_relative rounds a time delta in the future (in jiffies) up or down to (approximately) full seconds. This is useful for timers for which the exact time they fire does not matter too much, as long as they fire approximately every X seconds.

By rounding these timers to whole seconds, all such timers will fire at the same time, rather than at various times spread out. The goal of this is to have the CPU wake up less, which saves power.

The exact rounding is skewed for each processor to avoid all processors firing at the exact same time, which could lead to lock contention or spurious cache line bouncing.

The return value is the rounded version of the j parameter.


Name

round_jiffies — function to round jiffies to a full second

Synopsis

unsigned long round_jiffies (j); 
unsigned long j;
 

Arguments

j

the time in (absolute) jiffies that should be rounded

Description

round_jiffies rounds an absolute time in the future (in jiffies) up or down to (approximately) full seconds. This is useful for timers for which the exact time they fire does not matter too much, as long as they fire approximately every X seconds.

By rounding these timers to whole seconds, all such timers will fire at the same time, rather than at various times spread out. The goal of this is to have the CPU wake up less, which saves power.

The return value is the rounded version of the j parameter.


Name

round_jiffies_relative — function to round jiffies to a full second

Synopsis

unsigned long round_jiffies_relative (j); 
unsigned long j;
 

Arguments

j

the time in (relative) jiffies that should be rounded

Description

round_jiffies_relative rounds a time delta in the future (in jiffies) up or down to (approximately) full seconds. This is useful for timers for which the exact time they fire does not matter too much, as long as they fire approximately every X seconds.

By rounding these timers to whole seconds, all such timers will fire at the same time, rather than at various times spread out. The goal of this is to have the CPU wake up less, which saves power.

The return value is the rounded version of the j parameter.


Name

__round_jiffies_up — function to round jiffies up to a full second

Synopsis

unsigned long __round_jiffies_up (j,  
 cpu); 
unsigned long j;
int cpu;
 

Arguments

j

the time in (absolute) jiffies that should be rounded

cpu

the processor number on which the timeout will happen

Description

This is the same as __round_jiffies except that it will never round down. This is useful for timeouts for which the exact time of firing does not matter too much, as long as they don't fire too early.


Name

__round_jiffies_up_relative — function to round jiffies up to a full second

Synopsis

unsigned long __round_jiffies_up_relative (j,  
 cpu); 
unsigned long j;
int cpu;
 

Arguments

j

the time in (relative) jiffies that should be rounded

cpu

the processor number on which the timeout will happen

Description

This is the same as __round_jiffies_relative except that it will never round down. This is useful for timeouts for which the exact time of firing does not matter too much, as long as they don't fire too early.


Name

round_jiffies_up — function to round jiffies up to a full second

Synopsis

unsigned long round_jiffies_up (j); 
unsigned long j;
 

Arguments

j

the time in (absolute) jiffies that should be rounded

Description

This is the same as round_jiffies except that it will never round down. This is useful for timeouts for which the exact time of firing does not matter too much, as long as they don't fire too early.


Name

round_jiffies_up_relative — function to round jiffies up to a full second

Synopsis

unsigned long round_jiffies_up_relative (j); 
unsigned long j;
 

Arguments

j

the time in (relative) jiffies that should be rounded

Description

This is the same as round_jiffies_relative except that it will never round down. This is useful for timeouts for which the exact time of firing does not matter too much, as long as they don't fire too early.


Name

set_timer_slack — set the allowed slack for a timer

Synopsis

void set_timer_slack (timer,  
 slack_hz); 
struct timer_list * timer;
int slack_hz;
 

Arguments

timer

the timer to be modified

slack_hz

the amount of time (in jiffies) allowed for rounding

Description

Set the amount of time, in jiffies, that a certain timer has in terms of slack. By setting this value, the timer subsystem will schedule the actual timer somewhere between the time mod_timer asks for, and that time plus the slack.

By setting the slack to -1, a percentage of the delay is used instead.


Name

init_timer_key — initialize a timer

Synopsis

void init_timer_key (timer,  
 name,  
 key); 
struct timer_list * timer;
const char * name;
struct lock_class_key * key;
 

Arguments

timer

the timer to be initialized

name

name of the timer

key

lockdep class key of the fake lock used for tracking timer sync lock dependencies

Description

init_timer_key must be done to a timer prior calling *any* of the other timer functions.


Name

mod_timer_pending — modify a pending timer's timeout

Synopsis

int mod_timer_pending (timer,  
 expires); 
struct timer_list * timer;
unsigned long expires;
 

Arguments

timer

the pending timer to be modified

expires

new timeout in jiffies

Description

mod_timer_pending is the same for pending timers as mod_timer, but will not re-activate and modify already deleted timers.

It is useful for unserialized use of timers.


Name

mod_timer — modify a timer's timeout

Synopsis

int mod_timer (timer,  
 expires); 
struct timer_list * timer;
unsigned long expires;
 

Arguments

timer

the timer to be modified

expires

new timeout in jiffies

Description

mod_timer is a more efficient way to update the expire field of an active timer (if the timer is inactive it will be activated)

mod_timer(timer, expires) is equivalent to:

del_timer(timer); timer->expires = expires; add_timer(timer);

Note that if there are multiple unserialized concurrent users of the same timer, then mod_timer is the only safe way to modify the timeout, since add_timer cannot modify an already running timer.

The function returns whether it has modified a pending timer or not. (ie. mod_timer of an inactive timer returns 0, mod_timer of an active timer returns 1.)


Name

mod_timer_pinned — modify a timer's timeout

Synopsis

int mod_timer_pinned (timer,  
 expires); 
struct timer_list * timer;
unsigned long expires;
 

Arguments

timer

the timer to be modified

expires

new timeout in jiffies

Description

mod_timer_pinned is a way to update the expire field of an active timer (if the timer is inactive it will be activated) and not allow the timer to be migrated to a different CPU.

mod_timer_pinned(timer, expires) is equivalent to:

del_timer(timer); timer->expires = expires; add_timer(timer);


Name

add_timer — start a timer

Synopsis

void add_timer (timer); 
struct timer_list * timer;
 

Arguments

timer

the timer to be added

Description

The kernel will do a ->function(->data) callback from the timer interrupt at the ->expires point in the future. The current time is 'jiffies'.

The timer's ->expires, ->function (and if the handler uses it, ->data) fields must be set prior calling this function.

Timers with an ->expires field in the past will be executed in the next timer tick.


Name

add_timer_on — start a timer on a particular CPU

Synopsis

void add_timer_on (timer,  
 cpu); 
struct timer_list * timer;
int cpu;
 

Arguments

timer

the timer to be added

cpu

the CPU to start it on

Description

This is not very scalable on SMP. Double adds are not possible.


Name

del_timer — deactive a timer.

Synopsis

int del_timer (timer); 
struct timer_list * timer;
 

Arguments

timer

the timer to be deactivated

Description

del_timer deactivates a timer - this works on both active and inactive timers.

The function returns whether it has deactivated a pending timer or not. (ie. del_timer of an inactive timer returns 0, del_timer of an active timer returns 1.)


Name

try_to_del_timer_sync — Try to deactivate a timer

Synopsis

int try_to_del_timer_sync (timer); 
struct timer_list * timer;
 

Arguments

timer

timer do del

Description

This function tries to deactivate a timer. Upon successful (ret >= 0) exit the timer is not queued and the handler is not running on any CPU.


Name

del_timer_sync — deactivate a timer and wait for the handler to finish.

Synopsis

int del_timer_sync (timer); 
struct timer_list * timer;
 

Arguments

timer

the timer to be deactivated

Description

This function only differs from del_timer on SMP: besides deactivating the timer it also makes sure the handler has finished executing on other CPUs.

Synchronization rules

Callers must prevent restarting of the timer, otherwise this function is meaningless. It must not be called from interrupt contexts. The caller must not hold locks which would prevent completion of the timer's handler. The timer's handler must not call add_timer_on. Upon exit the timer is not queued and the handler is not running on any CPU.

Note

You must not hold locks that are held in interrupt context while calling this function. Even if the lock has nothing to do with the timer in question. Here's why:

CPU0 CPU1 ---- ---- <SOFTIRQ> call_timer_fn; base->running_timer = mytimer; spin_lock_irq(somelock); <IRQ> spin_lock(somelock); del_timer_sync(mytimer); while (base->running_timer == mytimer);

Now del_timer_sync will never return and never release somelock. The interrupt on the other CPU is waiting to grab somelock but it has interrupted the softirq that CPU0 is waiting to finish.

The function returns whether it has deactivated a pending timer or not.


Name

schedule_timeout — sleep until timeout

Synopsis

signed long __sched schedule_timeout (timeout); 
signed long timeout;
 

Arguments

timeout

timeout value in jiffies

Description

Make the current task sleep until timeout jiffies have elapsed. The routine will return immediately unless the current task state has been set (see set_current_state).

You can set the task state as follows -

TASK_UNINTERRUPTIBLE - at least timeout jiffies are guaranteed to pass before the routine returns. The routine will return 0

TASK_INTERRUPTIBLE - the routine may return early if a signal is delivered to the current task. In this case the remaining time in jiffies will be returned, or 0 if the timer expired in time

The current task state is guaranteed to be TASK_RUNNING when this routine returns.

Specifying a timeout value of MAX_SCHEDULE_TIMEOUT will schedule the CPU away without a bound on the timeout. In this case the return value will be MAX_SCHEDULE_TIMEOUT.

In all cases the return value is guaranteed to be non-negative.


Name

msleep — sleep safely even with waitqueue interruptions

Synopsis

void msleep (msecs); 
unsigned int msecs;
 

Arguments

msecs

Time in milliseconds to sleep for


Name

msleep_interruptible — sleep waiting for signals

Synopsis

unsigned long msleep_interruptible (msecs); 
unsigned int msecs;
 

Arguments

msecs

Time in milliseconds to sleep for


Name

usleep_range — Drop in replacement for udelay where wakeup is flexible

Synopsis

void usleep_range (min,  
 max); 
unsigned long min;
unsigned long max;
 

Arguments

min

Minimum time in usecs to sleep

max

Maximum time in usecs to sleep

Wait queues and Wake events

Name

wait_event — sleep until a condition gets true

Synopsis

wait_event (wq,  
 condition); 
wq;
condition;
 

Arguments

wq

the waitqueue to wait on

condition

a C expression for the event to wait for

Description

The process is put to sleep (TASK_UNINTERRUPTIBLE) until the condition evaluates to true. The condition is checked each time the waitqueue wq is woken up.

wake_up has to be called after changing any variable that could change the result of the wait condition.


Name

wait_event_timeout — sleep until a condition gets true or a timeout elapses

Synopsis

wait_event_timeout (wq,  
 condition,  
 timeout); 
wq;
condition;
timeout;
 

Arguments

wq

the waitqueue to wait on

condition

a C expression for the event to wait for

timeout

timeout, in jiffies

Description

The process is put to sleep (TASK_UNINTERRUPTIBLE) until the condition evaluates to true. The condition is checked each time the waitqueue wq is woken up.

wake_up has to be called after changing any variable that could change the result of the wait condition.

The function returns 0 if the timeout elapsed, and the remaining jiffies if the condition evaluated to true before the timeout elapsed.


Name

wait_event_interruptible — sleep until a condition gets true

Synopsis

wait_event_interruptible (wq,  
 condition); 
wq;
condition;
 

Arguments

wq

the waitqueue to wait on

condition

a C expression for the event to wait for

Description

The process is put to sleep (TASK_INTERRUPTIBLE) until the condition evaluates to true or a signal is received. The condition is checked each time the waitqueue wq is woken up.

wake_up has to be called after changing any variable that could change the result of the wait condition.

The function will return -ERESTARTSYS if it was interrupted by a signal and 0 if condition evaluated to true.


Name

wait_event_interruptible_timeout — sleep until a condition gets true or a timeout elapses

Synopsis

wait_event_interruptible_timeout (wq,  
 condition,  
 timeout); 
wq;
condition;
timeout;
 

Arguments

wq

the waitqueue to wait on

condition

a C expression for the event to wait for

timeout

timeout, in jiffies

Description

The process is put to sleep (TASK_INTERRUPTIBLE) until the condition evaluates to true or a signal is received. The condition is checked each time the waitqueue wq is woken up.

wake_up has to be called after changing any variable that could change the result of the wait condition.

The function returns 0 if the timeout elapsed, -ERESTARTSYS if it was interrupted by a signal, and the remaining jiffies otherwise if the condition evaluated to true before the timeout elapsed.


Name

wait_event_interruptible_locked — sleep until a condition gets true

Synopsis

wait_event_interruptible_locked (wq,  
 condition); 
wq;
condition;
 

Arguments

wq

the waitqueue to wait on

condition

a C expression for the event to wait for

Description

The process is put to sleep (TASK_INTERRUPTIBLE) until the condition evaluates to true or a signal is received. The condition is checked each time the waitqueue wq is woken up.

It must be called with wq.lock being held. This spinlock is unlocked while sleeping but condition testing is done while lock is held and when this macro exits the lock is held.

The lock is locked/unlocked using spin_lock/spin_unlock functions which must match the way they are locked/unlocked outside of this macro.

wake_up_locked has to be called after changing any variable that could change the result of the wait condition.

The function will return -ERESTARTSYS if it was interrupted by a signal and 0 if condition evaluated to true.


Name

wait_event_interruptible_locked_irq — sleep until a condition gets true

Synopsis

wait_event_interruptible_locked_irq (wq,  
 condition); 
wq;
condition;
 

Arguments

wq

the waitqueue to wait on

condition

a C expression for the event to wait for

Description

The process is put to sleep (TASK_INTERRUPTIBLE) until the condition evaluates to true or a signal is received. The condition is checked each time the waitqueue wq is woken up.

It must be called with wq.lock being held. This spinlock is unlocked while sleeping but condition testing is done while lock is held and when this macro exits the lock is held.

The lock is locked/unlocked using spin_lock_irq/spin_unlock_irq functions which must match the way they are locked/unlocked outside of this macro.

wake_up_locked has to be called after changing any variable that could change the result of the wait condition.

The function will return -ERESTARTSYS if it was interrupted by a signal and 0 if condition evaluated to true.


Name

wait_event_interruptible_exclusive_locked — sleep exclusively until a condition gets true

Synopsis

wait_event_interruptible_exclusive_locked (wq,  
 condition); 
wq;
condition;
 

Arguments

wq

the waitqueue to wait on

condition

a C expression for the event to wait for

Description

The process is put to sleep (TASK_INTERRUPTIBLE) until the condition evaluates to true or a signal is received. The condition is checked each time the waitqueue wq is woken up.

It must be called with wq.lock being held. This spinlock is unlocked while sleeping but condition testing is done while lock is held and when this macro exits the lock is held.

The lock is locked/unlocked using spin_lock/spin_unlock functions which must match the way they are locked/unlocked outside of this macro.

The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag set thus when other process waits process on the list if this process is awaken further processes are not considered.

wake_up_locked has to be called after changing any variable that could change the result of the wait condition.

The function will return -ERESTARTSYS if it was interrupted by a signal and 0 if condition evaluated to true.


Name

wait_event_interruptible_exclusive_locked_irq — sleep until a condition gets true

Synopsis

wait_event_interruptible_exclusive_locked_irq (wq,  
 condition); 
wq;
condition;
 

Arguments

wq

the waitqueue to wait on

condition

a C expression for the event to wait for

Description

The process is put to sleep (TASK_INTERRUPTIBLE) until the condition evaluates to true or a signal is received. The condition is checked each time the waitqueue wq is woken up.

It must be called with wq.lock being held. This spinlock is unlocked while sleeping but condition testing is done while lock is held and when this macro exits the lock is held.

The lock is locked/unlocked using spin_lock_irq/spin_unlock_irq functions which must match the way they are locked/unlocked outside of this macro.

The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag set thus when other process waits process on the list if this process is awaken further processes are not considered.

wake_up_locked has to be called after changing any variable that could change the result of the wait condition.

The function will return -ERESTARTSYS if it was interrupted by a signal and 0 if condition evaluated to true.


Name

wait_event_killable — sleep until a condition gets true

Synopsis

wait_event_killable (wq,  
 condition); 
wq;
condition;
 

Arguments

wq

the waitqueue to wait on

condition

a C expression for the event to wait for

Description

The process is put to sleep (TASK_KILLABLE) until the condition evaluates to true or a signal is received. The condition is checked each time the waitqueue wq is woken up.

wake_up has to be called after changing any variable that could change the result of the wait condition.

The function will return -ERESTARTSYS if it was interrupted by a signal and 0 if condition evaluated to true.


Name

wait_on_bit — wait for a bit to be cleared

Synopsis

int wait_on_bit (word,  
 bit,  
 action,  
 mode); 
void * word;
int bit;
int (*action) (void *);
unsigned mode;
 

Arguments

word

the word being waited on, a kernel virtual address

bit

the bit of the word being waited on

action

the function used to sleep, which may take special actions

mode

the task state to sleep in

Description

There is a standard hashed waitqueue table for generic use. This is the part of the hashtable's accessor API that waits on a bit. For instance, if one were to have waiters on a bitflag, one would call wait_on_bit in threads waiting for the bit to clear. One uses wait_on_bit where one is waiting for the bit to clear, but has no intention of setting it.


Name

wait_on_bit_lock — wait for a bit to be cleared, when wanting to set it

Synopsis

int wait_on_bit_lock (word,  
 bit,  
 action,  
 mode); 
void * word;
int bit;
int (*action) (void *);
unsigned mode;
 

Arguments

word

the word being waited on, a kernel virtual address

bit

the bit of the word being waited on

action

the function used to sleep, which may take special actions

mode

the task state to sleep in

Description

There is a standard hashed waitqueue table for generic use. This is the part of the hashtable's accessor API that waits on a bit when one intends to set it, for instance, trying to lock bitflags. For instance, if one were to have waiters trying to set bitflag and waiting for it to clear before setting it, one would call wait_on_bit in threads waiting to be able to set the bit. One uses wait_on_bit_lock where one is waiting for the bit to clear with the intention of setting it, and when done, clearing it.


Name

finish_wait — clean up after waiting in a queue

Synopsis

void finish_wait (q,  
 wait); 
wait_queue_head_t * q;
wait_queue_t * wait;
 

Arguments

q

waitqueue waited on

wait

wait descriptor

Description

Sets current thread back to running state and removes the wait descriptor from the given waitqueue if still queued.


Name

abort_exclusive_wait — abort exclusive waiting in a queue

Synopsis

void abort_exclusive_wait (q,  
 wait,  
 mode,  
 key); 
wait_queue_head_t * q;
wait_queue_t * wait;
unsigned int mode;
void * key;
 

Arguments

q

waitqueue waited on

wait

wait descriptor

mode

runstate of the waiter to be woken

key

key to identify a wait bit queue or NULL

Description

Sets current thread back to running state and removes the wait descriptor from the given waitqueue if still queued.

Wakes up the next waiter if the caller is concurrently woken up through the queue.

This prevents waiter starvation where an exclusive waiter aborts and is woken up concurrently and no one wakes up the next waiter.


Name

wake_up_bit — wake up a waiter on a bit

Synopsis

void wake_up_bit (word,  
 bit); 
void * word;
int bit;
 

Arguments

word

the word being waited on, a kernel virtual address

bit

the bit of the word being waited on

Description

There is a standard hashed waitqueue table for generic use. This is the part of the hashtable's accessor API that wakes up waiters on a bit. For instance, if one were to have waiters on a bitflag, one would call wake_up_bit after clearing the bit.

In order for this to function properly, as it uses waitqueue_active internally, some kind of memory barrier must be done prior to calling this. Typically, this will be smp_mb__after_clear_bit, but in some cases where bitflags are manipulated non-atomically under a lock, one may need to use a less regular barrier, such fs/inode.c's smp_mb, because spin_unlock does not guarantee a memory barrier.

High-resolution timers

Name

ktime_set — Set a ktime_t variable from a seconds/nanoseconds value

Synopsis

ktime_t ktime_set (secs,  
 nsecs); 
const long secs;
const unsigned long nsecs;
 

Arguments

secs

seconds to set

nsecs

nanoseconds to set

Description

Return the ktime_t representation of the value


Name

ktime_sub — subtract two ktime_t variables

Synopsis

ktime_t ktime_sub (lhs,  
 rhs); 
const ktime_t lhs;
const ktime_t rhs;
 

Arguments

lhs

minuend

rhs

subtrahend

Description

Returns the remainder of the subtraction


Name

ktime_add — add two ktime_t variables

Synopsis

ktime_t ktime_add (add1,  
 add2); 
const ktime_t add1;
const ktime_t add2;
 

Arguments

add1

addend1

add2

addend2

Description

Returns the sum of add1 and add2.


Name

timespec_to_ktime — convert a timespec to ktime_t format

Synopsis

ktime_t timespec_to_ktime (ts); 
const struct timespec ts;
 

Arguments

ts

the timespec variable to convert

Description

Returns a ktime_t variable with the converted timespec value


Name

timeval_to_ktime — convert a timeval to ktime_t format

Synopsis

ktime_t timeval_to_ktime (tv); 
const struct timeval tv;
 

Arguments

tv

the timeval variable to convert

Description

Returns a ktime_t variable with the converted timeval value


Name

ktime_to_timespec — convert a ktime_t variable to timespec format

Synopsis

struct timespec ktime_to_timespec (kt); 
const ktime_t kt;
 

Arguments

kt

the ktime_t variable to convert

Description

Returns the timespec representation of the ktime value


Name

ktime_to_timeval — convert a ktime_t variable to timeval format

Synopsis

struct timeval ktime_to_timeval (kt); 
const ktime_t kt;
 

Arguments

kt

the ktime_t variable to convert

Description

Returns the timeval representation of the ktime value


Name

ktime_to_ns — convert a ktime_t variable to scalar nanoseconds

Synopsis

s64 ktime_to_ns (kt); 
const ktime_t kt;
 

Arguments

kt

the ktime_t variable to convert

Description

Returns the scalar nanoseconds representation of kt


Name

ktime_equal — Compares two ktime_t variables to see if they are equal

Synopsis

int ktime_equal (cmp1,  
 cmp2); 
const ktime_t cmp1;
const ktime_t cmp2;
 

Arguments

cmp1

comparable1

cmp2

comparable2

Description

Compare two ktime_t variables, returns 1 if equal


Name

struct hrtimer — the basic hrtimer structure

Synopsis

struct hrtimer {
  struct timerqueue_node node;
  ktime_t _softexpires;
  enum hrtimer_restart		(* function) (struct hrtimer *);
  struct hrtimer_clock_base * base;
  unsigned long state;
#ifdef CONFIG_TIMER_STATS
  int start_pid;
  void * start_site;
  char start_comm[16];
#endif
};  

Members

node

timerqueue node, which also manages node.expires, the absolute expiry time in the hrtimers internal representation. The time is related to the clock on which the timer is based. Is setup by adding slack to the _softexpires value. For non range timers identical to _softexpires.

_softexpires

the absolute earliest expiry time of the hrtimer. The time which was given as expiry time when the timer was armed.

function

timer expiry callback function

base

pointer to the timer base (per cpu and per clock)

state

state information (See bit values above)

start_pid

timer statistics field to store the pid of the task which started the timer

start_site

timer statistics field to store the site where the timer was started

start_comm[16]

timer statistics field to store the name of the process which started the timer

Description

The hrtimer structure must be initialized by hrtimer_init


Name

struct hrtimer_sleeper — simple sleeper structure

Synopsis

struct hrtimer_sleeper {
  struct hrtimer timer;
  struct task_struct * task;
};  

Members

timer

embedded timer structure

task

task to wake up

Description

task is set to NULL, when the timer expires.


Name

struct hrtimer_clock_base — the timer base for a specific clock

Synopsis

struct hrtimer_clock_base {
  struct hrtimer_cpu_base * cpu_base;
  int index;
  clockid_t clockid;
  struct timerqueue_head active;
  ktime_t resolution;
  ktime_t (* get_time) (void);
  ktime_t softirq_time;
  ktime_t offset;
};  

Members

cpu_base

per cpu clock base

index

clock type index for per_cpu support when moving a timer to a base on another cpu.

clockid

clock id for per_cpu support

active

red black tree root node for the active timers

resolution

the resolution of the clock, in nanoseconds

get_time

function to retrieve the current time of the clock

softirq_time

the time when running the hrtimer queue in the softirq

offset

offset of this clock to the monotonic base


Name

ktime_add_ns — Add a scalar nanoseconds value to a ktime_t variable

Synopsis

ktime_t ktime_add_ns (kt,  
 nsec); 
const ktime_t kt;
u64 nsec;
 

Arguments

kt

addend

nsec

the scalar nsec value to add

Description

Returns the sum of kt and nsec in ktime_t format


Name

ktime_sub_ns — Subtract a scalar nanoseconds value from a ktime_t variable

Synopsis

ktime_t ktime_sub_ns (kt,  
 nsec); 
const ktime_t kt;
u64 nsec;
 

Arguments

kt

minuend

nsec

the scalar nsec value to subtract

Description

Returns the subtraction of nsec from kt in ktime_t format


Name

hrtimer_forward — forward the timer expiry

Synopsis

u64 hrtimer_forward (timer,  
 now,  
 interval); 
struct hrtimer * timer;
ktime_t now;
ktime_t interval;
 

Arguments

timer

hrtimer to forward

now

forward past this time

interval

the interval to forward

Description

Forward the timer expiry so it will expire in the future. Returns the number of overruns.


Name

hrtimer_start_range_ns — (re)start an hrtimer on the current CPU

Synopsis

int hrtimer_start_range_ns (timer,  
 tim,  
 delta_ns,  
 mode); 
struct hrtimer * timer;
ktime_t tim;
unsigned long delta_ns;
const enum hrtimer_mode mode;
 

Arguments

timer

the timer to be added

tim

expiry time

delta_ns

"slack" range for the timer

mode

expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL)

Returns

0 on success 1 when the timer was active


Name

hrtimer_start — (re)start an hrtimer on the current CPU

Synopsis

int hrtimer_start (timer,  
 tim,  
 mode); 
struct hrtimer * timer;
ktime_t tim;
const enum hrtimer_mode mode;
 

Arguments

timer

the timer to be added

tim

expiry time

mode

expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL)

Returns

0 on success 1 when the timer was active


Name

hrtimer_try_to_cancel — try to deactivate a timer

Synopsis

int hrtimer_try_to_cancel (timer); 
struct hrtimer * timer;
 

Arguments

timer

hrtimer to stop

Returns

0 when the timer was not active 1 when the timer was active -1 when the timer is currently excuting the callback function and cannot be stopped


Name

hrtimer_cancel — cancel a timer and wait for the handler to finish.

Synopsis

int hrtimer_cancel (timer); 
struct hrtimer * timer;
 

Arguments

timer

the timer to be cancelled

Returns

0 when the timer was not active 1 when the timer was active


Name

hrtimer_get_remaining — get remaining time for the timer

Synopsis

ktime_t hrtimer_get_remaining (timer); 
const struct hrtimer * timer;
 

Arguments

timer

the timer to read


Name

hrtimer_init — initialize a timer to the given clock

Synopsis

void hrtimer_init (timer,  
 clock_id,  
 mode); 
struct hrtimer * timer;
clockid_t clock_id;
enum hrtimer_mode mode;
 

Arguments

timer

the timer to be initialized

clock_id

the clock to be used

mode

timer mode abs/rel


Name

hrtimer_get_res — get the timer resolution for a clock

Synopsis

int hrtimer_get_res (which_clock,  
 tp); 
const clockid_t which_clock;
struct timespec * tp;
 

Arguments

which_clock

which clock to query

tp

pointer to timespec variable to store the resolution

Description

Store the resolution of the clock selected by which_clock in the variable pointed to by tp.


Name

schedule_hrtimeout_range — sleep until timeout

Synopsis

int __sched schedule_hrtimeout_range (expires,  
 delta,  
 mode); 
ktime_t * expires;
unsigned long delta;
const enum hrtimer_mode mode;
 

Arguments

expires

timeout value (ktime_t)

delta

slack in expires timeout (ktime_t)

mode

timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL

Description

Make the current task sleep until the given expiry time has elapsed. The routine will return immediately unless the current task state has been set (see set_current_state).

The delta argument gives the kernel the freedom to schedule the actual wakeup to a time that is both power and performance friendly. The kernel give the normal best effort behavior for expires+delta, but may decide to fire the timer earlier, but no earlier than expires.

You can set the task state as follows -

TASK_UNINTERRUPTIBLE - at least timeout time is guaranteed to pass before the routine returns.

TASK_INTERRUPTIBLE - the routine may return early if a signal is delivered to the current task.

The current task state is guaranteed to be TASK_RUNNING when this routine returns.

Returns 0 when the timer has expired otherwise -EINTR


Name

schedule_hrtimeout — sleep until timeout

Synopsis

int __sched schedule_hrtimeout (expires,  
 mode); 
ktime_t * expires;
const enum hrtimer_mode mode;
 

Arguments

expires

timeout value (ktime_t)

mode

timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL

Description

Make the current task sleep until the given expiry time has elapsed. The routine will return immediately unless the current task state has been set (see set_current_state).

You can set the task state as follows -

TASK_UNINTERRUPTIBLE - at least timeout time is guaranteed to pass before the routine returns.

TASK_INTERRUPTIBLE - the routine may return early if a signal is delivered to the current task.

The current task state is guaranteed to be TASK_RUNNING when this routine returns.

Returns 0 when the timer has expired otherwise -EINTR

Workqueues and Kevents

Name

queue_work — queue work on a workqueue

Synopsis

int queue_work (wq,  
 work); 
struct workqueue_struct * wq;
struct work_struct * work;
 

Arguments

wq

workqueue to use

work

work to queue

Description

Returns 0 if work was already on a queue, non-zero otherwise.

We queue the work to the CPU on which it was submitted, but if the CPU dies it can be processed by another CPU.


Name

queue_work_on — queue work on specific cpu

Synopsis

int queue_work_on (cpu,  
 wq,  
 work); 
int cpu;
struct workqueue_struct * wq;
struct work_struct * work;
 

Arguments

cpu

CPU number to execute work on

wq

workqueue to use

work

work to queue

Description

Returns 0 if work was already on a queue, non-zero otherwise.

We queue the work to a specific CPU, the caller must ensure it can't go away.


Name

queue_delayed_work — queue work on a workqueue after delay

Synopsis

int queue_delayed_work (wq,  
 dwork,  
 delay); 
struct workqueue_struct * wq;
struct delayed_work * dwork;
unsigned long delay;
 

Arguments

wq

workqueue to use

dwork

delayable work to queue

delay

number of jiffies to wait before queueing

Description

Returns 0 if work was already on a queue, non-zero otherwise.


Name

queue_delayed_work_on — queue work on specific CPU after delay

Synopsis

int queue_delayed_work_on (cpu,  
 wq,  
 dwork,  
 delay); 
int cpu;
struct workqueue_struct * wq;
struct delayed_work * dwork;
unsigned long delay;
 

Arguments

cpu

CPU number to execute work on

wq

workqueue to use

dwork

work to queue

delay

number of jiffies to wait before queueing

Description

Returns 0 if work was already on a queue, non-zero otherwise.


Name

flush_workqueue — ensure that any scheduled work has run to completion.

Synopsis

void flush_workqueue (wq); 
struct workqueue_struct * wq;
 

Arguments

wq

workqueue to flush

Description

Forces execution of the workqueue and blocks until its completion. This is typically used in driver shutdown handlers.

We sleep until all works which were queued on entry have been handled, but we are not livelocked by new incoming ones.


Name

flush_work — wait for a work to finish executing the last queueing instance

Synopsis

bool flush_work (work); 
struct work_struct * work;
 

Arguments

work

the work to flush

Description

Wait until work has finished execution. This function considers only the last queueing instance of work. If work has been enqueued across different CPUs on a non-reentrant workqueue or on multiple workqueues, work might still be executing on return on some of the CPUs from earlier queueing.

If work was queued only on a non-reentrant, ordered or unbound workqueue, work is guaranteed to be idle on return if it hasn't been requeued since flush started.

RETURNS

true if flush_work waited for the work to finish execution, false if it was already idle.


Name

flush_work_sync — wait until a work has finished execution

Synopsis

bool flush_work_sync (work); 
struct work_struct * work;
 

Arguments

work

the work to flush

Description

Wait until work has finished execution. On return, it's guaranteed that all queueing instances of work which happened before this function is called are finished. In other words, if work hasn't been requeued since this function was called, work is guaranteed to be idle on return.

RETURNS

true if flush_work_sync waited for the work to finish execution, false if it was already idle.


Name

cancel_work_sync — cancel a work and wait for it to finish

Synopsis

bool cancel_work_sync (work); 
struct work_struct * work;
 

Arguments

work

the work to cancel

Description

Cancel work and wait for its execution to finish. This function can be used even if the work re-queues itself or migrates to another workqueue. On return from this function, work is guaranteed to be not pending or executing on any CPU.

cancel_work_sync(delayed_work->work) must not be used for delayed_work's. Use cancel_delayed_work_sync instead.

The caller must ensure that the workqueue on which work was last queued can't be destroyed before this function returns.

RETURNS

true if work was pending, false otherwise.


Name

flush_delayed_work — wait for a dwork to finish executing the last queueing

Synopsis

bool flush_delayed_work (dwork); 
struct delayed_work * dwork;
 

Arguments

dwork

the delayed work to flush

Description

Delayed timer is cancelled and the pending work is queued for immediate execution. Like flush_work, this function only considers the last queueing instance of dwork.

RETURNS

true if flush_work waited for the work to finish execution, false if it was already idle.


Name

flush_delayed_work_sync — wait for a dwork to finish

Synopsis

bool flush_delayed_work_sync (dwork); 
struct delayed_work * dwork;
 

Arguments

dwork

the delayed work to flush

Description

Delayed timer is cancelled and the pending work is queued for execution immediately. Other than timer handling, its behavior is identical to flush_work_sync.

RETURNS

true if flush_work_sync waited for the work to finish execution, false if it was already idle.


Name

cancel_delayed_work_sync — cancel a delayed work and wait for it to finish

Synopsis

bool cancel_delayed_work_sync (dwork); 
struct delayed_work * dwork;
 

Arguments

dwork

the delayed work cancel

Description

This is cancel_work_sync for delayed works.

RETURNS

true if dwork was pending, false otherwise.


Name

schedule_work — put work task in global workqueue

Synopsis

int schedule_work (work); 
struct work_struct * work;
 

Arguments

work

job to be done

Description

Returns zero if work was already on the kernel-global workqueue and non-zero otherwise.

This puts a job in the kernel-global workqueue if it was not already queued and leaves it in the same position on the kernel-global workqueue otherwise.


Name

schedule_delayed_work — put work task in global workqueue after delay

Synopsis

int schedule_delayed_work (dwork,  
 delay); 
struct delayed_work * dwork;
unsigned long delay;
 

Arguments

dwork

job to be done

delay

number of jiffies to wait or 0 for immediate execution

Description

After waiting for a given time this puts a job in the kernel-global workqueue.


Name

schedule_delayed_work_on — queue work in global workqueue on CPU after delay

Synopsis

int schedule_delayed_work_on (cpu,  
 dwork,  
 delay); 
int cpu;
struct delayed_work * dwork;
unsigned long delay;
 

Arguments

cpu

cpu to use

dwork

job to be done

delay

number of jiffies to wait

Description

After waiting for a given time this puts a job in the kernel-global workqueue on the specified CPU.


Name

flush_scheduled_work — ensure that any scheduled work has run to completion.

Synopsis

void flush_scheduled_work (void); 
void;
 

Arguments

void

no arguments

Description

Forces execution of the kernel-global workqueue and blocks until its completion.

Think twice before calling this function! It's very easy to get into trouble if you don't take great care. Either of the following situations

will lead to deadlock

One of the work items currently on the workqueue needs to acquire a lock held by your code or its caller.

Your code is running in the context of a work routine.

They will be detected by lockdep when they occur, but the first might not occur very often. It depends on what work items are on the workqueue and what locks they need, which you have no control over.

In most situations flushing the entire workqueue is overkill; you merely need to know that a particular work item isn't queued and isn't running. In such cases you should use cancel_delayed_work_sync or cancel_work_sync instead.


Name

execute_in_process_context — reliably execute the routine with user context

Synopsis

int execute_in_process_context (fn,  
 ew); 
work_func_t fn;
struct execute_work * ew;
 

Arguments

fn

the function to execute

ew

guaranteed storage for the execute work structure (must be available when the work executes)

Description

Executes the function immediately if process context is available, otherwise schedules the function for delayed execution.

Returns

0 - function was executed 1 - function was scheduled for execution


Name

destroy_workqueue — safely terminate a workqueue

Synopsis

void destroy_workqueue (wq); 
struct workqueue_struct * wq;
 

Arguments

wq

target workqueue

Description

Safely destroy a workqueue. All work currently pending will be done first.


Name

workqueue_set_max_active — adjust max_active of a workqueue

Synopsis

void workqueue_set_max_active (wq,  
 max_active); 
struct workqueue_struct * wq;
int max_active;
 

Arguments

wq

target workqueue

max_active

new max_active value.

Description

Set max_active of wq to max_active.

CONTEXT

Don't call from IRQ context.


Name

workqueue_congested — test whether a workqueue is congested

Synopsis

bool workqueue_congested (cpu,  
 wq); 
unsigned int cpu;
struct workqueue_struct * wq;
 

Arguments

cpu

CPU in question

wq

target workqueue

Description

Test whether wq's cpu workqueue for cpu is congested. There is no synchronization around this function and the test result is unreliable and only useful as advisory hints or for debugging.

RETURNS

true if congested, false otherwise.


Name

work_cpu — return the last known associated cpu for work

Synopsis

unsigned int work_cpu (work); 
struct work_struct * work;
 

Arguments

work

the work of interest

RETURNS

CPU number if work was ever queued. WORK_CPU_NONE otherwise.


Name

work_busy — test whether a work is currently pending or running

Synopsis

unsigned int work_busy (work); 
struct work_struct * work;
 

Arguments

work

the work to be tested

Description

Test whether work is currently pending or running. There is no synchronization around this function and the test result is unreliable and only useful as advisory hints or for debugging. Especially for reentrant wqs, the pending state might hide the running state.

RETURNS

OR'd bitmask of WORK_BUSY_* bits.


Name

work_on_cpu — run a function in user context on a particular cpu

Synopsis

long work_on_cpu (cpu,  
 fn,  
 arg); 
unsigned int cpu;
long (*fn) (void *);
void * arg;
 

Arguments

cpu

the cpu to run on

fn

the function to run

arg

the function arg

Description

This will return the value fn returns. It is up to the caller to ensure that the cpu doesn't go offline. The caller must not hold any locks which would prevent fn from completing.

Internal Functions

Name

reparent_to_kthreadd — Reparent the calling kernel thread to kthreadd

Synopsis

void reparent_to_kthreadd (void); 
void;
 

Arguments

void

no arguments

Description

If a kernel thread is launched as a result of a system call, or if it ever exits, it should generally reparent itself to kthreadd so it isn't in the way of other processes and is correctly cleaned up on exit.

The various task state such as scheduling policy and priority may have been inherited from a user process, so we reset them to sane values here.

NOTE that reparent_to_kthreadd gives the caller full capabilities.


Name

wait_task_stopped — Wait for TASK_STOPPED or TASK_TRACED

Synopsis

int wait_task_stopped (wo,  
 ptrace,  
 p); 
struct wait_opts * wo;
int ptrace;
struct task_struct * p;
 

Arguments

wo

wait options

ptrace

is the wait for ptrace

p

task to wait for

Description

Handle sys_wait4 work for p in state TASK_STOPPED or TASK_TRACED.

CONTEXT

read_lock(tasklist_lock), which is released if return value is non-zero. Also, grabs and releases p->sighand->siglock.

RETURNS

0 if wait condition didn't exist and search for other wait conditions should continue. Non-zero return, -errno on failure and p's pid on success, implies that tasklist_lock is released and wait condition search should terminate.


Name

task_clear_group_stop_trapping — clear group stop trapping bit

Synopsis

void task_clear_group_stop_trapping (task); 
struct task_struct * task;
 

Arguments

task

target task

Description

If GROUP_STOP_TRAPPING is set, a ptracer is waiting for us. Clear it and wake up the ptracer. Note that we don't need any further locking. task->siglock guarantees that task->parent points to the ptracer.

CONTEXT

Must be called with task->sighand->siglock held.


Name

task_clear_group_stop_pending — clear pending group stop

Synopsis

void task_clear_group_stop_pending (task); 
struct task_struct * task;
 

Arguments

task

target task

Description

Clear group stop states for task.

CONTEXT

Must be called with task->sighand->siglock held.


Name

task_participate_group_stop — participate in a group stop

Synopsis

bool task_participate_group_stop (task); 
struct task_struct * task;
 

Arguments

task

task participating in a group stop

Description

task has GROUP_STOP_PENDING set and is participating in a group stop. Group stop states are cleared and the group stop count is consumed if GROUP_STOP_CONSUME was set. If the consumption completes the group stop, the appropriate SIGNAL_* flags are set.

CONTEXT

Must be called with task->sighand->siglock held.

RETURNS

true if group stop completion should be notified to the parent, false otherwise.


Name

do_notify_parent_cldstop — notify parent of stopped/continued state change

Synopsis

void do_notify_parent_cldstop (tsk,  
 for_ptracer,  
 why); 
struct task_struct * tsk;
bool for_ptracer;
int why;
 

Arguments

tsk

task reporting the state change

for_ptracer

the notification is for ptracer

why

CLD_{CONTINUED|STOPPED|TRAPPED} to report

Description

Notify tsk's parent that the stopped/continued state has changed. If for_ptracer is false, tsk's group leader notifies to its real parent. If true, tsk reports to tsk->parent which should be the ptracer.

CONTEXT

Must be called with tasklist_lock at least read locked.


Name

sys_restart_syscall — restart a system call

Synopsis

long sys_restart_syscall (void); 
void;
 

Arguments

void

no arguments


Name

set_current_blocked — change current->blocked mask

Synopsis

void set_current_blocked (newset); 
const sigset_t * newset;
 

Arguments

newset

new mask

Description

It is wrong to change ->blocked directly, this helper should be used to ensure the process can't miss a shared signal we are going to block.


Name

sys_rt_sigprocmask — change the list of currently blocked signals

Synopsis

long sys_rt_sigprocmask (how,  
 nset,  
 oset,  
 sigsetsize); 
int how;
sigset_t __user * nset;
sigset_t __user * oset;
size_t sigsetsize;
 

Arguments

how

whether to add, remove, or set signals

nset

stores pending signals

oset

previous value of signal mask if non-null

sigsetsize

size of sigset_t type


Name

sys_rt_sigpending — examine a pending signal that has been raised while blocked

Synopsis

long sys_rt_sigpending (set,  
 sigsetsize); 
sigset_t __user * set;
size_t sigsetsize;
 

Arguments

set

stores pending signals

sigsetsize

size of sigset_t type or larger


Name

do_sigtimedwait — wait for queued signals specified in which

Synopsis

int do_sigtimedwait (which,  
 info,  
 ts); 
const sigset_t * which;
siginfo_t * info;
const struct timespec * ts;
 

Arguments

which

queued signals to wait for

info

if non-null, the signal's siginfo is returned here

ts

upper bound on process time suspension


Name

sys_rt_sigtimedwait — synchronously wait for queued signals specified in uthese

Synopsis

long sys_rt_sigtimedwait (uthese,  
 uinfo,  
 uts,  
 sigsetsize); 
const sigset_t __user * uthese;
siginfo_t __user * uinfo;
const struct timespec __user * uts;
size_t sigsetsize;
 

Arguments

uthese

queued signals to wait for

uinfo

if non-null, the signal's siginfo is returned here

uts

upper bound on process time suspension

sigsetsize

size of sigset_t type


Name

sys_kill — send a signal to a process

Synopsis

long sys_kill (pid,  
 sig); 
pid_t pid;
int sig;
 

Arguments

pid

the PID of the process

sig

signal to be sent


Name

sys_tgkill — send signal to one specific thread

Synopsis

long sys_tgkill (tgid,  
 pid,  
 sig); 
pid_t tgid;
pid_t pid;
int sig;
 

Arguments

tgid

the thread group ID of the thread

pid

the PID of the thread

sig

signal to be sent

Description

This syscall also checks the tgid and returns -ESRCH even if the PID exists but it's not belonging to the target process anymore. This method solves the problem of threads exiting and PIDs getting reused.


Name

sys_tkill — send signal to one specific task

Synopsis

long sys_tkill (pid,  
 sig); 
pid_t pid;
int sig;
 

Arguments

pid

the PID of the task

sig

signal to be sent

Description

Send a signal to only one task, even if it's a CLONE_THREAD task.


Name

sys_rt_sigqueueinfo — send signal information to a signal

Synopsis

long sys_rt_sigqueueinfo (pid,  
 sig,  
 uinfo); 
pid_t pid;
int sig;
siginfo_t __user * uinfo;
 

Arguments

pid

the PID of the thread

sig

signal to be sent

uinfo

signal info to be sent


Name

sys_sigpending — examine pending signals

Synopsis

long sys_sigpending (set); 
old_sigset_t __user * set;
 

Arguments

set

where mask of pending signal is returned


Name

sys_sigprocmask — examine and change blocked signals

Synopsis

long sys_sigprocmask (how,  
 nset,  
 oset); 
int how;
old_sigset_t __user * nset;
old_sigset_t __user * oset;
 

Arguments

how

whether to add, remove, or set signals

nset

signals to add or remove (if non-null)

oset

previous value of signal mask if non-null

Description

Some platforms have their own version with special arguments; others support only sys_rt_sigprocmask.


Name

sys_rt_sigaction — alter an action taken by a process

Synopsis

long sys_rt_sigaction (sig,  
 act,  
 oact,  
 sigsetsize); 
int sig;
const struct sigaction __user * act;
struct sigaction __user * oact;
size_t sigsetsize;
 

Arguments

sig

signal to be sent

act

new sigaction

oact

used to save the previous sigaction

sigsetsize

size of sigset_t type


Name

sys_rt_sigsuspend — replace the signal mask for a value with the unewset value until a signal is received

Synopsis

long sys_rt_sigsuspend (unewset,  
 sigsetsize); 
sigset_t __user * unewset;
size_t sigsetsize;
 

Arguments

unewset

new signal mask value

sigsetsize

size of sigset_t type


Name

kthread_run — create and wake a thread.

Synopsis

kthread_run (threadfn,  
 data,  
 namefmt,  
 ...); 
threadfn;
data;
namefmt;
...;
 

Arguments

threadfn

the function to run until signal_pending(current).

data

data ptr for threadfn.

namefmt

printf-style name for the thread.

...

variable arguments

Description

Convenient wrapper for kthread_create followed by wake_up_process. Returns the kthread or ERR_PTR(-ENOMEM).


Name

kthread_should_stop — should this kthread return now?

Synopsis

int kthread_should_stop (void); 
void;
 

Arguments

void

no arguments

Description

When someone calls kthread_stop on your kthread, it will be woken and this will return true. You should then return, and your return value will be passed through to kthread_stop.


Name

kthread_create_on_node — create a kthread.

Synopsis

struct task_struct * kthread_create_on_node (threadfn,  
 data,  
 node,  
 namefmt[],  
 ...); 
int (*threadfn) (void *data);
void * data;
int node;
const char namefmt[];
...;
 

Arguments

threadfn

the function to run until signal_pending(current).

data

data ptr for threadfn.

node

memory node number.

namefmt[]

printf-style name for the thread.

...

variable arguments

Description

This helper function creates and names a kernel thread. The thread will be stopped: use wake_up_process to start it. See also kthread_run.

If thread is going to be bound on a particular cpu, give its node in node, to get NUMA affinity for kthread stack, or else give -1. When woken, the thread will run threadfn() with data as its argument. threadfn() can either call do_exit directly if it is a standalone thread for which no one will call kthread_stop, or return when 'kthread_should_stop' is true (which means kthread_stop has been called). The return value should be zero or a negative error number; it will be passed to kthread_stop.

Returns a task_struct or ERR_PTR(-ENOMEM).


Name

kthread_bind — bind a just-created kthread to a cpu.

Synopsis

void kthread_bind (p,  
 cpu); 
struct task_struct * p;
unsigned int cpu;
 

Arguments

p

thread created by kthread_create.

cpu

cpu (might not be online, must be possible) for k to run on.

Description

This function is equivalent to set_cpus_allowed, except that cpu doesn't need to be online, and the thread must be stopped (i.e., just returned from kthread_create).


Name

kthread_stop — stop a thread created by kthread_create.

Synopsis

int kthread_stop (k); 
struct task_struct * k;
 

Arguments

k

thread created by kthread_create.

Description

Sets kthread_should_stop for k to return true, wakes it, and waits for it to exit. This can also be called after kthread_create instead of calling wake_up_process: the thread will exit without calling threadfn.

If threadfn may call do_exit itself, the caller must ensure task_struct can't go away.

Returns the result of threadfn, or -EINTR if wake_up_process was never called.


Name

kthread_worker_fn — kthread function to process kthread_worker

Synopsis

int kthread_worker_fn (worker_ptr); 
void * worker_ptr;
 

Arguments

worker_ptr

pointer to initialized kthread_worker

Description

This function can be used as threadfn to kthread_create or kthread_run with worker_ptr argument pointing to an initialized kthread_worker. The started kthread will process work_list until the it is stopped with kthread_stop. A kthread can also call this function directly after extra initialization.

Different kthreads can be used for the same kthread_worker as long as there's only one kthread attached to it at any given time. A kthread_worker without an attached kthread simply collects queued kthread_works.


Name

queue_kthread_work — queue a kthread_work

Synopsis

bool queue_kthread_work (worker,  
 work); 
struct kthread_worker * worker;
struct kthread_work * work;
 

Arguments

worker

target kthread_worker

work

kthread_work to queue

Description

Queue work to work processor task for async execution. task must have been created with kthread_worker_create. Returns true if work was successfully queued, false if it was already pending.


Name

flush_kthread_work — flush a kthread_work

Synopsis

void flush_kthread_work (work); 
struct kthread_work * work;
 

Arguments

work

work to flush

Description

If work is queued or executing, wait for it to finish execution.


Name

flush_kthread_worker — flush all current works on a kthread_worker

Synopsis

void flush_kthread_worker (worker); 
struct kthread_worker * worker;
 

Arguments

worker

worker to flush

Description

Wait until all currently executing or pending works on worker are finished.

Kernel objects manipulation

Name

kobject_get_path — generate and return the path associated with a given kobj and kset pair.

Synopsis

char * kobject_get_path (kobj,  
 gfp_mask); 
struct kobject * kobj;
gfp_t gfp_mask;
 

Arguments

kobj

kobject in question, with which to build the path

gfp_mask

the allocation type used to allocate the path

Description

The result must be freed by the caller with kfree.


Name

kobject_set_name — Set the name of a kobject

Synopsis

int kobject_set_name (kobj,  
 fmt,  
 ...); 
struct kobject * kobj;
const char * fmt;
...;
 

Arguments

kobj

struct kobject to set the name of

fmt

format string used to build the name

...

variable arguments

Description

This sets the name of the kobject. If you have already added the kobject to the system, you must call kobject_rename in order to change the name of the kobject.


Name

kobject_init — initialize a kobject structure

Synopsis

void kobject_init (kobj,  
 ktype); 
struct kobject * kobj;
struct kobj_type * ktype;
 

Arguments

kobj

pointer to the kobject to initialize

ktype

pointer to the ktype for this kobject.

Description

This function will properly initialize a kobject such that it can then be passed to the kobject_add call.

After this function is called, the kobject MUST be cleaned up by a call to kobject_put, not by a call to kfree directly to ensure that all of the memory is cleaned up properly.


Name

kobject_add — the main kobject add function

Synopsis

int kobject_add (kobj,  
 parent,  
 fmt,  
 ...); 
struct kobject * kobj;
struct kobject * parent;
const char * fmt;
...;
 

Arguments

kobj

the kobject to add

parent

pointer to the parent of the kobject.

fmt

format to name the kobject with.

...

variable arguments

Description

The kobject name is set and added to the kobject hierarchy in this function.

If parent is set, then the parent of the kobj will be set to it. If parent is NULL, then the parent of the kobj will be set to the kobject associted with the kset assigned to this kobject. If no kset is assigned to the kobject, then the kobject will be located in the root of the sysfs tree.

If this function returns an error, kobject_put must be called to properly clean up the memory associated with the object. Under no instance should the kobject that is passed to this function be directly freed with a call to kfree, that can leak memory.

Note, no add uevent will be created with this call, the caller should set up all of the necessary sysfs files for the object and then call kobject_uevent with the UEVENT_ADD parameter to ensure that userspace is properly notified of this kobject's creation.


Name

kobject_init_and_add — initialize a kobject structure and add it to the kobject hierarchy

Synopsis

int kobject_init_and_add (kobj,  
 ktype,  
 parent,  
 fmt,  
 ...); 
struct kobject * kobj;
struct kobj_type * ktype;
struct kobject * parent;
const char * fmt;
...;
 

Arguments

kobj

pointer to the kobject to initialize

ktype

pointer to the ktype for this kobject.

parent

pointer to the parent of this kobject.

fmt

the name of the kobject.

...

variable arguments

Description

This function combines the call to kobject_init and kobject_add. The same type of error handling after a call to kobject_add and kobject lifetime rules are the same here.


Name

kobject_rename — change the name of an object

Synopsis

int kobject_rename (kobj,  
 new_name); 
struct kobject * kobj;
const char * new_name;
 

Arguments

kobj

object in question.

new_name

object's new name

Description

It is the responsibility of the caller to provide mutual exclusion between two different calls of kobject_rename on the same kobject and to ensure that new_name is valid and won't conflict with other kobjects.


Name

kobject_del — unlink kobject from hierarchy.

Synopsis

void kobject_del (kobj); 
struct kobject * kobj;
 

Arguments

kobj

object.


Name

kobject_get — increment refcount for object.

Synopsis

struct kobject * kobject_get (kobj); 
struct kobject * kobj;
 

Arguments

kobj

object.


Name

kobject_put — decrement refcount for object.

Synopsis

void kobject_put (kobj); 
struct kobject * kobj;
 

Arguments

kobj

object.

Description

Decrement the refcount, and if 0, call kobject_cleanup.


Name

kobject_create_and_add — create a struct kobject dynamically and register it with sysfs

Synopsis

struct kobject * kobject_create_and_add (name,  
 parent); 
const char * name;
struct kobject * parent;
 

Arguments

name

the name for the kset

parent

the parent kobject of this kobject, if any.

Description

This function creates a kobject structure dynamically and registers it with sysfs. When you are finished with this structure, call kobject_put and the structure will be dynamically freed when it is no longer being used.

If the kobject was not able to be created, NULL will be returned.


Name

kset_register — initialize and add a kset.

Synopsis

int kset_register (k); 
struct kset * k;
 

Arguments

k

kset.


Name

kset_unregister — remove a kset.

Synopsis

void kset_unregister (k); 
struct kset * k;
 

Arguments

k

kset.


Name

kset_create_and_add — create a struct kset dynamically and add it to sysfs

Synopsis

struct kset * kset_create_and_add (name,  
 uevent_ops,  
 parent_kobj); 
const char * name;
const struct kset_uevent_ops * uevent_ops;
struct kobject * parent_kobj;
 

Arguments

name

the name for the kset

uevent_ops

a struct kset_uevent_ops for the kset

parent_kobj

the parent kobject of this kset, if any.

Description

This function creates a kset structure dynamically and registers it with sysfs. When you are finished with this structure, call kset_unregister and the structure will be dynamically freed when it is no longer being used.

If the kset was not able to be created, NULL will be returned.

Kernel utility functions

Name

upper_32_bits — return bits 32-63 of a number

Synopsis

upper_32_bits (n); 
n;
 

Arguments

n

the number we're accessing

Description

A basic shift-right of a 64- or 32-bit quantity. Use this to suppress the right shift count >= width of type warning when that quantity is 32-bits.


Name

lower_32_bits — return bits 0-31 of a number

Synopsis

lower_32_bits (n); 
n;
 

Arguments

n

the number we're accessing


Name

might_sleep — annotation for functions that can sleep

Synopsis

might_sleep (); 
 

Arguments

None

Description

this macro will print a stack trace if it is executed in an atomic context (spinlock, irq-handler, ...).

This is a useful debugging help to be able to catch problems early and not be bitten later when the calling function happens to sleep when it is not supposed to.


Name

trace_printk — printf formatting in the ftrace buffer

Synopsis

trace_printk (fmt,  
 args...); 
fmt;
args...;
 

Arguments

fmt

the printf format for printing

args...

variable arguments

Note

__trace_printk is an internal function for trace_printk and the ip is passed in via the trace_printk macro.

This function allows a kernel developer to debug fast path sections that printk is not appropriate for. By scattering in various printk like tracing in the code, a developer can quickly see where problems are occurring.

This is intended as a debugging tool for the developer only. Please refrain from leaving trace_printks scattered around in your code.


Name

min_not_zero — return the minimum that is _not_ zero, unless both are zero

Synopsis

min_not_zero (x,  
 y); 
x;
y;
 

Arguments

x

value1

y

value2


Name

clamp — return a value clamped to a given range with strict typechecking

Synopsis

clamp (val,  
 min,  
 max); 
val;
min;
max;
 

Arguments

val

current value

min

minimum allowable value

max

maximum allowable value

Description

This macro does strict typechecking of min/max to make sure they are of the same type as val. See the unnecessary pointer comparisons.


Name

clamp_t — return a value clamped to a given range using a given type

Synopsis

clamp_t (type,  
 val,  
 min,  
 max); 
type;
val;
min;
max;
 

Arguments

type

the type of variable to use

val

current value

min

minimum allowable value

max

maximum allowable value

Description

This macro does no typechecking and uses temporary variables of type 'type' to make all the comparisons.


Name

clamp_val — return a value clamped to a given range using val's type

Synopsis

clamp_val (val,  
 min,  
 max); 
val;
min;
max;
 

Arguments

val

current value

min

minimum allowable value

max

maximum allowable value

Description

This macro does no typechecking and uses temporary variables of whatever type the input argument 'val' is. This is useful when val is an unsigned type and min and max are literals that will otherwise be assigned a signed integer type.


Name

container_of — cast a member of a structure out to the containing structure

Synopsis

container_of (ptr,  
 type,  
 member); 
ptr;
type;
member;
 

Arguments

ptr

the pointer to the member.

type

the type of the container struct this is embedded in.

member

the name of the member within the struct.


Name

BUILD_BUG_ON — break compile if a condition is true.

Synopsis

BUILD_BUG_ON (condition); 
condition;
 

Arguments

condition

the condition which the compiler should know is false.

Description

If you have some code which relies on certain constants being equal, or other compile-time-evaluated condition, you should use BUILD_BUG_ON to detect if someone changes it.

The implementation uses gcc's reluctance to create a negative array, but gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments to inline functions). So as a fallback we use the optimizer; if it can't prove the condition is false, it will cause a link error on the undefined __build_bug_on_failed. This error message can be harder to track down though, hence the two different methods.


Name

printk — print a kernel message

Synopsis

int printk (fmt,  
 ...); 
const char * fmt;
...;
 

Arguments

fmt

format string

...

variable arguments

Description

This is printk. It can be called from any context. We want it to work.

We try to grab the console_lock. If we succeed, it's easy - we log the output and call the console drivers. If we fail to get the semaphore we place the output into the log buffer and return. The current holder of the console_sem will notice the new output in console_unlock; and will send it to the consoles before releasing the lock.

One effect of this deferred printing is that code which calls printk and then changes console_loglevel may break. This is because console_loglevel is inspected when the actual printing occurs.

See also

printf(3)

See the vsnprintf documentation for format string extensions over C99.


Name

console_lock — lock the console system for exclusive use.

Synopsis

void console_lock (void); 
void;
 

Arguments

void

no arguments

Description

Acquires a lock which guarantees that the caller has exclusive access to the console system and the console_drivers list.

Can sleep, returns nothing.


Name

console_trylock — try to lock the console system for exclusive use.

Synopsis

int console_trylock (void); 
void;
 

Arguments

void

no arguments

Description

Tried to acquire a lock which guarantees that the caller has exclusive access to the console system and the console_drivers list.

returns 1 on success, and 0 on failure to acquire the lock.


Name

console_unlock — unlock the console system

Synopsis

void console_unlock (void); 
void;
 

Arguments

void

no arguments

Description

Releases the console_lock which the caller holds on the console system and the console driver list.

While the console_lock was held, console output may have been buffered by printk. If this is the case, console_unlock; emits the output prior to releasing the lock.

If there is output waiting for klogd, we wake it up.

console_unlock; may be called from any context.


Name

console_conditional_schedule — yield the CPU if required

Synopsis

void __sched console_conditional_schedule (void); 
void;
 

Arguments

void

no arguments

Description

If the console code is currently allowed to sleep, and if this CPU should yield the CPU to another task, do so here.

Must be called within console_lock;.


Name

printk_timed_ratelimit — caller-controlled printk ratelimiting

Synopsis

bool printk_timed_ratelimit (caller_jiffies,  
 interval_msecs); 
unsigned long * caller_jiffies;
unsigned int interval_msecs;
 

Arguments

caller_jiffies

pointer to caller's state

interval_msecs

minimum interval between prints

Description

printk_timed_ratelimit returns true if more than interval_msecs milliseconds have elapsed since the last time printk_timed_ratelimit returned true.


Name

kmsg_dump_register — register a kernel log dumper.

Synopsis

int kmsg_dump_register (dumper); 
struct kmsg_dumper * dumper;
 

Arguments

dumper

pointer to the kmsg_dumper structure

Description

Adds a kernel log dumper to the system. The dump callback in the structure will be called when the kernel oopses or panics and must be set. Returns zero on success and -EINVAL or -EBUSY otherwise.


Name

kmsg_dump_unregister — unregister a kmsg dumper.

Synopsis

int kmsg_dump_unregister (dumper); 
struct kmsg_dumper * dumper;
 

Arguments

dumper

pointer to the kmsg_dumper structure

Description

Removes a dump device from the system. Returns zero on success and -EINVAL otherwise.


Name

panic — halt the system

Synopsis

NORET_TYPE void panic (fmt,  
 ...); 
const char * fmt;
...;
 

Arguments

fmt

The text string to print

...

variable arguments

Description

Display a message, then perform cleanups.

This function never returns.


Name

emergency_restart — reboot the system

Synopsis

void emergency_restart (void); 
void;
 

Arguments

void

no arguments

Description

Without shutting down any hardware or taking any locks reboot the system. This is called when we know we are in trouble so this is our best effort to reboot. This is safe to call in interrupt context.


Name

kernel_restart — reboot the system

Synopsis

void kernel_restart (cmd); 
char * cmd;
 

Arguments

cmd

pointer to buffer containing command to execute for restart or NULL

Description

Shutdown everything and perform a clean reboot. This is not safe to call in interrupt context.


Name

kernel_halt — halt the system

Synopsis

void kernel_halt (void); 
void;
 

Arguments

void

no arguments

Description

Shutdown everything and perform a clean system halt.


Name

kernel_power_off — power_off the system

Synopsis

void kernel_power_off (void); 
void;
 

Arguments

void

no arguments

Description

Shutdown everything and perform a clean system power_off.


Name

orderly_poweroff — Trigger an orderly system poweroff

Synopsis

int orderly_poweroff (force); 
bool force;
 

Arguments

force

force poweroff if command execution fails

Description

This may be called from any context to trigger a system shutdown. If the orderly shutdown fails, it will force an immediate shutdown.


Name

rcu_read_lock_bh_held — might we be in RCU-bh read-side critical section?

Synopsis

int rcu_read_lock_bh_held (void); 
void;
 

Arguments

void

no arguments

Description

Check for bottom half being disabled, which covers both the CONFIG_PROVE_RCU and not cases. Note that if someone uses rcu_read_lock_bh, but then later enables BH, lockdep (if enabled) will show the situation. This is useful for debug checks in functions that require that they be called within an RCU read-side critical section.

Check debug_lockdep_rcu_enabled to prevent false positives during boot.


Name

init_rcu_head_on_stack — initialize on-stack rcu_head for debugobjects

Synopsis

void init_rcu_head_on_stack (head); 
struct rcu_head * head;
 

Arguments

head

pointer to rcu_head structure to be initialized

Description

This function informs debugobjects of a new rcu_head structure that has been allocated as an auto variable on the stack. This function is not required for rcu_head structures that are statically defined or that are dynamically allocated on the heap. This function has no effect for !CONFIG_DEBUG_OBJECTS_RCU_HEAD kernel builds.


Name

destroy_rcu_head_on_stack — destroy on-stack rcu_head for debugobjects

Synopsis

void destroy_rcu_head_on_stack (head); 
struct rcu_head * head;
 

Arguments

head

pointer to rcu_head structure to be initialized

Description

This function informs debugobjects that an on-stack rcu_head structure is about to go out of scope. As with init_rcu_head_on_stack, this function is not required for rcu_head structures that are statically defined or that are dynamically allocated on the heap. Also as with init_rcu_head_on_stack, this function has no effect for !CONFIG_DEBUG_OBJECTS_RCU_HEAD kernel builds.

Device Resource Management

Name

devres_alloc — Allocate device resource data

Synopsis

void * devres_alloc (release,  
 size,  
 gfp); 
dr_release_t release;
size_t size;
gfp_t gfp;
 

Arguments

release

Release function devres will be associated with

size

Allocation size

gfp

Allocation flags

Description

Allocate devres of size bytes. The allocated area is zeroed, then associated with release. The returned pointer can be passed to other devres_*() functions.

RETURNS

Pointer to allocated devres on success, NULL on failure.


Name

devres_free — Free device resource data

Synopsis

void devres_free (res); 
void * res;
 

Arguments

res

Pointer to devres data to free

Description

Free devres created with devres_alloc.


Name

devres_add — Register device resource

Synopsis

void devres_add (dev,  
 res); 
struct device * dev;
void * res;
 

Arguments

dev

Device to add resource to

res

Resource to register

Description

Register devres res to dev. res should have been allocated using devres_alloc. On driver detach, the associated release function will be invoked and devres will be freed automatically.


Name

devres_find — Find device resource

Synopsis

void * devres_find (dev,  
 release,  
 match,  
 match_data); 
struct device * dev;
dr_release_t release;
dr_match_t match;
void * match_data;
 

Arguments

dev

Device to lookup resource from

release

Look for resources associated with this release function

match

Match function (optional)

match_data

Data for the match function

Description

Find the latest devres of dev which is associated with release and for which match returns 1. If match is NULL, it's considered to match all.

RETURNS

Pointer to found devres, NULL if not found.


Name

devres_get — Find devres, if non-existent, add one atomically

Synopsis

void * devres_get (dev,  
 new_res,  
 match,  
 match_data); 
struct device * dev;
void * new_res;
dr_match_t match;
void * match_data;
 

Arguments

dev

Device to lookup or add devres for

new_res

Pointer to new initialized devres to add if not found

match

Match function (optional)

match_data

Data for the match function

Description

Find the latest devres of dev which has the same release function as new_res and for which match return 1. If found, new_res is freed; otherwise, new_res is added atomically.

RETURNS

Pointer to found or added devres.


Name

devres_remove — Find a device resource and remove it

Synopsis

void * devres_remove (dev,  
 release,  
 match,  
 match_data); 
struct device * dev;
dr_release_t release;
dr_match_t match;
void * match_data;
 

Arguments

dev

Device to find resource from

release

Look for resources associated with this release function

match

Match function (optional)

match_data

Data for the match function

Description

Find the latest devres of dev associated with release and for which match returns 1. If match is NULL, it's considered to match all. If found, the resource is removed atomically and returned.

RETURNS

Pointer to removed devres on success, NULL if not found.


Name

devres_destroy — Find a device resource and destroy it

Synopsis

int devres_destroy (dev,  
 release,  
 match,  
 match_data); 
struct device * dev;
dr_release_t release;
dr_match_t match;
void * match_data;
 

Arguments

dev

Device to find resource from

release

Look for resources associated with this release function

match

Match function (optional)

match_data

Data for the match function

Description

Find the latest devres of dev associated with release and for which match returns 1. If match is NULL, it's considered to match all. If found, the resource is removed atomically and freed.

RETURNS

0 if devres is found and freed, -ENOENT if not found.


Name

devres_open_group — Open a new devres group

Synopsis

void * devres_open_group (dev,  
 id,  
 gfp); 
struct device * dev;
void * id;
gfp_t gfp;
 

Arguments

dev

Device to open devres group for

id

Separator ID

gfp

Allocation flags

Description

Open a new devres group for dev with id. For id, using a pointer to an object which won't be used for another group is recommended. If id is NULL, address-wise unique ID is created.

RETURNS

ID of the new group, NULL on failure.


Name

devres_close_group — Close a devres group

Synopsis

void devres_close_group (dev,  
 id); 
struct device * dev;
void * id;
 

Arguments

dev

Device to close devres group for

id

ID of target group, can be NULL

Description

Close the group identified by id. If id is NULL, the latest open group is selected.


Name

devres_remove_group — Remove a devres group

Synopsis

void devres_remove_group (dev,  
 id); 
struct device * dev;
void * id;
 

Arguments

dev

Device to remove group for

id

ID of target group, can be NULL

Description

Remove the group identified by id. If id is NULL, the latest open group is selected. Note that removing a group doesn't affect any other resources.


Name

devres_release_group — Release resources in a devres group

Synopsis

int devres_release_group (dev,  
 id); 
struct device * dev;
void * id;
 

Arguments

dev

Device to release group for

id

ID of target group, can be NULL

Description

Release all resources in the group identified by id. If id is NULL, the latest open group is selected. The selected group and groups properly nested inside the selected group are removed.

RETURNS

The number of released non-group resources.


Name

devm_kzalloc — Resource-managed kzalloc

Synopsis

void * devm_kzalloc (dev,  
 size,  
 gfp); 
struct device * dev;
size_t size;
gfp_t gfp;
 

Arguments

dev

Device to allocate memory for

size

Allocation size

gfp

Allocation gfp flags

Description

Managed kzalloc. Memory allocated with this function is automatically freed on driver detach. Like all other devres resources, guaranteed alignment is unsigned long long.

RETURNS

Pointer to allocated memory on success, NULL on failure.


Name

devm_kfree — Resource-managed kfree

Synopsis

void devm_kfree (dev,  
 p); 
struct device * dev;
void * p;
 

Arguments

dev

Device this memory belongs to

p

Memory to free

Description

Free memory allocated with dev_kzalloc.

Chapter 2. Device drivers infrastructure

The Basic Device Driver-Model Structures

Name

struct bus_type — The bus type of the device

Synopsis

struct bus_type {
  const char * name;
  struct bus_attribute * bus_attrs;
  struct device_attribute * dev_attrs;
  struct driver_attribute * drv_attrs;
  int (* match) (struct device *dev, struct device_driver *drv);
  int (* uevent) (struct device *dev, struct kobj_uevent_env *env);
  int (* probe) (struct device *dev);
  int (* remove) (struct device *dev);
  void (* shutdown) (struct device *dev);
  int (* suspend) (struct device *dev, pm_message_t state);
  int (* resume) (struct device *dev);
  const struct dev_pm_ops * pm;
  struct subsys_private * p;
};  

Members

name

The name of the bus.

bus_attrs

Default attributes of the bus.

dev_attrs

Default attributes of the devices on the bus.

drv_attrs

Default attributes of the device drivers on the bus.

match

Called, perhaps multiple times, whenever a new device or driver is added for this bus. It should return a nonzero value if the given device can be handled by the given driver.

uevent

Called when a device is added, removed, or a few other things that generate uevents to add the environment variables.

probe

Called when a new device or driver add to this bus, and callback the specific driver's probe to initial the matched device.

remove

Called when a device removed from this bus.

shutdown

Called at shut-down time to quiesce the device.

suspend

Called when a device on this bus wants to go to sleep mode.

resume

Called to bring a device on this bus out of sleep mode.

pm

Power management operations of this bus, callback the specific device driver's pm-ops.

p

The private data of the driver core, only the driver core can touch this.

Description

A bus is a channel between the processor and one or more devices. For the purposes of the device model, all devices are connected via a bus, even if it is an internal, virtual, platform bus. Buses can plug into each other. A USB controller is usually a PCI device, for example. The device model represents the actual connections between buses and the devices they control. A bus is represented by the bus_type structure. It contains the name, the default attributes, the bus' methods, PM operations, and the driver core's private data.


Name

struct device_driver — The basic device driver structure

Synopsis

struct device_driver {
  const char * name;
  struct bus_type * bus;
  struct module * owner;
  const char * mod_name;
  bool suppress_bind_attrs;
  const struct of_device_id * of_match_table;
  int (* probe) (struct device *dev);
  int (* remove) (struct device *dev);
  void (* shutdown) (struct device *dev);
  int (* suspend) (struct device *dev, pm_message_t state);
  int (* resume) (struct device *dev);
  const struct attribute_group ** groups;
  const struct dev_pm_ops * pm;
  struct driver_private * p;
};  

Members

name

Name of the device driver.

bus

The bus which the device of this driver belongs to.

owner

The module owner.

mod_name

Used for built-in modules.

suppress_bind_attrs

Disables bind/unbind via sysfs.

of_match_table

The open firmware table.

probe

Called to query the existence of a specific device, whether this driver can work with it, and bind the driver to a specific device.

remove

Called when the device is removed from the system to unbind a device from this driver.

shutdown

Called at shut-down time to quiesce the device.

suspend

Called to put the device to sleep mode. Usually to a low power state.

resume

Called to bring a device from sleep mode.

groups

Default attributes that get created by the driver core automatically.

pm

Power management operations of the device which matched this driver.

p

Driver core's private data, no one other than the driver core can touch this.

Description

The device driver-model tracks all of the drivers known to the system. The main reason for this tracking is to enable the driver core to match up drivers with new devices. Once drivers are known objects within the system, however, a number of other things become possible. Device drivers can export information and configuration variables that are independent of any specific device.


Name

struct class — device classes

Synopsis

struct class {
  const char * name;
  struct module * owner;
  struct class_attribute * class_attrs;
  struct device_attribute * dev_attrs;
  struct bin_attribute * dev_bin_attrs;
  struct kobject * dev_kobj;
  int (* dev_uevent) (struct device *dev, struct kobj_uevent_env *env);
  char *(* devnode) (struct device *dev, mode_t *mode);
  void (* class_release) (struct class *class);
  void (* dev_release) (struct device *dev);
  int (* suspend) (struct device *dev, pm_message_t state);
  int (* resume) (struct device *dev);
  const struct kobj_ns_type_operations * ns_type;
  const void *(* namespace) (struct device *dev);
  const struct dev_pm_ops * pm;
  struct subsys_private * p;
};  

Members

name

Name of the class.

owner

The module owner.

class_attrs

Default attributes of this class.

dev_attrs

Default attributes of the devices belong to the class.

dev_bin_attrs

Default binary attributes of the devices belong to the class.

dev_kobj

The kobject that represents this class and links it into the hierarchy.

dev_uevent

Called when a device is added, removed from this class, or a few other things that generate uevents to add the environment variables.

devnode

Callback to provide the devtmpfs.

class_release

Called to release this class.

dev_release

Called to release the device.

suspend

Used to put the device to sleep mode, usually to a low power state.

resume

Used to bring the device from the sleep mode.

ns_type

Callbacks so sysfs can detemine namespaces.

namespace

Namespace of the device belongs to this class.

pm

The default device power management operations of this class.

p

The private data of the driver core, no one other than the driver core can touch this.

Description

A class is a higher-level view of a device that abstracts out low-level implementation details. Drivers may see a SCSI disk or an ATA disk, but, at the class level, they are all simply disks. Classes allow user space to work with devices based on what they do, rather than how they are connected or how they work.


Name

struct device — The basic device structure

Synopsis

struct device {
  struct device * parent;
  struct device_private * p;
  struct kobject kobj;
  const char * init_name;
  const struct device_type * type;
  struct mutex mutex;
  struct bus_type * bus;
  struct device_driver * driver;
  void * platform_data;
  struct dev_pm_info power;
  struct dev_power_domain * pwr_domain;
#ifdef CONFIG_NUMA
  int numa_node;
#endif
  u64 * dma_mask;
  u64 coherent_dma_mask;
  struct device_dma_parameters * dma_parms;
  struct list_head dma_pools;
  struct dma_coherent_mem * dma_mem;
  struct dev_archdata archdata;
  struct device_node * of_node;
  dev_t devt;
  spinlock_t devres_lock;
  struct list_head devres_head;
  struct klist_node knode_class;
  struct class * class;
  const struct attribute_group ** groups;
  void (* release) (struct device *dev);
};  

Members

parent

The device's parent device, the device to which it is attached. In most cases, a parent device is some sort of bus or host controller. If parent is NULL, the device, is a top-level device, which is not usually what you want.

p

Holds the private data of the driver core portions of the device. See the comment of the struct device_private for detail.

kobj

A top-level, abstract class from which other classes are derived.

init_name

Initial name of the device.

type

The type of device. This identifies the device type and carries type-specific information.

mutex

Mutex to synchronize calls to its driver.

bus

Type of bus device is on.

driver

Which driver has allocated this

platform_data

Platform data specific to the device.

power

For device power management. See Documentation/power/devices.txt for details.

pwr_domain

Provide callbacks that are executed during system suspend, hibernation, system resume and during runtime PM transitions along with subsystem-level and driver-level callbacks.

numa_node

NUMA node this device is close to.

dma_mask

Dma mask (if dma'ble device).

coherent_dma_mask

Like dma_mask, but for alloc_coherent mapping as not all hardware supports 64-bit addresses for consistent allocations such descriptors.

dma_parms

A low level driver may set these to teach IOMMU code about segment limitations.

dma_pools

Dma pools (if dma'ble device).

dma_mem

Internal for coherent mem override.

archdata

For arch-specific additions.

of_node

Associated device tree node.

devt

For creating the sysfs dev.

devres_lock

Spinlock to protect the resource of the device.

devres_head

The resources list of the device.

knode_class

The node used to add the device to the class list.

class

The class of the device.

groups

Optional attribute groups.

release

Callback to free the device after all references have gone away. This should be set by the allocator of the device (i.e. the bus driver that discovered the device).

Example

   For devices on custom boards, as typical of embedded
   and SOC based hardware, Linux often uses platform_data to point
   to board-specific structures describing devices and how they
   are wired.  That can include what ports are available, chip
   variants, which GPIO pins act in what additional roles, and so
   on.  This shrinks the Board Support Packages (BSPs) and
   minimizes board-specific #ifdefs in drivers.

Description

At the lowest level, every device in a Linux system is represented by an instance of struct device. The device structure contains the information that the device model core needs to model the system. Most subsystems, however, track additional information about the devices they host. As a result, it is rare for devices to be represented by bare device structures; instead, that structure, like kobject structures, is usually embedded within a higher-level representation of the device.

Device Drivers Base

Name

driver_for_each_device — Iterator for devices bound to a driver.

Synopsis

int driver_for_each_device (drv,  
 start,  
 data,  
 fn); 
struct device_driver * drv;
struct device * start;
void * data;
int (*fn) (struct device *, void *);
 

Arguments

drv

Driver we're iterating.

start

Device to begin with

data

Data to pass to the callback.

fn

Function to call for each device.

Description

Iterate over the drv's list of devices calling fn for each one.


Name

driver_find_device — device iterator for locating a particular device.

Synopsis

struct device * driver_find_device (drv,  
 start,  
 data,  
 match); 
struct device_driver * drv;
struct device * start;
void * data;
int (*match) (struct device *dev, void *data);
 

Arguments

drv

The device's driver

start

Device to begin with

data

Data to pass to match function

match

Callback function to check device

Description

This is similar to the driver_for_each_device function above, but it returns a reference to a device that is 'found' for later use, as determined by the match callback.

The callback should return 0 if the device doesn't match and non-zero if it does. If the callback returns non-zero, this function will return to the caller and not iterate over any more devices.


Name

driver_create_file — create sysfs file for driver.

Synopsis

int driver_create_file (drv,  
 attr); 
struct device_driver * drv;
const struct driver_attribute * attr;
 

Arguments

drv

driver.

attr

driver attribute descriptor.


Name

driver_remove_file — remove sysfs file for driver.

Synopsis

void driver_remove_file (drv,  
 attr); 
struct device_driver * drv;
const struct driver_attribute * attr;
 

Arguments

drv

driver.

attr

driver attribute descriptor.


Name

driver_add_kobj — add a kobject below the specified driver

Synopsis

int driver_add_kobj (drv,  
 kobj,  
 fmt,  
 ...); 
struct device_driver * drv;
struct kobject * kobj;
const char * fmt;
...;
 

Arguments

drv

requesting device driver

kobj

kobject to add below this driver

fmt

format string that names the kobject

...

variable arguments

Description

You really don't want to do this, this is only here due to one looney iseries driver, go poke those developers if you are annoyed about this...


Name

get_driver — increment driver reference count.

Synopsis

struct device_driver * get_driver (drv); 
struct device_driver * drv;
 

Arguments

drv

driver.


Name

put_driver — decrement driver's refcount.

Synopsis

void put_driver (drv); 
struct device_driver * drv;
 

Arguments

drv

driver.


Name

driver_register — register driver with bus

Synopsis

int driver_register (drv); 
struct device_driver * drv;
 

Arguments

drv

driver to register

Description

We pass off most of the work to the bus_add_driver call, since most of the things we have to do deal with the bus structures.


Name

driver_unregister — remove driver from system.

Synopsis

void driver_unregister (drv); 
struct device_driver * drv;
 

Arguments

drv

driver.

Description

Again, we pass off most of the work to the bus-level call.


Name

driver_find — locate driver on a bus by its name.

Synopsis

struct device_driver * driver_find (name,  
 bus); 
const char * name;
struct bus_type * bus;
 

Arguments

name

name of the driver.

bus

bus to scan for the driver.

Description

Call kset_find_obj to iterate over list of drivers on a bus to find driver by name. Return driver if found.

Note that kset_find_obj increments driver's reference count.


Name

dev_driver_string — Return a device's driver name, if at all possible

Synopsis

const char * dev_driver_string (dev); 
const struct device * dev;
 

Arguments

dev

struct device to get the name of

Description

Will return the device's driver's name if it is bound to a device. If the device is not bound to a device, it will return the name of the bus it is attached to. If it is not attached to a bus either, an empty string will be returned.


Name

device_create_file — create sysfs attribute file for device.

Synopsis

int device_create_file (dev,  
 attr); 
struct device * dev;
const struct device_attribute * attr;
 

Arguments

dev

device.

attr

device attribute descriptor.


Name

device_remove_file — remove sysfs attribute file.

Synopsis

void device_remove_file (dev,  
 attr); 
struct device * dev;
const struct device_attribute * attr;
 

Arguments

dev

device.

attr

device attribute descriptor.


Name

device_create_bin_file — create sysfs binary attribute file for device.

Synopsis

int device_create_bin_file (dev,  
 attr); 
struct device * dev;
const struct bin_attribute * attr;
 

Arguments

dev

device.

attr

device binary attribute descriptor.


Name

device_remove_bin_file — remove sysfs binary attribute file

Synopsis

void device_remove_bin_file (dev,  
 attr); 
struct device * dev;
const struct bin_attribute * attr;
 

Arguments

dev

device.

attr

device binary attribute descriptor.


Name

device_schedule_callback_owner — helper to schedule a callback for a device

Synopsis

int device_schedule_callback_owner (dev,  
 func,  
 owner); 
struct device * dev;
void (*func) (struct device *);
struct module * owner;
 

Arguments

dev

device.

func

callback function to invoke later.

owner

module owning the callback routine

Description

Attribute methods must not unregister themselves or their parent device (which would amount to the same thing). Attempts to do so will deadlock, since unregistration is mutually exclusive with driver callbacks.

Instead methods can call this routine, which will attempt to allocate and schedule a workqueue request to call back func with dev as its argument in the workqueue's process context. dev will be pinned until func returns.

This routine is usually called via the inline device_schedule_callback, which automatically sets owner to THIS_MODULE.

Returns 0 if the request was submitted, -ENOMEM if storage could not be allocated, -ENODEV if a reference to owner isn't available.

NOTE

This routine won't work if CONFIG_SYSFS isn't set! It uses an underlying sysfs routine (since it is intended for use by attribute methods), and if sysfs isn't available you'll get nothing but -ENOSYS.


Name

device_initialize — init device structure.

Synopsis

void device_initialize (dev); 
struct device * dev;
 

Arguments

dev

device.

Description

This prepares the device for use by other layers by initializing its fields. It is the first half of device_register, if called by that function, though it can also be called separately, so one may use dev's fields. In particular, get_device/put_device may be used for reference counting of dev after calling this function.

NOTE

Use put_device to give up your reference instead of freeing dev directly once you have called this function.


Name

dev_set_name — set a device name

Synopsis

int dev_set_name (dev,  
 fmt,  
 ...); 
struct device * dev;
const char * fmt;
...;
 

Arguments

dev

device

fmt

format string for the device's name

...

variable arguments


Name

device_add — add device to device hierarchy.

Synopsis

int device_add (dev); 
struct device * dev;
 

Arguments

dev

device.

Description

This is part 2 of device_register, though may be called separately _iff_ device_initialize has been called separately.

This adds dev to the kobject hierarchy via kobject_add, adds it to the global and sibling lists for the device, then adds it to the other relevant subsystems of the driver model.

NOTE

_Never_ directly free dev after calling this function, even if it returned an error! Always use put_device to give up your reference instead.


Name

device_register — register a device with the system.

Synopsis

int device_register (dev); 
struct device * dev;
 

Arguments

dev

pointer to the device structure

Description

This happens in two clean steps - initialize the device and add it to the system. The two steps can be called separately, but this is the easiest and most common. I.e. you should only call the two helpers separately if have a clearly defined need to use and refcount the device before it is added to the hierarchy.

NOTE

_Never_ directly free dev after calling this function, even if it returned an error! Always use put_device to give up the reference initialized in this function instead.


Name

get_device — increment reference count for device.

Synopsis

struct device * get_device (dev); 
struct device * dev;
 

Arguments

dev

device.

Description

This simply forwards the call to kobject_get, though we do take care to provide for the case that we get a NULL pointer passed in.


Name

put_device — decrement reference count.

Synopsis

void put_device (dev); 
struct device * dev;
 

Arguments

dev

device in question.


Name

device_del — delete device from system.

Synopsis

void device_del (dev); 
struct device * dev;
 

Arguments

dev

device.

Description

This is the first part of the device unregistration sequence. This removes the device from the lists we control from here, has it removed from the other driver model subsystems it was added to in device_add, and removes it from the kobject hierarchy.

NOTE

this should be called manually _iff_ device_add was also called manually.


Name

device_unregister — unregister device from system.

Synopsis

void device_unregister (dev); 
struct device * dev;
 

Arguments

dev

device going away.

Description

We do this in two parts, like we do device_register. First, we remove it from all the subsystems with device_del, then we decrement the reference count via put_device. If that is the final reference count, the device will be cleaned up via device_release above. Otherwise, the structure will stick around until the final reference to the device is dropped.


Name

device_for_each_child — device child iterator.

Synopsis

int device_for_each_child (parent,  
 data,  
 fn); 
struct device * parent;
void * data;
int (*fn) (struct device *dev, void *data);
 

Arguments

parent

parent struct device.

data

data for the callback.

fn

function to be called for each device.

Description

Iterate over parent's child devices, and call fn for each, passing it data.

We check the return of fn each time. If it returns anything other than 0, we break out and return that value.


Name

device_find_child — device iterator for locating a particular device.

Synopsis

struct device * device_find_child (parent,  
 data,  
 match); 
struct device * parent;
void * data;
int (*match) (struct device *dev, void *data);
 

Arguments

parent

parent struct device

data

Data to pass to match function

match

Callback function to check device

Description

This is similar to the device_for_each_child function above, but it returns a reference to a device that is 'found' for later use, as determined by the match callback.

The callback should return 0 if the device doesn't match and non-zero if it does. If the callback returns non-zero and a reference to the current device can be obtained, this function will return to the caller and not iterate over any more devices.


Name

__root_device_register — allocate and register a root device

Synopsis

struct device * __root_device_register (name,  
 owner); 
const char * name;
struct module * owner;
 

Arguments

name

root device name

owner

owner module of the root device, usually THIS_MODULE

Description

This function allocates a root device and registers it using device_register. In order to free the returned device, use root_device_unregister.

Root devices are dummy devices which allow other devices to be grouped under /sys/devices. Use this function to allocate a root device and then use it as the parent of any device which should appear under /sys/devices/{name}

The /sys/devices/{name} directory will also contain a 'module' symlink which points to the owner directory in sysfs.

Returns struct device pointer on success, or ERR_PTR on error.

Note

You probably want to use root_device_register.


Name

root_device_unregister — unregister and free a root device

Synopsis

void root_device_unregister (dev); 
struct device * dev;
 

Arguments

dev

device going away

Description

This function unregisters and cleans up a device that was created by root_device_register.


Name

device_create_vargs — creates a device and registers it with sysfs

Synopsis

struct device * device_create_vargs (class,  
 parent,  
 devt,  
 drvdata,  
 fmt,  
 args); 
struct class * class;
struct device * parent;
dev_t devt;
void * drvdata;
const char * fmt;
va_list args;
 

Arguments

class

pointer to the struct class that this device should be registered to

parent

pointer to the parent struct device of this new device, if any

devt

the dev_t for the char device to be added

drvdata

the data to be added to the device for callbacks

fmt

string for the device's name

args

va_list for the device's name

Description

This function can be used by char device classes. A struct device will be created in sysfs, registered to the specified class.

A dev file will be created, showing the dev_t for the device, if the dev_t is not 0,0. If a pointer to a parent struct device is passed in, the newly created struct device will be a child of that device in sysfs. The pointer to the struct device will be returned from the call. Any further sysfs files that might be required can be created using this pointer.

Returns struct device pointer on success, or ERR_PTR on error.

Note

the struct class passed to this function must have previously been created with a call to class_create.


Name

device_create — creates a device and registers it with sysfs

Synopsis

struct device * device_create (class,  
 parent,  
 devt,  
 drvdata,  
 fmt,  
 ...); 
struct class * class;
struct device * parent;
dev_t devt;
void * drvdata;
const char * fmt;
...;
 

Arguments

class

pointer to the struct class that this device should be registered to

parent

pointer to the parent struct device of this new device, if any

devt

the dev_t for the char device to be added

drvdata

the data to be added to the device for callbacks

fmt

string for the device's name

...

variable arguments

Description

This function can be used by char device classes. A struct device will be created in sysfs, registered to the specified class.

A dev file will be created, showing the dev_t for the device, if the dev_t is not 0,0. If a pointer to a parent struct device is passed in, the newly created struct device will be a child of that device in sysfs. The pointer to the struct device will be returned from the call. Any further sysfs files that might be required can be created using this pointer.

Returns struct device pointer on success, or ERR_PTR on error.

Note

the struct class passed to this function must have previously been created with a call to class_create.


Name

device_destroy — removes a device that was created with device_create

Synopsis

void device_destroy (class,  
 devt); 
struct class * class;
dev_t devt;
 

Arguments

class

pointer to the struct class that this device was registered with

devt

the dev_t of the device that was previously registered

Description

This call unregisters and cleans up a device that was created with a call to device_create.


Name

device_rename — renames a device

Synopsis

int device_rename (dev,  
 new_name); 
struct device * dev;
const char * new_name;
 

Arguments

dev

the pointer to the struct device to be renamed

new_name

the new name of the device

Description

It is the responsibility of the caller to provide mutual exclusion between two different calls of device_rename on the same device to ensure that new_name is valid and won't conflict with other devices.

Note

Don't call this function. Currently, the networking layer calls this function, but that will change. The following text from Kay Sievers offers

some insight

Renaming devices is racy at many levels, symlinks and other stuff are not replaced atomically, and you get a move uevent, but it's not easy to connect the event to the old and new device. Device nodes are not renamed at all, there isn't even support for that in the kernel now.

In the meantime, during renaming, your target name might be taken by another driver, creating conflicts. Or the old name is taken directly after you renamed it -- then you get events for the same DEVPATH, before you even see the move event. It's just a mess, and nothing new should ever rely on kernel device renaming. Besides that, it's not even implemented now for other things than (driver-core wise very simple) network devices.

We are currently about to change network renaming in udev to completely disallow renaming of devices in the same namespace as the kernel uses, because we can't solve the problems properly, that arise with swapping names of multiple interfaces without races. Means, renaming of eth[0-9]* will only be allowed to some other name than eth[0-9]*, for the aforementioned reasons.

Make up a real name in the driver before you register anything, or add some other attributes for userspace to find the device, or use udev to add symlinks -- but never rename kernel devices later, it's a complete mess. We don't even want to get into that and try to implement the missing pieces in the core. We really have other pieces to fix in the driver core mess. :)


Name

device_move — moves a device to a new parent

Synopsis

int device_move (dev,  
 new_parent,  
 dpm_order); 
struct device * dev;
struct device * new_parent;
enum dpm_order dpm_order;
 

Arguments

dev

the pointer to the struct device to be moved

new_parent

the new parent of the device (can by NULL)

dpm_order

how to reorder the dpm_list


Name

__class_create — create a struct class structure

Synopsis

struct class * __class_create (owner,  
 name,  
 key); 
struct module * owner;
const char * name;
struct lock_class_key * key;
 

Arguments

owner

pointer to the module that is to own this struct class

name

pointer to a string for the name of this class.

key

the lock_class_key for this class; used by mutex lock debugging

Description

This is used to create a struct class pointer that can then be used in calls to device_create.

Returns struct class pointer on success, or ERR_PTR on error.

Note, the pointer created here is to be destroyed when finished by making a call to class_destroy.


Name

class_destroy — destroys a struct class structure

Synopsis

void class_destroy (cls); 
struct class * cls;
 

Arguments

cls

pointer to the struct class that is to be destroyed

Description

Note, the pointer to be destroyed must have been created with a call to class_create.


Name

class_dev_iter_init — initialize class device iterator

Synopsis

void class_dev_iter_init (iter,  
 class,  
 start,  
 type); 
struct class_dev_iter * iter;
struct class * class;
struct device * start;
const struct device_type * type;
 

Arguments

iter

class iterator to initialize

class

the class we wanna iterate over

start

the device to start iterating from, if any

type

device_type of the devices to iterate over, NULL for all

Description

Initialize class iterator iter such that it iterates over devices of class. If start is set, the list iteration will start there, otherwise if it is NULL, the iteration starts at the beginning of the list.


Name

class_dev_iter_next — iterate to the next device

Synopsis

struct device * class_dev_iter_next (iter); 
struct class_dev_iter * iter;
 

Arguments

iter

class iterator to proceed

Description

Proceed iter to the next device and return it. Returns NULL if iteration is complete.

The returned device is referenced and won't be released till iterator is proceed to the next device or exited. The caller is free to do whatever it wants to do with the device including calling back into class code.


Name

class_dev_iter_exit — finish iteration

Synopsis

void class_dev_iter_exit (iter); 
struct class_dev_iter * iter;
 

Arguments

iter

class iterator to finish

Description

Finish an iteration. Always call this function after iteration is complete whether the iteration ran till the end or not.


Name

class_for_each_device — device iterator

Synopsis

int class_for_each_device (class,  
 start,  
 data,  
 fn); 
struct class * class;
struct device * start;
void * data;
int (*fn) (struct device *, void *);
 

Arguments

class

the class we're iterating

start

the device to start with in the list, if any.

data

data for the callback

fn

function to be called for each device

Description

Iterate over class's list of devices, and call fn for each, passing it data. If start is set, the list iteration will start there, otherwise if it is NULL, the iteration starts at the beginning of the list.

We check the return of fn each time. If it returns anything other than 0, we break out and return that value.

fn is allowed to do anything including calling back into class code. There's no locking restriction.


Name

class_find_device — device iterator for locating a particular device

Synopsis

struct device * class_find_device (class,  
 start,  
 data,  
 match); 
struct class * class;
struct device * start;
void * data;
int (*match) (struct device *, void *);
 

Arguments

class

the class we're iterating

start

Device to begin with

data

data for the match function

match

function to check device

Description

This is similar to the class_for_each_dev function above, but it returns a reference to a device that is 'found' for later use, as determined by the match callback.

The callback should return 0 if the device doesn't match and non-zero if it does. If the callback returns non-zero, this function will return to the caller and not iterate over any more devices.

Note, you will need to drop the reference with put_device after use.

fn is allowed to do anything including calling back into class code. There's no locking restriction.


Name

class_compat_register — register a compatibility class

Synopsis

struct class_compat * class_compat_register (name); 
const char * name;
 

Arguments

name

the name of the class

Description

Compatibility class are meant as a temporary user-space compatibility workaround when converting a family of class devices to a bus devices.


Name

class_compat_unregister — unregister a compatibility class

Synopsis

void class_compat_unregister (cls); 
struct class_compat * cls;
 

Arguments

cls

the class to unregister


Name

class_compat_create_link — create a compatibility class device link to a bus device

Synopsis

int class_compat_create_link (cls,  
 dev,  
 device_link); 
struct class_compat * cls;
struct device * dev;
struct device * device_link;
 

Arguments

cls

the compatibility class

dev

the target bus device

device_link

an optional device to which a device link should be created


Name

class_compat_remove_link — remove a compatibility class device link to a bus device

Synopsis

void class_compat_remove_link (cls,  
 dev,  
 device_link); 
struct class_compat * cls;
struct device * dev;
struct device * device_link;
 

Arguments

cls

the compatibility class

dev

the target bus device

device_link

an optional device to which a device link was previously created


Name

request_firmware — send firmware request and wait for it

Synopsis

int request_firmware (firmware_p,  
 name,  
 device); 
const struct firmware ** firmware_p;
const char * name;
struct device * device;
 

Arguments

firmware_p

pointer to firmware image

name

name of firmware file

device

device for which firmware is being loaded

Description

firmware_p will be used to return a firmware image by the name of name for device device.

Should be called from user context where sleeping is allowed.

name will be used as $FIRMWARE in the uevent environment and should be distinctive enough not to be confused with any other firmware image for this or any other device.


Name

release_firmware — release the resource associated with a firmware image

Synopsis

void release_firmware (fw); 
const struct firmware * fw;
 

Arguments

fw

firmware resource to release


Name

request_firmware_nowait — asynchronous version of request_firmware

Synopsis

int request_firmware_nowait (module,  
 uevent,  
 name,  
 device,  
 gfp,  
 context,  
 cont); 
struct module * module;
bool uevent;
const char * name;
struct device * device;
gfp_t gfp;
void * context;
void (*cont) (const struct firmware *fw, void *context);
 

Arguments

module

module requesting the firmware

uevent

sends uevent to copy the firmware image if this flag is non-zero else the firmware copy must be done manually.

name

name of firmware file

device

device for which firmware is being loaded

gfp

allocation flags

context

will be passed over to cont, and fw may be NULL if firmware request fails.

cont

function will be called asynchronously when the firmware request is over.

Description

Asynchronous variant of request_firmware for user contexts where it is not possible to sleep for long time. It can't be called in atomic contexts.


Name

transport_class_register — register an initial transport class

Synopsis

int transport_class_register (tclass); 
struct transport_class * tclass;
 

Arguments

tclass

a pointer to the transport class structure to be initialised

Description

The transport class contains an embedded class which is used to identify it. The caller should initialise this structure with zeros and then generic class must have been initialised with the actual transport class unique name. There's a macro DECLARE_TRANSPORT_CLASS to do this (declared classes still must be registered).

Returns 0 on success or error on failure.


Name

transport_class_unregister — unregister a previously registered class

Synopsis

void transport_class_unregister (tclass); 
struct transport_class * tclass;
 

Arguments

tclass

The transport class to unregister

Description

Must be called prior to deallocating the memory for the transport class.


Name

anon_transport_class_register — register an anonymous class

Synopsis

int anon_transport_class_register (atc); 
struct anon_transport_class * atc;
 

Arguments

atc

The anon transport class to register

Description

The anonymous transport class contains both a transport class and a container. The idea of an anonymous class is that it never actually has any device attributes associated with it (and thus saves on container storage). So it can only be used for triggering events. Use prezero and then use DECLARE_ANON_TRANSPORT_CLASS to initialise the anon transport class storage.


Name

anon_transport_class_unregister — unregister an anon class

Synopsis

void anon_transport_class_unregister (atc); 
struct anon_transport_class * atc;
 

Arguments

atc

Pointer to the anon transport class to unregister

Description

Must be called prior to deallocating the memory for the anon transport class.


Name

transport_setup_device — declare a new dev for transport class association but don't make it visible yet.

Synopsis

void transport_setup_device (dev); 
struct device * dev;
 

Arguments

dev

the generic device representing the entity being added

Description

Usually, dev represents some component in the HBA system (either the HBA itself or a device remote across the HBA bus). This routine is simply a trigger point to see if any set of transport classes wishes to associate with the added device. This allocates storage for the class device and initialises it, but does not yet add it to the system or add attributes to it (you do this with transport_add_device). If you have no need for a separate setup and add operations, use transport_register_device (see transport_class.h).


Name

transport_add_device — declare a new dev for transport class association

Synopsis

void transport_add_device (dev); 
struct device * dev;
 

Arguments

dev

the generic device representing the entity being added

Description

Usually, dev represents some component in the HBA system (either the HBA itself or a device remote across the HBA bus). This routine is simply a trigger point used to add the device to the system and register attributes for it.


Name

transport_configure_device — configure an already set up device

Synopsis

void transport_configure_device (dev); 
struct device * dev;
 

Arguments

dev

generic device representing device to be configured

Description

The idea of configure is simply to provide a point within the setup process to allow the transport class to extract information from a device after it has been setup. This is used in SCSI because we have to have a setup device to begin using the HBA, but after we send the initial inquiry, we use configure to extract the device parameters. The device need not have been added to be configured.


Name

transport_remove_device — remove the visibility of a device

Synopsis

void transport_remove_device (dev); 
struct device * dev;
 

Arguments

dev

generic device to remove

Description

This call removes the visibility of the device (to the user from sysfs), but does not destroy it. To eliminate a device entirely you must also call transport_destroy_device. If you don't need to do remove and destroy as separate operations, use transport_unregister_device (see transport_class.h) which will perform both calls for you.


Name

transport_destroy_device — destroy a removed device

Synopsis

void transport_destroy_device (dev); 
struct device * dev;
 

Arguments

dev

device to eliminate from the transport class.

Description

This call triggers the elimination of storage associated with the transport classdev. Note: all it really does is relinquish a reference to the classdev. The memory will not be freed until the last reference goes to zero. Note also that the classdev retains a reference count on dev, so dev too will remain for as long as the transport class device remains around.


Name

sysdev_driver_register — Register auxiliary driver

Synopsis

int sysdev_driver_register (cls,  
 drv); 
struct sysdev_class * cls;
struct sysdev_driver * drv;
 

Arguments

cls

Device class driver belongs to.

drv

Driver.

Description

drv is inserted into cls->drivers to be called on each operation on devices of that class. The refcount of cls is incremented.


Name

sysdev_driver_unregister — Remove an auxiliary driver.

Synopsis

void sysdev_driver_unregister (cls,  
 drv); 
struct sysdev_class * cls;
struct sysdev_driver * drv;
 

Arguments

cls

Class driver belongs to.

drv

Driver.


Name

sysdev_register — add a system device to the tree

Synopsis

int sysdev_register (sysdev); 
struct sys_device * sysdev;
 

Arguments

sysdev

device in question


Name

platform_device_register_simple — add a platform-level device and its resources

Synopsis

struct platform_device * platform_device_register_simple (name,  
 id,  
 res,  
 num); 
const char * name;
int id;
const struct resource * res;
unsigned int num;
 

Arguments

name

base name of the device we're adding

id

instance id

res

set of resources that needs to be allocated for the device

num

number of resources

Description

This function creates a simple platform device that requires minimal resource and memory management. Canned release function freeing memory allocated for the device allows drivers using such devices to be unloaded without waiting for the last reference to the device to be dropped.

This interface is primarily intended for use with legacy drivers which probe hardware directly. Because such drivers create sysfs device nodes themselves, rather than letting system infrastructure handle such device enumeration tasks, they don't fully conform to the Linux driver model. In particular, when such drivers are built as modules, they can't be hotplugged.

Returns struct platform_device pointer on success, or ERR_PTR on error.


Name

platform_device_register_data — add a platform-level device with platform-specific data

Synopsis

struct platform_device * platform_device_register_data (parent,  
 name,  
 id,  
 data,  
 size); 
struct device * parent;
const char * name;
int id;
const void * data;
size_t size;
 

Arguments

parent

parent device for the device we're adding

name

base name of the device we're adding

id

instance id

data

platform specific data for this platform device

size

size of platform specific data

Description

This function creates a simple platform device that requires minimal resource and memory management. Canned release function freeing memory allocated for the device allows drivers using such devices to be unloaded without waiting for the last reference to the device to be dropped.

Returns struct platform_device pointer on success, or ERR_PTR on error.


Name

platform_get_resource — get a resource for a device

Synopsis

struct resource * platform_get_resource (dev,  
 type,  
 num); 
struct platform_device * dev;
unsigned int type;
unsigned int num;
 

Arguments

dev

platform device

type

resource type

num

resource index


Name

platform_get_irq — get an IRQ for a device

Synopsis

int platform_get_irq (