OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [peripheral/] [mc.c] - Blame information for rev 997

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 239 markom
/* mc.c -- Simulation of Memory Controller
2
         Copyright (C) 2001 by Marko Mlinar, markom@opencores.org
3
 
4
         This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
         This program is free software; you can redistribute it and/or modify
7
         it under the terms of the GNU General Public License as published by
8
         the Free Software Foundation; either version 2 of the License, or
9
         (at your option) any later version.
10
 
11
         This program is distributed in the hope that it will be useful,
12
         but WITHOUT ANY WARRANTY; without even the implied warranty of
13
         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
14
         GNU General Public License for more details.
15
 
16
         You should have received a copy of the GNU General Public License
17
         along with this program; if not, write to the Free Software
18
         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
*/
20
 
21
/* Enable memory controller, via:
22
  section mc
23
    enable = 1
24
    POC = 0x13243545
25
  end
26
 
27 261 markom
   Limitations:
28
    - memory refresh is not simulated
29 742 ivang
*/
30 239 markom
 
31
#include "mc.h"
32
#include "abstract.h"
33 261 markom
#include "sim-config.h"
34
 
35 539 simons
extern struct dev_memarea *dev_list;
36
 
37 261 markom
static struct mc mc;
38
 
39 539 simons
void set_csc_tms (int cs, unsigned long csc, unsigned long tms) {
40
  struct dev_memarea *mem_dev = dev_list;
41
 
42
  while (mem_dev) {
43
    if (mem_dev->chip_select == cs) {
44 970 simons
      mem_dev->addr_mask = mc.ba_mask << 22;
45
      mem_dev->addr_compare = ((csc >> MC_CSC_SEL_OFFSET) /* & 0xff*/) << 22;
46 543 simons
      mem_dev->valid = (csc >> MC_CSC_EN_OFFSET) & 0x01;
47 539 simons
 
48
      if ((csc >> MC_CSC_MEMTYPE_OFFSET) && 0x07 == MC_CSC_MEMTYPE_ASYNC) {
49
        mem_dev->delayr = (tms & 0xff) + ((tms >> 8) & 0x0f);
50
        mem_dev->delayw = ((tms >> 12)  & 0x0f) + ((tms >> 16) & 0x0f) + ((tms >> 20) & 0x3f);
51
      } else if ((csc >> MC_CSC_MEMTYPE_OFFSET) && 0x07 == MC_CSC_MEMTYPE_SDRAM) {
52
        mem_dev->delayr = 3 + ((tms >> 4) & 0x03);
53
        mem_dev->delayw = 3 + ((tms >> 4) & 0x03);
54
      } else if ((csc >> MC_CSC_MEMTYPE_OFFSET) && 0x07 == MC_CSC_MEMTYPE_SSRAM) {
55
        mem_dev->delayr = 2;
56
        mem_dev->delayw = 2;
57
      } else if ((csc >> MC_CSC_MEMTYPE_OFFSET) && 0x07 == MC_CSC_MEMTYPE_SYNC) {
58
        mem_dev->delayr = 2;
59
        mem_dev->delayw = 2;
60
      }
61 543 simons
      return;
62 539 simons
    }
63
    mem_dev = mem_dev->next;
64
  }
65 261 markom
}
66
 
67
/* Set a specific MC register with value. */
68
void mc_write_word(unsigned long addr, unsigned long value)
69
{
70
        int chipsel;
71
 
72 344 markom
        debug(5, "mc_write_word(%x,%08x)\n", addr, (unsigned)value);
73 261 markom
 
74
  addr -= config.mc.baseaddr;
75
 
76
        switch (addr) {
77
          case MC_CSR:
78
            mc.csr = value;
79
            break;
80
          case MC_POC:
81
            fprintf (stderr, "warning: write to MC's POC register!");
82
            break;
83
          case MC_BA_MASK:
84 539 simons
            mc.ba_mask = value & MC_BA_MASK_VALID;
85 543 simons
      for (chipsel = 0; chipsel < N_CE; chipsel++)
86
        set_csc_tms (chipsel, mc.csc[chipsel], mc.tms[chipsel]);
87 261 markom
            break;
88
                default:
89
                  if (addr >= MC_CSC(0) && addr <= MC_TMS(N_CE - 1)) {
90
                    addr -= MC_CSC(0);
91
                    if ((addr >> 2) & 1)
92
                      mc.tms[addr >> 3] = value;
93
                    else
94
                      mc.csc[addr >> 3] = value;
95
 
96
                    set_csc_tms (addr >> 3, mc.csc[addr >> 3], mc.tms[addr >> 3]);
97
                    break;
98
                  } else
99 344 markom
                        debug(1, "write out of range (addr %x)\n", addr + config.mc.baseaddr);
100 261 markom
        }
101
}
102
 
103
/* Read a specific MC register. */
104
unsigned long mc_read_word(unsigned long addr)
105
{
106 545 ivang
        unsigned long value = 0;
107 261 markom
        int chipsel;
108
 
109 545 ivang
        debug(5, "mc_read_word(%x)", addr);
110 261 markom
 
111
  addr -= config.mc.baseaddr;
112
 
113
        switch (addr) {
114
          case MC_CSR:
115
            value = mc.csr;
116
            break;
117
          case MC_POC:
118
            value = mc.poc;
119
            break;
120
          case MC_BA_MASK:
121
            value = mc.ba_mask;
122
            break;
123
                default:
124
                  if (addr >= MC_CSC(0) && addr <= MC_TMS(N_CE - 1)) {
125
                    addr -= MC_CSC(0);
126
                    if ((addr >> 2) & 1)
127
                      value = mc.tms[addr >> 3];
128
                    else
129
                      value = mc.csc[addr >> 3];
130
                  } else
131 545 ivang
                        debug(1, " read out of range (addr %x)\n", addr + config.mc.baseaddr);
132 261 markom
            break;
133
        }
134 545 ivang
        debug(5, " value(%x)\n", value);
135 261 markom
        return value;
136
}
137
 
138
/* Read POC register and init memory controler regs. */
139
void mc_reset()
140
{
141 543 simons
  struct dev_memarea *mem_dev = dev_list;
142
 
143 261 markom
  if (config.mc.enabled) {
144 997 markom
        PRINTF("Resetting memory controller.\n");
145 261 markom
        memset(&mc, 0, sizeof(struct mc));
146
 
147
    mc.poc = config.mc.POC;
148 539 simons
 
149
    /* Set CS0 */
150
    mc.csc[0] = (((config.mc.POC & 0x0c) >> 2) << MC_CSC_MEMTYPE_OFFSET) | ((config.mc.POC & 0x03) << MC_CSC_BW_OFFSET) | 1;
151
 
152
    if ((mc.csc[0] >> MC_CSC_MEMTYPE_OFFSET) && 0x07 == MC_CSC_MEMTYPE_ASYNC) {
153
      mc.tms[0] = MC_TMS_ASYNC_VALID;
154
    } else if ((mc.csc[0] >> MC_CSC_MEMTYPE_OFFSET) && 0x07 == MC_CSC_MEMTYPE_SDRAM) {
155
      mc.tms[0] = MC_TMS_SDRAM_VALID;
156
    } else if ((mc.csc[0] >> MC_CSC_MEMTYPE_OFFSET) && 0x07 == MC_CSC_MEMTYPE_SSRAM) {
157
      mc.tms[0] = MC_TMS_SSRAM_VALID;
158
    } else if ((mc.csc[0] >> MC_CSC_MEMTYPE_OFFSET) && 0x07 == MC_CSC_MEMTYPE_SYNC) {
159
      mc.tms[0] = MC_TMS_SYNC_VALID;
160
    }
161
 
162 543 simons
    while (mem_dev) {
163
      mem_dev->valid = 0;
164
      mem_dev = mem_dev->next;
165
    }
166
 
167 539 simons
    set_csc_tms (0, mc.csc[0], mc.tms[0]);
168
 
169 970 simons
        register_memoryarea(config.mc.baseaddr, MC_ADDR_SPACE, 4, 1, mc_read_word, mc_write_word);
170 261 markom
  }
171
}
172
 
173
inline void mc_clock()
174
{
175
}
176 742 ivang
 
177
void mc_status()
178
{
179
    int i;
180
 
181 997 markom
    PRINTF( "\nMemory Controller at 0x%08X:\n", config.mc.baseaddr );
182
    PRINTF( "POC: 0x%08X\n", mc.poc );
183
    PRINTF( "BAS: 0x%08X\n", mc.ba_mask );
184
    PRINTF( "CSR: 0x%08X\n", mc.csr );
185 742 ivang
 
186
    for (i=0; i<N_CE; i++) {
187 997 markom
        PRINTF( "CE %02d -  CSC: 0x%08X  TMS: 0x%08X\n", i, mc.csc[i], mc.tms[i]);
188 742 ivang
    }
189
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.