Main Page | Data Structures | File List | Data Fields | Globals

axis_sram.c File Reference


Detailed Description

SRAM access and control from user space.

Author:
Andrew Roca
Allows user access to SRAM. User applications can choose several access mechanisms 1) file type lseek/read/write operations on an open sram device 2) direct access via the mmap call this needs to create page table entries for the user process to allow it access to the physical memory 3) mtd character device access 4) mtd block device access this allows the sram to be used as a RAM disk

This module also supports the sram partitioning scheme. SRAM partition definitions are defined in axis_sram.c and are fixed at compile time. Note at the momemt the MTS system fails if more than one device is defined by the axis driver and the driver attempts to unload

#include "axis_sram.h"
#include <linux/mtd/partitions.h>

Include dependency graph for axis_sram.c:

Include dependency graph

Functions

void update_sram_access (struct sram_block *block)
int set_block_read (struct sram_block *block, int allow)
int set_block_write (struct sram_block *block, int allow)
int set_block_read_write (struct sram_block *block, int read_allow, int write_allow)
int mtd_ram_erase (struct mtd_info *mtd, struct erase_info *instr)
 Function to simulate erasing flash for MTD subsystem.

int mtd_ram_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf)
 passed to MTD system

void mtd_ram_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, size_t len)
 passed to MTD system

int mtd_ram_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buffer)
 Ram read for MTD sub system.

int mtd_ram_write (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buffer)
 Rather than messing about with the SRAM let the Linux MTD support handle it.

int axis_ram_open (struct inode *inode_ptr,struct file *file_ptr)
 open function for sram partition character support

loff_t axis_ram_llseek (struct file *file_ptr, loff_t offset, int where_from)
 handles user lseek calls for SRAM devices.

ssize_t axis_ram_read (struct file *file_ptr, char *buf, size_t count, loff_t *ppos)
 Gets data from a SRAM partition and returns it to userland.

ssize_t axis_ram_write (struct file *file_ptr, const char *buf, size_t count, loff_t *ppos)
 Copies data from USER space and sends it to SRAM.

int axis_ram_ioctl (struct inode *inode_ptr, struct file *file_ptr, unsigned int type, unsigned long data)
 Provides an interface to allow user land to control sram read/write.

int axis_ram_mmap (struct file *file_ptr, struct vm_area_struct *vma)
 handles a user mmap request.

int axis_ram_release (struct inode *inode_ptr, struct file *file_ptr)
 Called by kernel in response to a process closing a device.

int proc_read_sram (char *buf, char **start, off_t offset, int count, int *eof, void *data)
 Outputs data about the current SRAM configuration.

int proc_read_mtd_config (char *buf, char **start, off_t offset, int count, int *eof, void *data)
int proc_read_read_enable (char *buf, char **start, off_t offset, int count, int *eof, void *data)
int proc_read_write_enable (char *buf, char **start, off_t offset, int count, int *eof, void *data)
int proc_write_read_enable (struct file *file, const char *buffer, unsigned long count, void *data)
int proc_write_write_enable (struct file *file, const char *buffer, unsigned long count, void *data)
unsigned long index_to_read_map (unsigned long i)
unsigned long index_to_write_map (unsigned long i)
void init_access_control_entry (struct access_control_entry *ptr, unsigned long start_address, ssize_t length, int write_not_read)
void init_sram_access_control (struct sram_access_control *ptr, unsigned long start_address, ssize_t length)
void create_proc_sram_directory (struct axis_pci_device_entry *device, struct sram_block *block)
void delete_proc_sram_directory (struct axis_pci_device_entry *device, struct sram_block *block)
void create_proc_sram_entries (struct axis_pci_device_entry *device)
 Creates a /proc directory fills it entries that output the current SRAM configuration.

void delete_proc_sram_entries (struct axis_pci_device_entry *device)
 Deletes the SRAM related entries in the /Proc filesystem.

void init_mtd_block (struct mtd_info *block, ssize_t length, char *Name, unsigned int number)
 Initialises a MTD block.

int build_sram_config (struct axis_pci_device_entry *device)
 Read the table defined in sram_config and convert it to a set of memory devices.

void delete_sram_config (struct axis_pci_device_entry *device)
 Removes any SRAM devices created.


Variables

file_operations ram_file_operations

Function Documentation

int axis_ram_ioctl struct inode *  inode_ptr,
struct file *  file_ptr,
unsigned int  type,
unsigned long  data
[static]
 

Provides an interface to allow user land to control sram read/write.

Parameters:
inode_ptr - devices inode
file_ptr - pointer to kernel file structure for open device
type - identifies the IOCTL operation requested
data - unspecified parameter supplied by user program meaning depends on type
Returns:
0 on success error number otherwise

To allow user applications options other then read / write the driver support IOCTL calls the type constants are defined in axis.h

Here is the call graph for this function:

loff_t axis_ram_llseek struct file *  file_ptr,
loff_t  offset,
int  where_from
[static]
 

handles user lseek calls for SRAM devices.

Parameters:
file_ptr - pointer to kernel file structure for open device
offset - file offset requested
where_from - New offset is from head or tail of file
Returns:
new offset

Called by kernel in response to a user application making a llseek call. Resets the file_ptrs f_pos element to new position

int axis_ram_mmap struct file *  file_ptr,
struct vm_area_struct *  vma
[static]
 

handles a user mmap request.

Parameters:
file_ptr - pointer to kernel file structure for open device
vma- kernel virtual memory area structure
Returns:
0 on success error code otherwise

Called by kernel in response to a user application making a mmap call. Enables read / write for SRAM partition and then remaps the requested memory block into the user applications address space so it can access it.

int axis_ram_open struct inode *  inode_ptr,
struct file *  file_ptr
[static]
 

open function for sram partition character support

Parameters:
inode_ptr - pointer to inode structure the kernel will associate with this instance
file_ptr - pointer to the file structure the kernel uses to track this open instance
Returns:
0 on sucess error code otherwise

This open is called from the general open after its worked out what type of subdevice user space has requested Called if we have an open on an Axis SRAM block (note the axis device has one set of entry points and sub classes itself on device open by using the TYPE nibble from the minor number and replacing the file ops structure in the file *. Function checks that the SRAM region is accessible.

ssize_t axis_ram_read struct file *  file_ptr,
char *  buffer,
size_t  count,
loff_t *  ppos
[static]
 

Gets data from a SRAM partition and returns it to userland.

Parameters:
file_ptr - pointer to kernel file structure for open device
buffer - pointer to user applications buffer
count - number of bytes to read
ppos - index of first byte
Returns:
number read

Called by kernel in response to a user application making a read call. Note the user buffer pointer is not a valid address from inside the kernel. Reads a block of SRAM from PCI SRAM back to user space with file l ike semantics

int axis_ram_release struct inode *  inode_ptr,
struct file *  file_ptr
[static]
 

Called by kernel in response to a process closing a device.

Parameters:
inode_ptr 
file_ptr 
Returns:
0 on success

ssize_t axis_ram_write struct file *  file_ptr,
const char *  buf,
size_t  count,
loff_t *  ppos
[static]
 

Copies data from USER space and sends it to SRAM.

Parameters:
file_ptr - pointer to kernel file structure for open device
buf - user processes buffer
count - number of bytes to write
ppos - offset to start
Returns:
number written

Called by the kernel in response to a write call by a user application. Note the buffer address supplied will not be a valid kernel address

int build_sram_config struct axis_pci_device_entry device  ) 
 

Read the table defined in sram_config and convert it to a set of memory devices.

Returns:
0 on success
Parameters:
device - hardware master structure

The SRAM configuration is compiled into the axis_sram_config structure this function reads the structure and creates partitions and devices according to the elements found there.

Note at current if more than one MTD device is defined the MTD system seems to cause a kernel panic when the second MTD device is removed this happens in response to a module unload triggered by a rmmod axis command.

Here is the call graph for this function:

void create_proc_sram_directory struct axis_pci_device_entry device,
struct sram_block block
 

Here is the call graph for this function:

void create_proc_sram_entries struct axis_pci_device_entry device  ) 
 

Creates a /proc directory fills it entries that output the current SRAM configuration.

Returns:
none
Parameters:
device - Pointer to the hardware master control block
This function creates a directory entry (under Axis) in the /proc file system and then creates entries in it, one for each SRAM partition defined. Each entry will output data describing the current state of the partition

Here is the call graph for this function:

void delete_proc_sram_directory struct axis_pci_device_entry device,
struct sram_block block
 

void delete_proc_sram_entries struct axis_pci_device_entry device  ) 
 

Deletes the SRAM related entries in the /Proc filesystem.

Returns:
none
Parameters:
device - Pointer to the hardware master control block
Deletes the SRAM related entries in the /Proc filesystem

Here is the call graph for this function:

void delete_sram_config struct axis_pci_device_entry device  ) 
 

Removes any SRAM devices created.

Returns:
0 on success
Parameters:
device - hardware master structure

Called if the driver is unloaded this destroys the drivers it created.

Note at current if more than one MTD device is defined the MTD system seems to cause a kernel panic when the second MTD device is removed this happens in response to a module unload triggered by a rmmod axis command.

unsigned long index_to_read_map unsigned long  i  )  [inline, static]
 

unsigned long index_to_write_map unsigned long  i  )  [inline, static]
 

void init_access_control_entry struct access_control_entry ptr,
unsigned long  start_address,
ssize_t  length,
int  write_not_read
[static]
 

Here is the call graph for this function:

void init_mtd_block struct mtd_info *  block,
ssize_t  length,
char *  Name,
unsigned int  number
[inline, static]
 

Initialises a MTD block.

Returns:
none
Parameters:
block - Pointer to the block to initalise
length - The amount of RAM allocated to the block
Name - The Name that will appear in the MTD /proc entry
number - The MTD device number
To register with the MTD system the driver passes it a structure containing a description of the device to create. This function performs most of the initalisation needed for such a structure

Here is the call graph for this function:

void init_sram_access_control struct sram_access_control ptr,
unsigned long  start_address,
ssize_t  length
[inline, static]
 

Here is the call graph for this function:

int mtd_ram_erase struct mtd_info *  mtd,
struct erase_info *  instr
[static]
 

Function to simulate erasing flash for MTD subsystem.

Here is the call graph for this function:

int mtd_ram_point struct mtd_info *  mtd,
loff_t  from,
size_t  len,
size_t *  retlen,
u_char **  mtdbuf
[static]
 

passed to MTD system

Here is the call graph for this function:

int mtd_ram_read struct mtd_info *  mtd,
loff_t  from,
size_t  len,
size_t *  retlen,
u_char *  buffer
[static]
 

Ram read for MTD sub system.

Here is the call graph for this function:

void mtd_ram_unpoint struct mtd_info *  mtd,
u_char *  addr,
loff_t  from,
size_t  len
[static]
 

passed to MTD system

Here is the call graph for this function:

int mtd_ram_write struct mtd_info *  mtd,
loff_t  to,
size_t  len,
size_t *  retlen,
const u_char *  buffer
[static]
 

Rather than messing about with the SRAM let the Linux MTD support handle it.

Here is the call graph for this function:

int proc_read_mtd_config char *  buf,
char **  start,
off_t  offset,
int  count,
int *  eof,
void *  data
[static]
 

int proc_read_read_enable char *  buf,
char **  start,
off_t  offset,
int  count,
int *  eof,
void *  data
[static]
 

int proc_read_sram char *  buf,
char **  start,
off_t  offset,
int  count,
int *  eof,
void *  data
[static]
 

Outputs data about the current SRAM configuration.

Returns:
length of data written negative value on failure
Parameters:
buf - data is written here
start - not used
offset - not used
count - not used
eof - used to signal end of file
data - user data set to point to SRAM block related to this configuration
A callback function that gets passed to the /proc file system and which outputs data on the current SRAM configuration

int proc_read_write_enable char *  buf,
char **  start,
off_t  offset,
int  count,
int *  eof,
void *  data
[static]
 

int proc_write_read_enable struct file *  file,
const char *  buffer,
unsigned long  count,
void *  data
[static]
 

Here is the call graph for this function:

int proc_write_write_enable struct file *  file,
const char *  buffer,
unsigned long  count,
void *  data
[static]
 

Here is the call graph for this function:

int set_block_read struct sram_block block,
int  allow
[inline, static]
 

Here is the call graph for this function:

int set_block_read_write struct sram_block block,
int  read_allow,
int  write_allow
[inline, static]
 

Here is the call graph for this function:

int set_block_write struct sram_block block,
int  allow
[inline, static]
 

Here is the call graph for this function:

void update_sram_access struct sram_block block  )  [static]
 


Variable Documentation

struct file_operations ram_file_operations
 

Initial value:

{
                                          
    llseek:          axis_ram_llseek,         
    read:            axis_ram_read,           
    write:           axis_ram_write,          
                                          
                                          
    ioctl:           axis_ram_ioctl,          
    mmap:            axis_ram_mmap,                           
    open:            axis_ram_open,            
                                           
    release:         axis_ram_release,          
}
Defines a table of file operations for an Axis Ram device Users open a generic Axis device if the TYPE part of the minor number is an SRAM device we replace the generic axis file operations structure for the open file with this. (Budget virtual construction??) This way we only need to register one axis device type with the kernel but can still code devices individually


Generated on Fri Jan 28 12:35:23 2005 for Axis Kernel Driver by doxygen 1.3.6