linux/drivers/mxc/security/sahara2/sah_memory_mapper.c File Reference

Re-creates SAHARA data structures in Kernel memory such that they are suitable for DMA. Provides support for kernel API. More...

Data Structures

struct  mem_block
struct  mem_big_block

Typedefs

typedef struct mem_block Mem_Block
typedef struct mem_big_block Mem_Big_Block

Functions

static Mem_Blocksah_Alloc_Block (void)
static void sah_Free_Block (Mem_Block *block)
static Mem_Big_Blocksah_Alloc_Big_Block (void)
static void sah_Free_Big_Block (Mem_Big_Block *block)
static void sah_Append_Block (Mem_Block *block)
static void sah_Append_Big_Block (Mem_Big_Block *block)
void * wire_user_memory (void *address, uint32_t length, void **page_ctx)
void unwire_user_memory (void **page_ctx)
os_error_code map_user_memory (struct vm_area_struct *vma, uint32_t physical_addr, uint32_t size)
os_error_code unmap_user_memory (uint32_t user_addr, uint32_t size)
void sah_Free_Descriptor (sah_Desc *desc)
void sah_Free_Head_Descriptor (sah_Head_Desc *desc)
void sah_Free_Link (sah_Link *link)
sah_Head_Descsah_Copy_Descriptors (fsl_shw_uco_t *user_ctx, sah_Head_Desc *user_head_desc)
sah_Linksah_Physicalise_Links (sah_Link *first_link)
sah_Head_Descsah_Physicalise_Descriptors (sah_Head_Desc *first_desc)
sah_Linksah_DePhysicalise_Links (sah_Link *first_link)
sah_Head_Descsah_DePhysicalise_Descriptors (sah_Head_Desc *first_desc)
void sah_Free_Chained_Descriptors (sah_Head_Desc *head_desc)
void sah_Free_Chained_Links (sah_Link *link)
sah_Linksah_Copy_Links (fsl_shw_uco_t *user_ctx, sah_Link *ptr)
sah_Linksah_Make_Links (fsl_shw_uco_t *user_ctx, sah_Link *ptr, sah_Link **tail)
void sah_Destroy_Descriptors (sah_Head_Desc *head_desc)
void sah_Destroy_Links (sah_Link *link)
int sah_Init_Mem_Map (void)
void sah_Stop_Mem_Map (void)
sah_Head_Descsah_Alloc_Head_Descriptor (void)
sah_Descsah_Alloc_Descriptor (void)
sah_Linksah_Alloc_Link (void)
int sah_Block_Add_Page (int big)

Variables

static os_lock_t mem_lock
static Mem_Blockblock_free_head = NULL
static Mem_Blockblock_free_tail = NULL
static Mem_Big_Blockbig_block_free_head = NULL
static Mem_Big_Blockbig_block_free_tail = NULL

Detailed Description

Re-creates SAHARA data structures in Kernel memory such that they are suitable for DMA. Provides support for kernel API.

This file needs to be ported.

The memory mapper gets a call at sah_Init_Mem_Map() during driver initialization.

The routine sah_Copy_Descriptors() is used to bring descriptor chains from user memory down to kernel memory, relink using physical addresses, and make sure that all user data will be accessible by the Sahara DMA. sah_Destroy_Descriptors() does the inverse.

The sah_Alloc_Block(), sah_Free_Block(), and sah_Block_Add_Page() routines implement a cache of free blocks used when allocating descriptors and links within the kernel.

The memory mapper gets a call at sah_Stop_Mem_Map() during driver shutdown.


Typedef Documentation

typedef struct mem_big_block Mem_Big_Block

Structure for head descriptor memory blocks in internal pool

typedef struct mem_block Mem_Block

Structure for link/descriptor memory blocks in internal pool


Function Documentation

static Mem_Big_Block * sah_Alloc_Big_Block ( void   )  [static]

Allocate memory block.

Allocate block from free pool. A block is large enough to fit either a link or descriptor.

Returns:
Mem_Block Free block, NULL if no free blocks available.

References mem_lock, mem_big_block::next, os_lock_save_context, os_unlock_restore_context, and sah_Block_Add_Page().

Referenced by sah_Alloc_Head_Descriptor().

static Mem_Block * sah_Alloc_Block ( void   )  [static]

Allocate memory block.

Allocate block from free pool. A block is large enough to fit either a link or descriptor.

Returns:
Mem_Block Free block, NULL if no free blocks available.

References mem_lock, mem_block::next, os_lock_save_context, os_unlock_restore_context, and sah_Block_Add_Page().

Referenced by sah_Alloc_Descriptor(), and sah_Alloc_Link().

sah_Desc* sah_Alloc_Descriptor ( void   ) 

Allocate descriptor.

Allocate descriptor from free pool.

Returns:
sah_Desc Free descriptor, NULL if no free descriptors available.

References mem_block::data, mem_block::dma_addr, sah_Desc::next, sah_Desc::ptr1, sah_Desc::ptr2, and sah_Alloc_Block().

Referenced by sah_Copy_Descriptors().

sah_Head_Desc* sah_Alloc_Head_Descriptor ( void   ) 

Allocate Head descriptor.

Allocate Head descriptor from free pool.

Returns:
sah_Head_Desc Free descriptor, NULL if no free descriptors available.

References mem_big_block::data, sah_Head_Desc::desc, mem_big_block::dma_addr, sah_Desc::next, sah_Desc::ptr1, sah_Desc::ptr2, and sah_Alloc_Big_Block().

Referenced by sah_Copy_Descriptors(), and sah_HW_Reset().

sah_Link* sah_Alloc_Link ( void   ) 

Allocate link.

Allocate link from free pool.

Returns:
sah_Link Free link, NULL if no free links available.

References sah_Link::data, mem_block::data, mem_block::dma_addr, sah_Link::flags, sah_Link::len, sah_Link::next, and sah_Alloc_Block().

Referenced by sah_Make_Links(), and sah_Physicalise_Links().

static void sah_Append_Big_Block ( Mem_Big_Block block  )  [static]

Append memory block to free pool.

Append memory block to end of free pool.

Parameters:
block A block entry
Returns:
none
Precondition:
This function must be called with the mem_lock held.

References mem_big_block::next.

Referenced by sah_Block_Add_Page(), and sah_Free_Big_Block().

static void sah_Append_Block ( Mem_Block block  )  [static]

Append memory block to free pool.

Append memory block to end of free pool.

Parameters:
block A block entry
Returns:
none
Precondition:
mem_lock must be held

References mem_block::next.

Referenced by sah_Block_Add_Page(), and sah_Free_Block().

int sah_Block_Add_Page ( int  big  ) 

Add page of blocks to block free pool.

Add a new page to end of block free pool. This will allocate one page and fill the pool with entries, appending to the end.

Precondition:
This function must be called with the mem_lock held.
Parameters:
big 0 - make blocks big enough for sah_Desc non-zero - make blocks big enough for sah_Head_Desc
Returns:
int TRUE if blocks added succeesfully, FALSE otherwise

References mem_block::dma_addr, mem_big_block::dma_addr, os_alloc_coherent, os_alloc_memory, os_pa, sah_Append_Big_Block(), and sah_Append_Block().

Referenced by sah_Alloc_Big_Block(), and sah_Alloc_Block().

sah_Head_Desc* sah_Copy_Descriptors ( fsl_shw_uco_t user_ctx,
sah_Head_Desc user_head_desc 
)

Kernel Descriptor Chain Copier.

This function runs through a descriptor chain pointed to by a user-space address. It duplicates each descriptor in Kernel space memory and calls sah_Copy_Links() to handle any links attached to the descriptors. This function cleans-up everything that it created in the case of a failure.

Parameters:
fsl_shw_uco_t The user context to act under
user_head_desc A Head Descriptor pointer from user-space.
Returns:
sah_Head_Desc * - A virtual address of the first descriptor in the chain.
NULL - If there was some error.

References sah_Head_Desc::desc, FSL_RETURN_INTERNAL_ERROR_S, FSL_RETURN_NO_RESOURCE_S, FSL_RETURN_OK_S, FSL_UCO_SAVE_DESC_CHAIN, sah_Desc::header, sah_Desc::next, os_flush_cache_all, sah_Head_Desc::out1_ptr, sah_Desc::ptr1, sah_Desc::ptr2, sah_Alloc_Descriptor(), sah_Alloc_Head_Descriptor(), sah_Copy_Links(), sah_Destroy_Descriptors(), sah_Head_Desc::uco_flags, and sah_Head_Desc::user_ref.

Referenced by handle_sah_ioctl_dar().

sah_Link* sah_Copy_Links ( fsl_shw_uco_t user_ctx,
sah_Link ptr 
)

Kernel Link Chain Copier.

This function runs through a link chain pointed to by a user-space address. It makes a temporary kernel-space copy of each link in the chain and calls sah_Make_Links() to create a set of kernel-side links to replace it.

Parameters:
ptr A link pointer from user-space.
Returns:
sah_Link * - The virtual address of the first link in the chain.
NULL - If there was some error.

References FSL_RETURN_INTERNAL_ERROR_S, FSL_RETURN_OK_S, sah_Link::len, sah_Link::next, sah_Destroy_Links(), and sah_Make_Links().

Referenced by sah_Copy_Descriptors().

sah_Head_Desc* sah_DePhysicalise_Descriptors ( sah_Head_Desc first_desc  ) 

Run through descriptors and links that have been Physicalised (sah_Physicalise_Descriptors function) and set the dma addresses back to KM virtual addresses

Parameters:
first_desc Kernel virtual address of first descriptor in chain.

Warning! This ONLY works without LLO flags in headers!!!

References sah_Head_Desc::desc, FSL_UCO_CHAIN_PREPHYSICALIZED, sah_DePhysicalise_Links(), and sah_Head_Desc::uco_flags.

Referenced by sah_blocking_mode(), sah_get_results_from_pool(), and sah_Physicalise_Descriptors().

sah_Link* sah_DePhysicalise_Links ( sah_Link first_link  ) 

Convert physical Link chain.

This function runs through a sah_Link chain pointed to by a physical address. It computes the virtual address for each pointer

Parameters:
first_link A kernel address of a sah_Link
Returns:
sah_Link * A kernal address for the link chain of first_link
NULL If there was some error.
Postcondition:
All links will be chained together by original virtual addresses, data pointers will point to virtual addresses. Appropriate cache lines will be flushed, memory unwired, etc.

References sah_Link::len, sah_Link::next, os_cache_inv_range, os_printk, sah_Free_Link(), SAH_IN_USER_KEYSTORE, SAH_LINK_INSERTED_LINK, SAH_OUTPUT_LINK, SAH_PREPHYS_DATA, and SAH_STORED_KEY_INFO.

Referenced by sah_DePhysicalise_Descriptors().

void sah_Destroy_Descriptors ( sah_Head_Desc head_desc  ) 

Kernel Descriptor Chain Destructor.

This walks through a SAHARA descriptor chain and frees everything that is not NULL. Finally it also unmaps all of the physical memory and frees the kiobuf_list Queue.

Parameters:
desc A Descriptor pointer from kernel-space. This should be in bus address space.
Returns:
void

References sah_Desc::header, sah_Desc::len1, sah_Desc::len2, sah_Desc::next, os_flush_cache_all, sah_Desc::ptr1, sah_Desc::ptr2, sah_Destroy_Links(), sah_Free_Descriptor(), and sah_Free_Head_Descriptor().

Referenced by sah_Copy_Descriptors().

void sah_Destroy_Links ( sah_Link link  ) 

Kernel Link Chain Destructor.

This walks through a SAHARA link chain and frees everything that is not NULL excluding user-space buffers.

Parameters:
link A Link pointer from kernel-space.
Returns:
void

References sah_Link::data, sah_Link::len, sah_Link::next, and sah_Free_Link().

Referenced by sah_Copy_Links(), sah_Destroy_Descriptors(), and sah_Make_Links().

static void sah_Free_Big_Block ( Mem_Big_Block block  )  [static]

Free memory block.

Free memory block back to free pool

Parameters:
block A block allocated with sah_Alloc_Block().
Returns:
none

References mem_lock, os_lock_save_context, os_unlock_restore_context, and sah_Append_Big_Block().

Referenced by sah_Free_Head_Descriptor().

static void sah_Free_Block ( Mem_Block block  )  [static]

Free memory block.

Free memory block back to free pool

Parameters:
block A block allocated with sah_Alloc_Block().
Returns:
none

References mem_lock, os_lock_save_context, os_unlock_restore_context, and sah_Append_Block().

Referenced by sah_Free_Descriptor(), and sah_Free_Link().

void sah_Free_Chained_Descriptors ( sah_Head_Desc head_desc  ) 

Kernel Descriptor Chain Destructor.

This walks through a SAHARA descriptor chain and free()'s everything that is not NULL. Finally it also unmaps all of the physical memory and frees the kiobuf_list Queue.

Parameters:
head_desc A Descriptor pointer from kernel-space.
Returns:
void

References sah_Head_Desc::desc, sah_Desc::header, sah_Desc::len1, sah_Desc::len2, sah_Desc::next, sah_Desc::ptr1, sah_Desc::ptr2, sah_Free_Chained_Links(), sah_Free_Descriptor(), and sah_Free_Head_Descriptor().

Referenced by handle_sah_ioctl_dar(), and sah_get_results_pointers().

void sah_Free_Chained_Links ( sah_Link link  ) 

Kernel Link Chain Destructor.

This walks through a SAHARA link chain and frees everything that is not NULL, excluding user-space buffers.

Parameters:
link A Link pointer from kernel-space. This is in bus address space.
Returns:
void

References sah_Link::data, sah_Link::len, sah_Link::next, sah_Link::ownerid, and sah_Free_Link().

Referenced by sah_Free_Chained_Descriptors().

void sah_Free_Descriptor ( sah_Desc desc  ) 

Free descriptor.

Free descriptor back to free pool

Parameters:
desc A descriptor allocated with sah_Alloc_Descriptor().
Returns:
none

References sah_Free_Block().

Referenced by sah_Destroy_Descriptors(), and sah_Free_Chained_Descriptors().

void sah_Free_Head_Descriptor ( sah_Head_Desc desc  ) 

Free Head descriptor.

Free Head descriptor back to free pool

Parameters:
desc A Head descriptor allocated with sah_Alloc_Head_Descriptor().
Returns:
none

References sah_Free_Big_Block().

Referenced by sah_Destroy_Descriptors(), sah_Free_Chained_Descriptors(), and sah_HW_Reset().

void sah_Free_Link ( sah_Link link  ) 

Free link.

Free link back to free pool

Parameters:
link A link allocated with sah_Alloc_Link().
Returns:
none

References sah_Free_Block().

Referenced by sah_DePhysicalise_Links(), sah_Destroy_Links(), sah_Free_Chained_Links(), and sah_Make_Links().

int sah_Init_Mem_Map ( void   ) 

Initialize memory manager/mapper.

In 2.4, this function also allocates a kiovec to be used when mapping user data to kernel space

Returns:
0 for success, OS error code on failure

References mem_lock, OS_ERROR_FAIL_S, OS_ERROR_OK_S, os_lock_alloc_init(), and os_printk.

Referenced by OS_DEV_INIT().

sah_Link* sah_Make_Links ( fsl_shw_uco_t user_ctx,
sah_Link ptr,
sah_Link **  tail 
)

Kernel Link Chain Constructor.

This function takes an input link pointed to by a user-space address and returns a chain of links that span the physical pages pointed to by the input link.

Parameters:
ptr A link pointer from user-space.
tail The address of a link pointer. This is used to return the tail link created by this function.
Returns:
sah_Link * - A virtual address of the first link in the chain.
NULL - If there was some error.

References sah_Link::data, sah_Link::flags, FSL_RETURN_BAD_DATA_LENGTH_S, FSL_RETURN_INTERNAL_ERROR_S, FSL_RETURN_NO_RESOURCE_S, FSL_RETURN_OK_S, sah_Link::len, sah_Link::next, os_cache_clean_range, os_cache_flush_range, sah_Link::ownerid, sah_Alloc_Link(), sah_Destroy_Links(), sah_Free_Link(), SAH_IN_USER_KEYSTORE, SAH_OUTPUT_LINK, SAH_PREPHYS_DATA, SAH_STORED_KEY_INFO, and sah_Link::slot.

Referenced by sah_Copy_Links().

sah_Head_Desc* sah_Physicalise_Descriptors ( sah_Head_Desc first_desc  ) 

Run through descriptors and links created by KM-API and set the dma addresses and 'do not free' flags.

Parameters:
first_desc KERNEL VIRTUAL address of first descriptor in chain.

Warning! This ONLY works without LLO flags in headers!!!

Returns:
Virtual address of first_desc.
NULL if Descriptor Chain could not be physicalised

References sah_Head_Desc::desc, FSL_UCO_CHAIN_PREPHYSICALIZED, sah_Desc::next, sah_Head_Desc::next, os_printk, sah_DePhysicalise_Descriptors(), sah_Physicalise_Links(), and sah_Head_Desc::uco_flags.

Referenced by adaptor_Exec_Descriptor_Chain().

sah_Link* sah_Physicalise_Links ( sah_Link first_link  ) 

Convert kernel Link chain.

This function runs through a sah_Link chain pointed to by a kernel-space address. It computes the physical address for each pointer, and converts the chain to use these physical addresses.

This function needs to return some indication that the chain could not be converted. It also needs to back out any conversion already taken place on this chain of links.

Then, of course, sah_Physicalise_Descriptors() will need to recognize that an error occured, and then be able to back out any physicalization of the chain which had taken place up to that point!

Parameters:
first_link A sah_Link pointer from kernel space; must not be NULL, so error case can be distinguished.
Returns:
sah_Link * A dma'able address of the first descriptor in the chain.
NULL If Link chain could not be physicalised, i.e. ERROR

References sah_Link::data, sah_Link::flags, FSL_RETURN_OK_S, sah_Link::len, sah_Link::next, os_cache_clean_range, os_cache_flush_range, os_pa, os_printk, sah_Alloc_Link(), SAH_IN_USER_KEYSTORE, SAH_LINK_INSERTED_LINK, SAH_OUTPUT_LINK, SAH_OWNS_LINK_DATA, SAH_PREPHYS_DATA, and SAH_STORED_KEY_INFO.

Referenced by sah_Physicalise_Descriptors().

void sah_Stop_Mem_Map ( void   ) 

Clean up memory manager/mapper.

In 2.4, this function also frees the kiovec used when mapping user data to kernel space.

Returns:
none

References mem_lock, and os_lock_deallocate.

Referenced by OS_DEV_SHUTDOWN().


Variable Documentation

Memory block free pool - pointer to first block. Chain is protected by mem_lock.

Memory block free pool - pointer to last block. Chain is protected by mem_lock. a

Mem_Block* block_free_head = NULL [static]

Memory block free pool - pointer to first block. Chain is protected by mem_lock.

Mem_Block* block_free_tail = NULL [static]

Memory block free pool - pointer to last block. Chain is protected by mem_lock.

os_lock_t mem_lock [static]
footer
©  Freescale Semiconductor, Inc., 2007.  All rights reserved.
Freescale Confidential Proprietary
NDA Required
doxygen