linux/drivers/mxc/security/rng/shw_driver.c File Reference

Defines

#define FALSE   0
#define TRUE   1

Functions

 OS_DEV_INIT (shw_init)
 OS_DEV_SHUTDOWN (shw_shutdown)
static void shw_cleanup (void)
 OS_DEV_OPEN (shw_open)
 OS_DEV_IOCTL (shw_ioctl)
 OS_DEV_MMAP (shw_mmap)
 OS_DEV_CLOSE (shw_release)
static void shw_user_callback (fsl_shw_uco_t *user_ctx)
static os_error_code shw_setup_user_driver_interaction (void)
static os_error_code init_uco (fsl_shw_uco_t *user_ctx, void *user_mode_uco)
static void * copy_array (void *userloc, void *userend, void *data_start, unsigned element_size, unsigned element_count)
static os_error_code copy_fsl_code (void *user_header, fsl_shw_return_t result_code)
static os_error_code get_capabilities (fsl_shw_uco_t *user_ctx, void *user_mode_pco_request)
static os_error_code get_results (fsl_shw_uco_t *user_ctx, void *user_mode_results_req)
static void process_hdr (fsl_shw_uco_t *user_ctx, struct shw_req_header *hdr)
static os_error_code get_random (fsl_shw_uco_t *user_ctx, void *user_mode_get_random_req)
static os_error_code add_entropy (fsl_shw_uco_t *user_ctx, void *user_mode_add_entropy_req)
fsl_shw_return_t fsl_shw_register_user (fsl_shw_uco_t *user_ctx)
fsl_shw_return_t fsl_shw_deregister_user (fsl_shw_uco_t *user_ctx)
fsl_shw_pco_tfsl_shw_get_capabilities (fsl_shw_uco_t *user_ctx)
fsl_shw_return_t fsl_shw_get_random (fsl_shw_uco_t *user_ctx, uint32_t length, uint8_t *data)
fsl_shw_return_t fsl_shw_add_entropy (fsl_shw_uco_t *user_ctx, uint32_t length, uint8_t *data)
fsl_shw_return_t fsl_shw_hash (fsl_shw_uco_t *user_ctx, fsl_shw_hco_t *hash_ctx, const uint8_t *msg, uint32_t length, uint8_t *result, uint32_t result_len)
fsl_shw_return_t fsl_shw_hmac_precompute (fsl_shw_uco_t *user_ctx, fsl_shw_sko_t *key_info, fsl_shw_hmco_t *hmac_ctx)
fsl_shw_return_t fsl_shw_hmac (fsl_shw_uco_t *user_ctx, fsl_shw_sko_t *key_info, fsl_shw_hmco_t *hmac_ctx, const uint8_t *msg, uint32_t length, uint8_t *result, uint32_t result_len)
fsl_shw_return_t do_scc_encrypt_region (fsl_shw_uco_t *user_ctx, void *partition_base, uint32_t offset_bytes, uint32_t byte_count, uint8_t *black_data, uint32_t *IV, fsl_shw_cypher_mode_t cypher_mode)
fsl_shw_return_t do_scc_decrypt_region (fsl_shw_uco_t *user_ctx, void *partition_base, uint32_t offset_bytes, uint32_t byte_count, const uint8_t *black_data, uint32_t *IV, fsl_shw_cypher_mode_t cypher_mode)
void * fsl_shw_smalloc (fsl_shw_uco_t *user_ctx, uint32_t size, const uint8_t *UMID, uint32_t permissions)
fsl_shw_return_t fsl_shw_sfree (fsl_shw_uco_t *user_ctx, void *address)
fsl_shw_return_t fsl_shw_diminish_perms (fsl_shw_uco_t *user_ctx, void *address, uint32_t permissions)
fsl_shw_return_t fsl_shw_gen_encrypt (fsl_shw_uco_t *user_ctx, fsl_shw_acco_t *auth_ctx, fsl_shw_sko_t *cipher_key_info, fsl_shw_sko_t *auth_key_info, uint32_t auth_data_length, const uint8_t *auth_data, uint32_t payload_length, const uint8_t *payload, uint8_t *ct, uint8_t *auth_value)
fsl_shw_return_t fsl_shw_auth_decrypt (fsl_shw_uco_t *user_ctx, fsl_shw_acco_t *auth_ctx, fsl_shw_sko_t *cipher_key_info, fsl_shw_sko_t *auth_key_info, uint32_t auth_data_length, const uint8_t *auth_data, uint32_t payload_length, const uint8_t *ct, const uint8_t *auth_value, uint8_t *payload)
fsl_shw_return_t fsl_shw_gen_random_pf_key (fsl_shw_uco_t *user_ctx)

Variables

static int shw_major_node = SHW_MAJOR_NODE
static int shw_device_registered = 0
static os_driver_reg_t reg_handle
fsl_shw_uco_tuser_list
os_lock_t shw_queue_lock = NULL
static fsl_shw_key_alg_t pf_syms []
static fsl_shw_sym_mode_t pf_modes []
static fsl_shw_hash_alg_t pf_hashes []
static fsl_shw_pco_t cap

Detailed Description

This is the user-mode driver code for the FSL Security Hardware (SHW) API. as well as the 'common' FSL SHW API code for kernel API users.

Its interaction with the Linux kernel is from calls to shw_init() when the driver is loaded, and shw_shutdown() should the driver be unloaded.

The User API (driver interface) is handled by the following functions:

The driver also provides the following functions for kernel users of the FSL SHW API:

All other functions are internal to the driver.

The life of the driver starts at boot (or module load) time, with a call by the kernel to shw_init().

The life of the driver ends when the kernel is shutting down (or the driver is being unloaded). At this time, shw_shutdown() is called. No function will ever be called after that point.

In the case that the driver is reloaded, a new copy of the driver, with fresh global values, etc., is loaded, and there will be a new call to shw_init().

In user mode, the user's fsl_shw_register_user() call causes an open() event on the driver followed by a ioctl() with the registration information. Any subsequent API calls by the user are handled through the ioctl() function and shuffled off to the appropriate routine (or driver) for service. The fsl_shw_deregister_user() call by the user results in a close() function call on the driver.

In kernel mode, the driver provides the functions fsl_shw_register_user(), fsl_shw_deregister_user(), fsl_shw_get_capabilities(), and fsl_shw_get_results(). Other parts of the API are provided by other drivers, if available, to support the cryptographic functions.


Define Documentation

#define FALSE   0

Not true. Guaranteed to be zero.

#define TRUE   1

True. Guaranteed to be non-zero.


Function Documentation

static os_error_code add_entropy ( fsl_shw_uco_t user_ctx,
void *  user_mode_add_entropy_req 
) [static]

Handle user-mode Add Entropy request

Parameters:
user_ctx Pointer to the kernel version of user's context
user_mode_add_entropy_req Address of user-space request
Returns:
an os_error_code

References copy_fsl_code(), fsl_shw_add_entropy(), os_alloc_memory, os_copy_from_user, OS_ERROR_OK_S, and os_free_memory.

Referenced by OS_DEV_IOCTL().

static void* copy_array ( void *  userloc,
void *  userend,
void *  data_start,
unsigned  element_size,
unsigned  element_count 
) [inline, static]

Copy array from kernel to user space.

This routine will check bounds before trying to copy, and return failure on bounds violation or error during the copy.

Parameters:
userloc Location in userloc to place data. If NULL, the function will do nothing (except return NULL).
userend Address beyond allowed copy region at userloc.
data_start Location of data to be copied
element_size sizeof() an element
element_count Number of elements of size element_size to copy.
Returns:
New value of userloc, or NULL if there was an error.

References OS_ERROR_OK_S.

Referenced by get_capabilities().

static os_error_code copy_fsl_code ( void *  user_header,
fsl_shw_return_t  result_code 
) [inline, static]

Send an FSL SHW API return code up into the user-space request structure.

Parameters:
user_header User address of request block / request header
result_code The FSL SHW API code to be placed at header.code
Returns:
an os_error_code

NOTE: This function assumes that the shw_req_header is at the beginning of each request structure.

References os_copy_to_user.

Referenced by add_entropy(), get_capabilities(), get_random(), and get_results().

static os_error_code get_capabilities ( fsl_shw_uco_t user_ctx,
void *  user_mode_pco_request 
) [static]

Handle user-mode Get Capabilities request

Right now, this function can only have a failure if the user has failed to provide a pointer to a location in user space with enough room to hold the fsl_shw_pco_t structure and any associated data. It will treat this failure as an ioctl failure and return an ioctl error code, instead of treating it as an API failure.

Parameters:
user_ctx The kernel version of user's context
user_mode_pco_request Pointer to user-space request
Returns:
an os_error_code

References copy_array(), copy_fsl_code(), FSL_RETURN_OK_S, os_copy_from_user, os_copy_to_user, OS_ERROR_BAD_ADDRESS_S, and OS_ERROR_OK_S.

Referenced by fsl_shw_get_capabilities(), and OS_DEV_IOCTL().

static os_error_code get_random ( fsl_shw_uco_t user_ctx,
void *  user_mode_get_random_req 
) [static]

Handle user-mode Get Random request

Parameters:
user_ctx The kernel version of user's context
user_mode_get_random_req Pointer to user-space request
Returns:
an os_error_code

References copy_fsl_code(), fsl_shw_get_random(), FSL_UCO_BLOCKING_MODE, os_copy_from_user, OS_ERROR_OK_S, and process_hdr().

Referenced by OS_DEV_IOCTL().

static os_error_code get_results ( fsl_shw_uco_t user_ctx,
void *  user_mode_results_req 
) [static]

Handle user-mode Get Results request

Get arguments from user space into kernel space, then call fsl_shw_get_results, and then copy its return code and any results from kernel space back to user space.

Parameters:
user_ctx The kernel version of user's context
user_mode_results_req Pointer to user-space request
Returns:
an os_error_code

References copy_fsl_code(), FSL_RETURN_OK_S, fsl_shw_get_results(), os_alloc_memory, os_copy_from_user, os_copy_to_user, OS_ERROR_NO_MEMORY_S, OS_ERROR_OK_S, and os_free_memory.

Referenced by OS_DEV_IOCTL().

static os_error_code init_uco ( fsl_shw_uco_t user_ctx,
void *  user_mode_uco 
) [static]

Initialze kernel User Context Object from User-space version.

Copy user UCO into kernel UCO, set flags and fields for operation within kernel space. Add user to driver's list of users.

Parameters:
user_ctx Pointer to kernel space UCO
user_mode_uco User pointer to user space version
Returns:
os_error_code

References fsl_shw_uco_t::callback, fsl_shw_uco_t::flags, FSL_UCO_USERMODE_USER, os_copy_from_user, OS_ERROR_OK_S, os_get_process_handle, SHW_ADD_USER(), and shw_user_callback().

Referenced by OS_DEV_IOCTL().

OS_DEV_CLOSE ( shw_release   ) 

Handle close() call from user. This is a Linux device driver interface routine.

Returns:
OS_ERROR_OK_S on success (always!)

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 ( shw_init   ) 
OS_DEV_IOCTL ( shw_ioctl   ) 
OS_DEV_MMAP ( shw_mmap   ) 

This function implements the smalloc() function for userspace programs, by making a call to the SCC2 mmap() function that acquires a region of secure memory on behalf of the user, and then maps it into the users memory space. Currently, the only memory size supported is that of a single SCC2 partition. Requests for other sized memory regions will fail.

References FSL_RETURN_OK_S, fsl_shw_register_user(), map_user_memory(), os_alloc_memory, os_dev_get_user_private, os_dev_set_user_private, OS_ERROR_BAD_ARG_S, OS_ERROR_FAIL_S, OS_ERROR_NO_MEMORY_S, OS_ERROR_OK_S, scc_configuration, and scc_get_configuration().

OS_DEV_OPEN ( shw_open   ) 

Handle open() call from user.

Returns:
OS_ERROR_OK_S on success (always!)

References os_dev_open_return, os_dev_set_user_private, and OS_ERROR_OK_S.

OS_DEV_SHUTDOWN ( shw_shutdown   ) 

Prepare driver for exit.

This is called during rmmod when the driver is unloading or when the kernel is shutting down.

Calls shw_cleanup() to do all work to undo anything that happened during initialization or while driver was running.

References os_dev_shutdown_return, OS_ERROR_OK_S, and shw_cleanup().

static void process_hdr ( fsl_shw_uco_t user_ctx,
struct shw_req_header *  hdr 
) [inline, static]

Process header of user-mode request.

Mark header as User Mode request. Update UCO's flags and reference fields with current versions from the header.

Parameters:
user_ctx Pointer to kernel version of UCO.
hdr Pointer to common part of user request.
Returns:
void

References fsl_shw_uco_t::flags, FSL_UCO_USERMODE_USER, and fsl_shw_uco_t::user_ref.

Referenced by get_random().

static void shw_cleanup ( void   )  [static]

Prepare driver for shutdown.

Remove the driver registration.

References os_driver_remove_registration, os_lock_deallocate, shw_device_registered, and shw_queue_lock.

Referenced by OS_DEV_INIT(), and OS_DEV_SHUTDOWN().

static os_error_code shw_setup_user_driver_interaction ( void   )  [static]

Register the driver with the kernel as the driver for shw_major_node. Note that this value may be zero, in which case the major number will be assigned by the OS. shw_major_node is never modified.

The open(), ioctl(), and close() handles for the driver ned to be registered with the kernel. Upon success, shw_device_registered will be true;

Returns:
OS_ERROR_OK_S on success, or an os err code

References OS_DEV_CLOSE_REF, OS_DEV_IOCTL_REF, OS_DEV_MMAP_REF(), OS_DEV_OPEN_REF, os_driver_add_registration, os_driver_complete_registration, os_driver_get_major, os_driver_init_registration, OS_ERROR_OK_S, OS_FN_CLOSE, OS_FN_IOCTL, OS_FN_MMAP, OS_FN_OPEN, shw_device_registered, SHW_DRIVER_NAME, and shw_major_node.

Referenced by OS_DEV_INIT().

static void shw_user_callback ( fsl_shw_uco_t user_ctx  )  [static]

FSL SHW User callback function.

This function is set in the kernel version of the user context as the callback function when the user mode user wants a callback. Its job is to inform the user process that results (may) be available. It does this by sending a SIGUSR2 signal which is then caught by the user-mode FSL SHW library.

Parameters:
user_ctx Kernel version of uco associated with the request.
Returns:
void

References os_send_signal.

Referenced by init_uco().


Variable Documentation

fsl_shw_pco_t cap [static]
Initial value:
 {
        1, 3,                   
        2, 3,                   
        sizeof(pf_syms) / sizeof(fsl_shw_key_alg_t),    
        pf_syms,                
        sizeof(pf_modes) / sizeof(fsl_shw_sym_mode_t),  
        pf_modes,               
        sizeof(pf_hashes) / sizeof(fsl_shw_hash_alg_t), 
        pf_hashes,              
        
        {                       
         {0, 0, 0, 0}
         ,                      
         {0, 0, 0, 0}
         ,                      
         {0, 0, 0, 0}
         ,                      




         {0, 0, 0, 0}
         ,                      

         {0, 0, 0, 0}           
         }
        ,
        0, 0,                   
        0, 0, 0,                
        {{0, 0}
         }
        ,                       
}

This matches SHW capabilities...

Referenced by csi_v4l_do_ioctl(), mxc_v4l_do_ioctl(), run_user_wrap(), and run_wrap().

Initial value:
 {
}

Empty list of supported hash algorithms.

Initial value:
 {
}

Empty list of supported symmetric modes.

Initial value:
 {
}

Empty list of supported symmetric algorithms.

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

int shw_device_registered = 0 [static]

Flag to know whether the driver has been associated with its user device node (e.g. /dev/shw).

Referenced by shw_cleanup(), and shw_setup_user_driver_interaction().

int shw_major_node = SHW_MAJOR_NODE [static]

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

Referenced by shw_setup_user_driver_interaction().

This is the lock for all user request pools. H/W component drivers may also use it for their own work queues.

Referenced by fsl_shw_deregister_user(), fsl_shw_get_results(), OS_DEV_INIT(), SHW_ADD_USER(), shw_cleanup(), and SHW_REMOVE_USER().

Linked List of registered users of the API

Referenced by SHW_ADD_USER(), and SHW_REMOVE_USER().

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