\hypertarget{memmap_8c}{
\section{memmap.c File Reference}
\label{memmap_8c}\index{memmap.c@{memmap.c}}
}
Memory Map functions.  


{\tt \#include $<$string.h$>$}\par
{\tt \#include \char`\"{}MEM/MEM\_\-cmddefs.h\char`\"{}}\par
{\tt \#include \char`\"{}MEM/MEM\_\-map.h\char`\"{}}\par
{\tt \#include \char`\"{}MEM/MEM\_\-msgs.h\char`\"{}}\par
{\tt \#include \char`\"{}MSG/MSG\_\-pubdefs.h\char`\"{}}\par
{\tt \#include \char`\"{}mempriv.h\char`\"{}}\par


Include dependency graph for memmap.c:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=258pt]{memmap_8c__incl}
\end{center}
\end{figure}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\hypertarget{memmap_8c_a0}{
\#define \hyperlink{memmap_8c_a0}{DIM}(a)\ (sizeof (a) / sizeof ((a)\mbox{[}0\mbox{]}))}
\label{memmap_8c_a0}

\begin{CompactList}\small\item\em Dimension of an array. \item\end{CompactList}\item 
\hypertarget{memmap_8c_a1}{
\#define \hyperlink{memmap_8c_a1}{mem\_\-NUM\_\-MEM\_\-MAP\_\-TABLE\_\-ENTRIES}\ (64)}
\label{memmap_8c_a1}

\begin{CompactList}\small\item\em Maximum number of mem\_\-map\-Memory\-Table entries. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void $\ast$ \hyperlink{memmap_8c_a7}{MEM\_\-map\-RWGeneric} (void $\ast$dest\_\-p, const void $\ast$source\_\-p, const size\_\-t nbytes, void $\ast$context\_\-p, size\_\-t $\ast$bytes\_\-moved\_\-p)
\begin{CompactList}\small\item\em Generic memory access callback. \item\end{CompactList}\item 
void $\ast$ \hyperlink{memmap_8c_a8}{MEM\_\-map\-Read32Swap} (void $\ast$dest\_\-p, const void $\ast$source\_\-p, const size\_\-t nbytes, void $\ast$context\_\-p, size\_\-t $\ast$bytes\_\-read\_\-p)
\begin{CompactList}\small\item\em Byte-swapped 32-bit memory read callback. \item\end{CompactList}\item 
void $\ast$ \hyperlink{memmap_8c_a9}{MEM\_\-map\-Write32Swap} (void $\ast$dest\_\-p, const void $\ast$source\_\-p, const size\_\-t nbytes, void $\ast$context\_\-p, size\_\-t $\ast$bytes\_\-written\_\-p)
\begin{CompactList}\small\item\em Byte-swapped 32-bit memory write callback. \item\end{CompactList}\item 
void $\ast$ \hyperlink{memmap_8c_a10}{MEM\_\-map\-Read\-Buffer} (void $\ast$dest\_\-p, const void $\ast$offset, const size\_\-t nbytes, void $\ast$buf\_\-p, size\_\-t $\ast$bytes\_\-read\_\-p)
\begin{CompactList}\small\item\em Buffer read access. \item\end{CompactList}\item 
void $\ast$ \hyperlink{memmap_8c_a11}{MEM\_\-map\-Write\-Buffer} (void $\ast$offset, const void $\ast$src\_\-p, const size\_\-t nbytes, void $\ast$buf\_\-p, size\_\-t $\ast$bytes\_\-written\_\-p)
\begin{CompactList}\small\item\em Buffer write access. \item\end{CompactList}\item 
unsigned int \hyperlink{memmap_8c_a12}{Mem\_\-Validate\-Memory\-Range} (const \hyperlink{struct__MEM__Descriptor}{MEM\_\-Descriptor} $\ast$md, const \hyperlink{MEM__map_8h_a12}{MEM\_\-map\-Access\-Type} access\-Type, const \hyperlink{struct__mem__mapEntry}{mem\_\-map\-Entry} $\ast$$\ast$map\-Entry)
\begin{CompactList}\small\item\em Validate memory descriptor against memory map table. \item\end{CompactList}\item 
unsigned int \hyperlink{memmap_8c_a13}{MEM\_\-map\-Init} (void)
\begin{CompactList}\small\item\em Start the Memory Map system. \item\end{CompactList}\item 
unsigned int \hyperlink{memmap_8c_a14}{MEM\_\-map\-Add\-Entry} (const caddr\_\-t start\_\-addr, const size\_\-t num\_\-bytes, const \hyperlink{MEM__map_8h_a12}{MEM\_\-map\-Access\-Type} access\_\-flags, \hyperlink{MEM__map_8h_a13}{MEM\_\-map\-Access\-Cb} $\ast$read\_\-cb, \hyperlink{MEM__map_8h_a13}{MEM\_\-map\-Access\-Cb} $\ast$write\_\-cb, void $\ast$context\_\-p)
\begin{CompactList}\small\item\em Add an entry to the memory map table. \item\end{CompactList}\item 
unsigned int \hyperlink{memmap_8c_a15}{MEM\_\-map\-Add\-Ppci\-Entries} (void)
\begin{CompactList}\small\item\em Add memory map table entries for the PPCI bridge chip. \item\end{CompactList}\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
\hyperlink{struct__mem__mapEntry}{mem\_\-map\-Entry} \hyperlink{memmap_8c_a2}{mem\_\-map\-Memory\-Table} \mbox{[}mem\_\-NUM\_\-MEM\_\-MAP\_\-TABLE\_\-ENTRIES\mbox{]}
\begin{CompactList}\small\item\em Memory map table for 'memory' accesses. \item\end{CompactList}\item 
\hypertarget{memmap_8c_a3}{
unsigned char \hyperlink{memmap_8c_a3}{mem\_\-map\-Fake\-Regs} \mbox{[}MEM\_\-REGISTER\_\-SET\_\-BYTES\mbox{]}}
\label{memmap_8c_a3}

\begin{CompactList}\small\item\em Buffer for simulating CPU register accesses. \item\end{CompactList}\item 
unsigned char \hyperlink{memmap_8c_a4}{mem\_\-map\-Fake\-Pci} \mbox{[}65536\mbox{]}
\begin{CompactList}\small\item\em Buffer for simulating PCI device header accesses. \item\end{CompactList}\item 
\hyperlink{struct__mem__mapEntry}{mem\_\-map\-Entry} \hyperlink{memmap_8c_a5}{mem\_\-map\-Register\-Table} \mbox{[}$\,$\mbox{]}
\begin{CompactList}\small\item\em Memory map table for 'register' accesses. \item\end{CompactList}\item 
\hyperlink{struct__mem__mapEntry}{mem\_\-map\-Entry} \hyperlink{memmap_8c_a6}{mem\_\-map\-Pci\-Config\-Table} \mbox{[}$\,$\mbox{]}
\begin{CompactList}\small\item\em Memory map table for 'PCI Configuration' accesses. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Memory Map functions. 

These functions manipulate memory maps.



\footnotesize\begin{verbatim}
  CVS $Id: memmap.c,v 1.16 2004/12/08 17:42:22 dmay Exp $
  \end{verbatim}\normalsize


\subsection{Function Documentation}
\hypertarget{memmap_8c_a14}{
\index{memmap.c@{memmap.c}!MEM_mapAddEntry@{MEM\_\-mapAddEntry}}
\index{MEM_mapAddEntry@{MEM\_\-mapAddEntry}!memmap.c@{memmap.c}}
\subsubsection[MEM\_\-mapAddEntry]{\setlength{\rightskip}{0pt plus 5cm}unsigned int MEM\_\-map\-Add\-Entry (const caddr\_\-t {\em start\_\-addr}, const size\_\-t {\em num\_\-bytes}, const \hyperlink{MEM__map_8h_a12}{MEM\_\-map\-Access\-Type} {\em access\_\-flags}, \hyperlink{MEM__map_8h_a13}{MEM\_\-map\-Access\-Cb} $\ast$ {\em read\_\-cb}, \hyperlink{MEM__map_8h_a13}{MEM\_\-map\-Access\-Cb} $\ast$ {\em write\_\-cb}, void $\ast$ {\em context\_\-p})}}
\label{memmap_8c_a14}


Add an entry to the memory map table. 

Add an entry to the memory map table, which defines all the valid locations within the memory address space. Each table entry defines a contiguous region of the memory address space, including the types of accesses allowed to the region and pointers to callback functions that can be used to read and write the region.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em start\_\-addr}]Start address of region. \item[{\em num\_\-bytes}]Size of region, in bytes. \item[{\em access\_\-flags}]Bitmap of allowed accesses to the region. \item[{\em read\_\-cb}]Pointer to callback function for reading from region. \item[{\em write\_\-cb}]Pointer to callback function for writing to region. \item[{\em context\_\-p}]Generic pointer passed to callback functions.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]A MEM MSG code. \end{Desc}
\hypertarget{memmap_8c_a15}{
\index{memmap.c@{memmap.c}!MEM_mapAddPpciEntries@{MEM\_\-mapAddPpciEntries}}
\index{MEM_mapAddPpciEntries@{MEM\_\-mapAddPpciEntries}!memmap.c@{memmap.c}}
\subsubsection[MEM\_\-mapAddPpciEntries]{\setlength{\rightskip}{0pt plus 5cm}unsigned int MEM\_\-map\-Add\-Ppci\-Entries (void)}}
\label{memmap_8c_a15}


Add memory map table entries for the PPCI bridge chip. 

Add memory map table entries for the registers within the power\-PCI bridge chip on the RAD750 board.

\begin{Desc}
\item[Returns:]A MEM MSG code. \end{Desc}


Here is the call graph for this function:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=185pt]{memmap_8c_a15_cgraph}
\end{center}
\end{figure}
\hypertarget{memmap_8c_a13}{
\index{memmap.c@{memmap.c}!MEM_mapInit@{MEM\_\-mapInit}}
\index{MEM_mapInit@{MEM\_\-mapInit}!memmap.c@{memmap.c}}
\subsubsection[MEM\_\-mapInit]{\setlength{\rightskip}{0pt plus 5cm}unsigned int MEM\_\-map\-Init (void)}}
\label{memmap_8c_a13}


Start the Memory Map system. 

Start the Memory Map system. This function should be called once to initialize the internal state associated with the Memory Map functions.

\begin{Desc}
\item[Returns:]A MEM MSG code. \end{Desc}
\hypertarget{memmap_8c_a8}{
\index{memmap.c@{memmap.c}!MEM_mapRead32Swap@{MEM\_\-mapRead32Swap}}
\index{MEM_mapRead32Swap@{MEM\_\-mapRead32Swap}!memmap.c@{memmap.c}}
\subsubsection[MEM\_\-mapRead32Swap]{\setlength{\rightskip}{0pt plus 5cm}void $\ast$ MEM\_\-map\-Read32Swap (void $\ast$ {\em dest\_\-p}, const void $\ast$ {\em source\_\-p}, const size\_\-t {\em nbytes}, void $\ast$ {\em context\_\-p}, size\_\-t $\ast$ {\em bytes\_\-read\_\-p})}}
\label{memmap_8c_a8}


Byte-swapped 32-bit memory read callback. 

This is a callback function for reading 32-bit words that require byte swapping. Accesses must be a multiple of 32-bits and aligned on a 32-bit boundary.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dest\_\-p}]Pointer to destination of the read. \item[{\em source\_\-p}]Pointer to source of the read. \item[{\em nbytes}]Number of bytes to read. \item[{\em context\_\-p}]Pointer to generic context (unused). \item[{\em bytes\_\-read\_\-p}]Pointer to location to return number of bytes read.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]dest\_\-p if no error occurred, NULL if an error occurred. \end{Desc}
\hypertarget{memmap_8c_a10}{
\index{memmap.c@{memmap.c}!MEM_mapReadBuffer@{MEM\_\-mapReadBuffer}}
\index{MEM_mapReadBuffer@{MEM\_\-mapReadBuffer}!memmap.c@{memmap.c}}
\subsubsection[MEM\_\-mapReadBuffer]{\setlength{\rightskip}{0pt plus 5cm}void $\ast$ MEM\_\-map\-Read\-Buffer (void $\ast$ {\em dest\_\-p}, const void $\ast$ {\em offset}, const size\_\-t {\em nbytes}, void $\ast$ {\em buf\_\-p}, size\_\-t $\ast$ {\em bytes\_\-read\_\-p})}}
\label{memmap_8c_a10}


Buffer read access. 

This is a callback function for reading values from a buffer. This would be used, for example, to read a snapshot of the CPU register values or the PCI configuration space values which have been captured in a buffer. A pointer to the beginning of this snapshot buffer must be provided as the {\em buf\_\-p\/} parameter.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dest\_\-p}]Pointer to destination of the buffer read. \item[{\em offset}]Offset from {\em buf\_\-p\/} to begin reading. \item[{\em nbytes}]Number of bytes to read. \item[{\em buf\_\-p}]Pointer to start of buffer. \item[{\em bytes\_\-read\_\-p}]Pointer to location to return number of bytes read.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]dest\_\-p if no error occurred, NULL if an error occurred. \end{Desc}
\hypertarget{memmap_8c_a7}{
\index{memmap.c@{memmap.c}!MEM_mapRWGeneric@{MEM\_\-mapRWGeneric}}
\index{MEM_mapRWGeneric@{MEM\_\-mapRWGeneric}!memmap.c@{memmap.c}}
\subsubsection[MEM\_\-mapRWGeneric]{\setlength{\rightskip}{0pt plus 5cm}void $\ast$ MEM\_\-map\-RWGeneric (void $\ast$ {\em dest\_\-p}, const void $\ast$ {\em source\_\-p}, const size\_\-t {\em nbytes}, void $\ast$ {\em context\_\-p}, size\_\-t $\ast$ {\em bytes\_\-moved\_\-p})}}
\label{memmap_8c_a7}


Generic memory access callback. 

This is a callback function for reading and writing generic memory. It is suitable for RAM or other memory that has no alignment or access restrictions.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dest\_\-p}]Pointer to destination of the memory read or write. \item[{\em source\_\-p}]Pointer to source of the memory read or write. \item[{\em nbytes}]Number of bytes to read or write. \item[{\em context\_\-p}]Pointer to generic context (unused). \item[{\em bytes\_\-moved\_\-p}]Pointer to location to return number of bytes moved.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]dest\_\-p if no error occurred, NULL if an error occurred. \end{Desc}
\hypertarget{memmap_8c_a9}{
\index{memmap.c@{memmap.c}!MEM_mapWrite32Swap@{MEM\_\-mapWrite32Swap}}
\index{MEM_mapWrite32Swap@{MEM\_\-mapWrite32Swap}!memmap.c@{memmap.c}}
\subsubsection[MEM\_\-mapWrite32Swap]{\setlength{\rightskip}{0pt plus 5cm}void $\ast$ MEM\_\-map\-Write32Swap (void $\ast$ {\em dest\_\-p}, const void $\ast$ {\em source\_\-p}, const size\_\-t {\em nbytes}, void $\ast$ {\em context\_\-p}, size\_\-t $\ast$ {\em bytes\_\-written\_\-p})}}
\label{memmap_8c_a9}


Byte-swapped 32-bit memory write callback. 

This is a callback function for writing 32-bit words that require byte swapping. Accesses must be a multiple of 32-bits and aligned on a 32-bit boundary.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dest\_\-p}]Pointer to destination of the write. \item[{\em source\_\-p}]Pointer to source of the write. \item[{\em nbytes}]Number of bytes to write. \item[{\em context\_\-p}]Pointer to generic context (unused). \item[{\em bytes\_\-written\_\-p}]Pointer to location to return num bytes written.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]dest\_\-p if no error occurred, NULL if an error occurred. \end{Desc}
\hypertarget{memmap_8c_a11}{
\index{memmap.c@{memmap.c}!MEM_mapWriteBuffer@{MEM\_\-mapWriteBuffer}}
\index{MEM_mapWriteBuffer@{MEM\_\-mapWriteBuffer}!memmap.c@{memmap.c}}
\subsubsection[MEM\_\-mapWriteBuffer]{\setlength{\rightskip}{0pt plus 5cm}void $\ast$ MEM\_\-map\-Write\-Buffer (void $\ast$ {\em offset}, const void $\ast$ {\em src\_\-p}, const size\_\-t {\em nbytes}, void $\ast$ {\em buf\_\-p}, size\_\-t $\ast$ {\em bytes\_\-written\_\-p})}}
\label{memmap_8c_a11}


Buffer write access. 

This is a callback function for writing values to a buffer. A pointer to the beginning of the buffer must be provided as the {\em buf\_\-p\/} parameter.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em offset}]Offset from {\em buf\_\-p\/} to begin writing. \item[{\em src\_\-p}]Pointer to source of the buffer write. \item[{\em nbytes}]Number of bytes to write. \item[{\em buf\_\-p}]Pointer to start of buffer. \item[{\em bytes\_\-written\_\-p}]Pointer to location to return num bytes written.\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]offset if no error occurred, NULL if an error occurred. \end{Desc}
\hypertarget{memmap_8c_a12}{
\index{memmap.c@{memmap.c}!Mem_ValidateMemoryRange@{Mem\_\-ValidateMemoryRange}}
\index{Mem_ValidateMemoryRange@{Mem\_\-ValidateMemoryRange}!memmap.c@{memmap.c}}
\subsubsection[Mem\_\-ValidateMemoryRange]{\setlength{\rightskip}{0pt plus 5cm}unsigned int Mem\_\-Validate\-Memory\-Range (const \hyperlink{struct__MEM__Descriptor}{MEM\_\-Descriptor} $\ast$ {\em md}, const \hyperlink{MEM__map_8h_a12}{MEM\_\-map\-Access\-Type} {\em access\-Type}, const \hyperlink{struct__mem__mapEntry}{mem\_\-map\-Entry} $\ast$$\ast$ {\em map\-Entry})}}
\label{memmap_8c_a12}


Validate memory descriptor against memory map table. 

This function verifies that a memory descriptor is valid for a given set of access types. Potential access types are specified in {\em access\-Type\/} as a bitfield. If at least one of the access types specified is legal for the memory descriptor, a handle to the appropriate memory map entry is passed back for future use. If, instead, the caller wants to know if $\ast$all$\ast$ specified access types are valid, then this function must be called once for each type.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em md}]Pointer to memory descriptor to be validated. \item[{\em access\-Type}]Bitfield of types of accesses to validate. \item[{\em map\-Entry}]Pointer to location to return map table entry handle.\end{description}
\end{Desc}
\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em MEM\_\-SUCCESS}]md is OK for access\-Type. \item[{\em MEM\_\-OUTOFRNG}]md does not fit in any memory map. \item[{\em MEM\_\-BADMAP}]md does not contain a legal memory map type. \item[{\em MEM\_\-BADACC}]access\-Type is not legal for md. \end{description}
\end{Desc}


\subsection{Variable Documentation}
\hypertarget{memmap_8c_a4}{
\index{memmap.c@{memmap.c}!mem_mapFakePci@{mem\_\-mapFakePci}}
\index{mem_mapFakePci@{mem\_\-mapFakePci}!memmap.c@{memmap.c}}
\subsubsection[mem\_\-mapFakePci]{\setlength{\rightskip}{0pt plus 5cm}\hyperlink{memmap_8c_a4}{mem\_\-map\-Fake\-Pci}\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{memmap_8c_a4}


{\bf Initial value:}

\footnotesize\begin{verbatim}
    {
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
    }
\end{verbatim}\normalsize 
Buffer for simulating PCI device header accesses. 

\hypertarget{memmap_8c_a2}{
\index{memmap.c@{memmap.c}!mem_mapMemoryTable@{mem\_\-mapMemoryTable}}
\index{mem_mapMemoryTable@{mem\_\-mapMemoryTable}!memmap.c@{memmap.c}}
\subsubsection[mem\_\-mapMemoryTable]{\setlength{\rightskip}{0pt plus 5cm}\hyperlink{memmap_8c_a2}{mem\_\-map\-Memory\-Table}\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{memmap_8c_a2}


Memory map table for 'memory' accesses. 

Describes the memory map for MEM\_\-MEMMAP\_\-MEMORY loads and dumps. \hypertarget{memmap_8c_a6}{
\index{memmap.c@{memmap.c}!mem_mapPciConfigTable@{mem\_\-mapPciConfigTable}}
\index{mem_mapPciConfigTable@{mem\_\-mapPciConfigTable}!memmap.c@{memmap.c}}
\subsubsection[mem\_\-mapPciConfigTable]{\setlength{\rightskip}{0pt plus 5cm}\hyperlink{memmap_8c_a6}{mem\_\-map\-Pci\-Config\-Table}\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{memmap_8c_a6}


{\bf Initial value:}

\footnotesize\begin{verbatim} 
    {
        { 1,                        
          (void *)0x0,              
          0x10000,                  
          MEM_MAP_ACCESS_ANY,       









          MEM_mapReadBuffer,        
          MEM_mapWriteBuffer,       
          mem_mapFakePci            



        },
    }
\end{verbatim}\normalsize 
Memory map table for 'PCI Configuration' accesses. 

Describes the memory map for MEM\_\-MEMMAP\_\-PCI\_\-CFG loads and dumps. The PCI configuration space is a 256-byte address space for each device on the PCI bus. \hypertarget{memmap_8c_a5}{
\index{memmap.c@{memmap.c}!mem_mapRegisterTable@{mem\_\-mapRegisterTable}}
\index{mem_mapRegisterTable@{mem\_\-mapRegisterTable}!memmap.c@{memmap.c}}
\subsubsection[mem\_\-mapRegisterTable]{\setlength{\rightskip}{0pt plus 5cm}\hyperlink{memmap_8c_a5}{mem\_\-map\-Register\-Table}\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{memmap_8c_a5}


{\bf Initial value:}

\footnotesize\begin{verbatim} 
    {
        { 1,                        
          (void *)0x0,              
          MEM_REGISTER_SET_BYTES,   
          MEM_MAP_ACCESS_ANY,       









          MEM_mapReadBuffer,        
          MEM_mapWriteBuffer,       
          mem_mapFakeRegs           



        },
    }
\end{verbatim}\normalsize 
Memory map table for 'register' accesses. 

Describes the memory map for MEM\_\-MEMMAP\_\-REGISTER loads and dumps. 