imx-test-3.0.35-4.1.0/module_test/rng_test_driver.c File Reference

This is a test driver for the RNG driver. More...

Functions

 OS_DEV_INIT (rng_test_init)
 OS_DEV_OPEN (rng_test_open)
 OS_DEV_IOCTL (rng_test_ioctl)
 OS_DEV_CLOSE (rng_test_release)
static os_error_code rng_test_get_random (fsl_shw_uco_t *user_ctx, unsigned long rng_data)
static os_error_code rng_test_add_entropy (fsl_shw_uco_t *user_ctx, unsigned long rng_data)
static os_error_code rng_test_read_register (unsigned long rng_data)
static os_error_code rng_test_write_register (unsigned long rng_data)
static os_error_code rng_test_setup_user_driver_interaction (void)
 OS_DEV_SHUTDOWN (rng_test_cleanup)

Variables

static int rng_test_major_node = RNG_TEST_MAJOR_NODE
static int rng_device_registered = 0
static os_driver_reg_t reg_handle

Detailed Description

This is a test driver for the RNG driver.

This driver and its associated reference test program are intended to demonstrate the use of and excercise the RNG block from kernel space.

The test program also shows use of the RNG driver from user space.


Function Documentation

OS_DEV_CLOSE ( rng_test_release   ) 

Driver interface function for close() system call.

De-register from the FSL SHW API. Free associated memory.

References fsl_shw_deregister_user(), os_dev_close_return, os_dev_get_user_private, os_dev_set_user_private, OS_ERROR_OK_S, and os_free_memory.

OS_DEV_INIT ( rng_test_init   ) 

****************************************************************************

Function Implementations - Externally Accessible

Initialize the driver.

Bind this driver to the RNG device node.

This is called during module load (insmod) or kernel init.

References os_dev_init_return, os_printk, and rng_test_setup_user_driver_interaction().

OS_DEV_IOCTL ( rng_test_ioctl   ) 

Driver interface function for ioctl() system call.

This function serves as a control for the commands being passed by the application code. Depending on what command has been sent, a specific function will occur.

This routine handles the following valid commands:

  • RNG_GET_CONFIGURATION - Return driver, SMN, and SCM versions, memory sizes, block size.
  • RNG_READ_REG - Read register from RNG.
  • RNG_WRITE_REG - Write register to RNG.
Precondition:
Application code supplies a command with the related data (via the rng_data struct)
Postcondition:
A specific action is performed based on the requested command.
Returns:
os_error_code

References os_dev_get_ioctl_arg, os_dev_get_ioctl_op, os_dev_get_user_private, os_dev_ioctl_return, OS_ERROR_FAIL_S, rng_test_add_entropy(), rng_test_get_random(), rng_test_read_register(), and rng_test_write_register().

OS_DEV_OPEN ( rng_test_open   ) 

Driver interface function for open() system call.

Register the test user with the FSL SHW API.

References FSL_RETURN_OK_S, fsl_shw_register_user(), os_alloc_memory, os_dev_open_return, os_dev_set_user_private, OS_ERROR_FAIL_S, OS_ERROR_NO_MEMORY_S, and OS_ERROR_OK_S.

OS_DEV_SHUTDOWN ( rng_test_cleanup   ) 

Prepare driver for exit.

This is called during rmmod when the driver is unloading. Try to undo whatever was done during rng_test_init(), to make the machine be in the same state, if possible.

Mask off RNG interrupts. Put the RNG to sleep?

References os_dev_shutdown_return, os_driver_remove_registration, OS_ERROR_OK_S, os_printk, and rng_device_registered.

static os_error_code rng_test_add_entropy ( fsl_shw_uco_t user_ctx,
unsigned long  rng_data 
) [static]

This function will add randomness to the RNG.

Parameters:
[in] randomness Some 'good' entropy to add to the RNG.
Returns:
See rng_test_return_t.

References fsl_shw_add_entropy(), os_alloc_memory, os_copy_from_user, os_copy_to_user, OS_ERROR_NO_MEMORY_S, os_free_memory, and os_printk.

Referenced by OS_DEV_IOCTL().

static os_error_code rng_test_get_random ( fsl_shw_uco_t user_ctx,
unsigned long  rng_data 
) [static]

This function will retrieve entropy from the internal buffer of the RNG driver. If not enough entropy is available, it will SLEEP until more is available.

Returns:
See rng_return_t.

References fsl_shw_get_random(), os_alloc_memory, os_copy_from_user, os_copy_to_user, OS_ERROR_BAD_ADDRESS_S, os_free_memory, os_printk, and RNG_RET_OK.

Referenced by OS_DEV_IOCTL().

static os_error_code rng_test_read_register ( unsigned long  rng_data  )  [static]

Read value from an RNG register. The offset will be checked for validity (range) as well as whether it is accessible at the time of the call.

Parameters:
[in] register_offset The (byte) offset within the RNG block of the register to be queried. See rngregs for meanings.
[out] value Pointer to where value from the register should be placed.
Returns:
See rng_return_t.

References os_copy_from_user, os_copy_to_user, OS_ERROR_OK_S, and os_printk.

Referenced by OS_DEV_IOCTL().

static os_error_code rng_test_setup_user_driver_interaction ( void   )  [static]

Register the driver as the driver for RNG_TEST_MAJOR_NODE

If RNG_TEST_MAJOR_NODE is zero, then make sure that rng_test_major_node has the registered node value.

References OS_DEV_IOCTL_REF, os_driver_add_registration, os_driver_complete_registration, os_driver_get_major, os_driver_init_registration, OS_ERROR_FAIL_S, OS_ERROR_OK_S, OS_FN_CLOSE, OS_FN_IOCTL, OS_FN_OPEN, os_printk, rng_device_registered, and rng_test_major_node.

Referenced by OS_DEV_INIT().

static os_error_code rng_test_write_register ( unsigned long  rng_data  )  [static]

Write a new value into an RNG register.

The offset will be checked for validity (range) as well as whether it is accessible at the time of the call.

Parameters:
[in] register_offset The (byte) offset within the RNG block of the register to be modified. See rngregs for meanings.
[in] value The value to store into the register.
Returns:
See rng_test_return_t.

References os_copy_from_user, os_copy_to_user, OS_ERROR_OK_S, and os_printk.

Referenced by OS_DEV_IOCTL().


Variable Documentation

OS-independent handle used for registering user interface of a driver.

int rng_device_registered = 0 [static]

Flag to know whether register_chrdev() succeeded. Useful if the driver is ever to be unloaded. 0 is not registered, non-zero is registered.

Referenced by OS_DEV_SHUTDOWN(), and rng_test_setup_user_driver_interaction().

int rng_test_major_node = RNG_TEST_MAJOR_NODE [static]

****************************************************************************

Global / Static Variables

Major node (user/device interaction value) for this driver.

Referenced by rng_test_setup_user_driver_interaction().

footer
©  Freescale Semiconductor, Inc., 2007.  All rights reserved.
Freescale Confidential Proprietary
NDA Required
doxygen