Search
lxdream.org :: lxdream/src/mmio.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/mmio.h
changeset 10:c898b37506e0
next31:495e480360d7
author nkeynes
date Mon Dec 12 10:37:41 2005 +0000 (15 years ago)
permissions -rw-r--r--
last change Use cpu-specific is_valid_page function
view annotate diff log raw
     1 #ifndef dream_mmio_H
     2 #define dream_mmio_H 1
     4 #ifdef __cplusplus
     5 extern "C" {
     6 #if 0
     7 }
     8 #endif
     9 #endif
    11 #include <stdint.h>
    12 #include <stdlib.h>
    13 #include "sh4core.h"
    15 #define PAGE_TABLE_ENTRIES 128*1024
    16 #define PAGE_SIZE 4096
    17 #define PAGE_BITS 12
    19 #define PORT_R 1
    20 #define PORT_W 2
    21 #define PORT_MEM 4 /* store written value */
    22 #define PORT_RW 3
    23 #define PORT_MR 5
    24 #define PORT_MRW 7
    25 #define UNDEFINED 0xDEADBEEF /* This has to be a value that nothing inits to */
    27 struct mmio_region {
    28     char *id, *desc;
    29     uint32_t base;
    30     int32_t (*io_read)(uint32_t addr);
    31     void (*io_write)(uint32_t addr, uint32_t val);
    32     char *mem;
    33     char *save_mem; /* Used to compare for gui updates */
    34     struct mmio_port {
    35         char *id, *desc;
    36         int width;
    37         uint32_t offset;
    38         uint32_t def_val;
    39         int flags;
    40         uint32_t *val;
    41     } ports[80];
    42     struct mmio_port **index; /* reverse lookup by address */
    43     int trace_flag; /* set to 1 to enable transfer traces */
    44 };
    46 void register_io_region( struct mmio_region *mmio );
    47 void register_io_regions( struct mmio_region **mmiolist );
    49 extern struct mmio_region *io_rgn[];
    50 extern int num_io_rgns;
    52 #define MMIO_READ( id, r ) *((int32_t *)(mmio_region_##id.mem + (r)))
    53 #define MMIO_WRITE( id, r, v ) *((int32_t *)(mmio_region_##id.mem + (r))) = (v)
    54 #define MMIO_REG( id, r ) ((int32_t *)(mmio_region_##id.mem + (r)))
    55 #define MMIO_REGID( mid, r ) (mmio_region_##mid.index[(r)>>2] != NULL ? \
    56             mmio_region_##mid.index[(r)>>2]->id : "<UNDEF>" )
    57 #define MMIO_REGDESC( mid, r) (mmio_region_##mid.index[(r)>>2] != NULL ? \
    58             mmio_region_##mid.index[(r)>>2]->desc : "Undefined register" )
    59 #define MMIO_TRACE( mid ) mmio_region_##mid.trace_flag = 1
    60 #define MMIO_NOTRACE( mid ) mmio_region_##mid.trace_flag = 0
    62 #define MMIO_REGID_BYNUM( mid, r ) (io_rgn[mid]->index[(r)>>2] != NULL ? \
    63             io_rgn[mid]->index[(r)>>2]->id : "<UNDEF>" )
    64 #define MMIO_REGDESC_BYNUM( mid, r ) (io_rgn[mid]->index[(r)>>2] != NULL ? \
    65             io_rgn[mid]->index[(r)>>2]->desc : "Undefined register" )
    66 #define MMIO_NAME_BYNUM( mid ) (io_rgn[mid]->id)
    68 #ifdef __cplusplus
    69 }
    70 #endif
    72 #endif
    74 #ifdef MMIO_IMPL
    76 #ifndef MMIO_IMPL_INCLUDED
    77 #define MMIO_IMPL_INCLUDED
    78 #undef MMIO_REGION_BEGIN
    79 #undef LONG_PORT
    80 #undef WORD_PORT
    81 #undef BYTE_PORT
    82 #undef MMIO_REGION_END
    83 #undef MMIO_REGION_LIST_BEGIN
    84 #undef MMIO_REGION
    85 #undef MMIO_REGION_LIST_END
    86 #define MMIO_REGION_BEGIN(b,id,d) struct mmio_region mmio_region_##id = { #id, d, b, mmio_region_##id##_read, mmio_region_##id##_write, 0, 0, {
    87 #define LONG_PORT( o,id,f,def,d ) { #id, d, 32, o, def, f },
    88 #define WORD_PORT( o,id,f,def,d ) { #id, d, 16, o, def, f },
    89 #define BYTE_PORT( o,id,f,def,d ) { #id, d, 8, o, def, f },
    90 #define MMIO_REGION_END {NULL, NULL, 0, 0, 0, 0} } };
    91 #define MMIO_REGION_LIST_BEGIN(id) struct mmio_region *mmio_list_##id[] = {
    92 #define MMIO_REGION( id ) &mmio_region_##id,
    93 #define MMIO_REGION_LIST_END NULL};
    95 /* Stub defines for modules we haven't got to yet, or ones which don't
    96  * actually need any direct code on read and/or write
    97  */
    98 #define MMIO_REGION_READ_STUBFN( id ) \
    99 int32_t mmio_region_##id##_read( uint32_t reg ) { \
   100     int32_t val = MMIO_READ( id, reg ); \
   101     WARN( "Read from unimplemented module %s (%03X => %08X) [%s: %s]",\
   102           #id, reg, val, MMIO_REGID(id,reg), MMIO_REGDESC(id,reg) ); \
   103     return val; \
   104 }
   105 #define MMIO_REGION_WRITE_STUBFN( id ) \
   106 void mmio_region_##id##_write( uint32_t reg, uint32_t val ) { \
   107     WARN( "Write to unimplemented module %s (%03X <= %08X) [%s: %s]", \
   108           #id, reg, val, MMIO_REGID(id,reg), MMIO_REGDESC(id,reg) ); \
   109     MMIO_WRITE( id, reg, val ); \
   110 }
   111 #define MMIO_REGION_STUBFNS( id ) \
   112     MMIO_REGION_READ_STUBFN( id ) \
   113     MMIO_REGION_WRITE_STUBFN( id )
   114 #define MMIO_REGION_READ_DEFFN( id ) \
   115 int32_t mmio_region_##id##_read( uint32_t reg ) { \
   116     return MMIO_READ( id, reg ); \
   117 }
   118 #define MMIO_REGION_WRITE_DEFFN( id ) \
   119 void mmio_region_##id##_write( uint32_t reg, uint32_t val ) { \
   120     MMIO_WRITE( id, reg, val ); \
   121 }
   122 #define MMIO_REGION_DEFFNS( id ) \
   123     MMIO_REGION_READ_DEFFN( id ) \
   124     MMIO_REGION_WRITE_DEFFN( id )
   125 #endif
   127 #define MMIO_REGION_WRITE_FN( id, reg, val ) \
   128 void mmio_region_##id##_write( uint32_t reg, uint32_t val )
   130 #define MMIO_REGION_READ_FN( id, reg ) \
   131 int32_t mmio_region_##id##_read( uint32_t reg )
   133 #else
   135 #ifndef MMIO_IFACE_INCLUDED
   136 #define MMIO_IFACE_INCLUDED
   137 #define MMIO_REGION_BEGIN(b,id,d) \
   138 extern struct mmio_region mmio_region_##id; \
   139 int32_t mmio_region_##id##_read(uint32_t); \
   140 void mmio_region_##id##_write(uint32_t, uint32_t); \
   141 enum mmio_region_##id##_port_t {
   142 #define LONG_PORT( o,id,f,def,d ) id = o,
   143 #define WORD_PORT( o,id,f,def,d ) id = o,
   144 #define BYTE_PORT( o,id,f,def,d ) id = o,
   145 #define MMIO_REGION_END };
   146 #define MMIO_REGION_LIST_BEGIN(id) extern struct mmio_region *mmio_list_##id[];
   147 #define MMIO_REGION( id )
   148 #define MMIO_REGION_LIST_END
   149 #endif
   151 #endif
.