DRAMCtrl.py revision 9728
16145Snate@binkert.org# Copyright (c) 2012-2013 ARM Limited
26145Snate@binkert.org# All rights reserved.
36145Snate@binkert.org#
46145Snate@binkert.org# The license below extends only to copyright in the software and shall
56145Snate@binkert.org# not be construed as granting a license to any other intellectual
66145Snate@binkert.org# property including but not limited to intellectual property relating
76145Snate@binkert.org# to a hardware implementation of the functionality of the software
86145Snate@binkert.org# licensed hereunder.  You may use the software subject to the license
96145Snate@binkert.org# terms below provided that you ensure that this notice is replicated
106145Snate@binkert.org# unmodified and in its entirety in all distributions of the software,
116145Snate@binkert.org# modified or unmodified, in source code or in binary form.
126145Snate@binkert.org#
136145Snate@binkert.org# Redistribution and use in source and binary forms, with or without
146145Snate@binkert.org# modification, are permitted provided that the following conditions are
156145Snate@binkert.org# met: redistributions of source code must retain the above copyright
166145Snate@binkert.org# notice, this list of conditions and the following disclaimer;
176145Snate@binkert.org# redistributions in binary form must reproduce the above copyright
186145Snate@binkert.org# notice, this list of conditions and the following disclaimer in the
196145Snate@binkert.org# documentation and/or other materials provided with the distribution;
206145Snate@binkert.org# neither the name of the copyright holders nor the names of its
216145Snate@binkert.org# contributors may be used to endorse or promote products derived from
226145Snate@binkert.org# this software without specific prior written permission.
236145Snate@binkert.org#
246145Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
256145Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
266145Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
276145Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
286145Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
297039Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
307039Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
316145Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
327039Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
337039Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3410301Snilay@cs.wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
357039Snate@binkert.org#
3610301Snilay@cs.wisc.edu# Authors: Andreas Hansson
376145Snate@binkert.org#          Ani Udipi
386145Snate@binkert.org
396145Snate@binkert.orgfrom m5.params import *
407039Snate@binkert.orgfrom AbstractMemory import *
4111025Snilay@cs.wisc.edu
426145Snate@binkert.org# Enum for memory scheduling algorithms, currently First-Come
437039Snate@binkert.org# First-Served and a First-Row Hit then First-Come First-Served
446145Snate@binkert.orgclass MemSched(Enum): vals = ['fcfs', 'frfcfs']
456145Snate@binkert.org
4611308Santhony.gutierrez@amd.com# Enum for the address mapping. With Ra, Co, Ba and Ch denoting rank,
4711308Santhony.gutierrez@amd.com# column, bank and channel, respectively, and going from MSB to LSB.
4811308Santhony.gutierrez@amd.com# Available are RaBaChCo and RaBaCoCh, that are suitable for an
4911308Santhony.gutierrez@amd.com# open-page policy, optimising for sequential accesses hitting in the
5011308Santhony.gutierrez@amd.com# open row. For a closed-page policy, CoRaBaCh maximises parallelism.
5111308Santhony.gutierrez@amd.comclass AddrMap(Enum): vals = ['RaBaChCo', 'RaBaCoCh', 'CoRaBaCh']
526145Snate@binkert.org
536145Snate@binkert.org# Enum for the page policy, either open or close.
547039Snate@binkert.orgclass PageManage(Enum): vals = ['open', 'close']
5511025Snilay@cs.wisc.edu
566145Snate@binkert.org# SimpleDRAM is a single-channel single-ported DRAM controller model
577039Snate@binkert.org# that aims to model the most important system-level performance
587039Snate@binkert.org# effects of a DRAM without getting into too much detail of the DRAM
597039Snate@binkert.org# itself.
606145Snate@binkert.orgclass SimpleDRAM(AbstractMemory):
616145Snate@binkert.org    type = 'SimpleDRAM'
6211308Santhony.gutierrez@amd.com    cxx_header = "mem/simple_dram.hh"
6311308Santhony.gutierrez@amd.com
6411308Santhony.gutierrez@amd.com    @classmethod
6511308Santhony.gutierrez@amd.com    def makeMultiChannel(cls, nbr_mem_ctrls, mem_start_addr, mem_size,
6611308Santhony.gutierrez@amd.com                         intlv_high_bit = 11):
6711308Santhony.gutierrez@amd.com        """
6811308Santhony.gutierrez@amd.com        Make a multi-channel configuration of this class.
6911308Santhony.gutierrez@amd.com
7011308Santhony.gutierrez@amd.com        Create multiple instances of the specific class and set their
7111308Santhony.gutierrez@amd.com        parameters such that the address range is interleaved between
7211308Santhony.gutierrez@amd.com        them.
7311308Santhony.gutierrez@amd.com
7411308Santhony.gutierrez@amd.com        Returns a list of controllers.
7511308Santhony.gutierrez@amd.com        """
7611308Santhony.gutierrez@amd.com        import math
7711308Santhony.gutierrez@amd.com        from m5.util import fatal
787039Snate@binkert.org        intlv_bits = int(math.log(nbr_mem_ctrls, 2))
797039Snate@binkert.org        if 2 ** intlv_bits != nbr_mem_ctrls:
806843Sdrh5@cs.wisc.edu            fatal("Number of memory channels must be a power of 2")
817039Snate@binkert.org        mem_ctrls = []
8210005Snilay@cs.wisc.edu        for i in xrange(nbr_mem_ctrls):
837039Snate@binkert.org            # The default interleaving granularity is tuned to match a
847039Snate@binkert.org            # row buffer size of 32 cache lines of 64 bytes (starting
857039Snate@binkert.org            # at bit 11 for 2048 bytes). There is unfortunately no
867039Snate@binkert.org            # good way of checking this at instantiation time.
876843Sdrh5@cs.wisc.edu            mem_ctrls.append(cls(range = AddrRange(mem_start_addr,
886843Sdrh5@cs.wisc.edu                                                   size = mem_size,
897039Snate@binkert.org                                                   intlvHighBit = \
9011025Snilay@cs.wisc.edu                                                       intlv_high_bit,
9110005Snilay@cs.wisc.edu                                                   intlvBits = intlv_bits,
926467Sdrh5@cs.wisc.edu                                                   intlvMatch = i),
937039Snate@binkert.org                                 channels = nbr_mem_ctrls))
947039Snate@binkert.org        return mem_ctrls
9510005Snilay@cs.wisc.edu
9610005Snilay@cs.wisc.edu    # single-ported on the system interface side, instantiate with a
9711025Snilay@cs.wisc.edu    # bus in front of the controller for multiple ports
9810005Snilay@cs.wisc.edu    port = SlavePort("Slave port")
996468Sdrh5@cs.wisc.edu
1006467Sdrh5@cs.wisc.edu    # the basic configuration of the controller architecture
1016467Sdrh5@cs.wisc.edu    write_buffer_size = Param.Unsigned(32, "Number of read queue entries")
1027039Snate@binkert.org    read_buffer_size = Param.Unsigned(32, "Number of write queue entries")
1037039Snate@binkert.org
1046145Snate@binkert.org    # threshold in percent for when to trigger writes and start
1057039Snate@binkert.org    # emptying the write buffer as it starts to get full
1066145Snate@binkert.org    write_thresh_perc = Param.Percent(70, "Threshold to trigger writes")
1076145Snate@binkert.org
1087039Snate@binkert.org    # scheduler, address map and page policy
1097039Snate@binkert.org    mem_sched_policy = Param.MemSched('frfcfs', "Memory scheduling policy")
1106145Snate@binkert.org    addr_mapping = Param.AddrMap('RaBaChCo', "Address mapping policy")
1117039Snate@binkert.org    page_policy = Param.PageManage('open', "Page closure management policy")
1126145Snate@binkert.org
1136145Snate@binkert.org    # pipeline latency of the controller and PHY, split into a
1147039Snate@binkert.org    # frontend part and a backend part, with reads and writes serviced
1157039Snate@binkert.org    # by the queues only seeing the frontend contribution, and reads
1167039Snate@binkert.org    # serviced by the memory seeing the sum of the two
1176926SBrad.Beckmann@amd.com    static_frontend_latency = Param.Latency("10ns", "Static frontend latency")
1186926SBrad.Beckmann@amd.com    static_backend_latency = Param.Latency("10ns", "Static backend latency")
1196145Snate@binkert.org
12010008Snilay@cs.wisc.edu    # the physical organisation of the DRAM
12110008Snilay@cs.wisc.edu    lines_per_rowbuffer = Param.Unsigned("Row buffer size in cache lines")
12210008Snilay@cs.wisc.edu    ranks_per_channel = Param.Unsigned("Number of ranks per channel")
12310008Snilay@cs.wisc.edu    banks_per_rank = Param.Unsigned("Number of banks per rank")
12410008Snilay@cs.wisc.edu    # only used for the address mapping as the controller by
12510008Snilay@cs.wisc.edu    # construction is a single channel and multiple controllers have
12610008Snilay@cs.wisc.edu    # to be instantiated for a multi-channel configuration
12711308Santhony.gutierrez@amd.com    channels = Param.Unsigned(1, "Number of channels")
12811308Santhony.gutierrez@amd.com
12911308Santhony.gutierrez@amd.com    # timing behaviour and constraints - all in nanoseconds
13011308Santhony.gutierrez@amd.com
13111308Santhony.gutierrez@amd.com    # the amount of time in nanoseconds from issuing an activate command
13211308Santhony.gutierrez@amd.com    # to the data being available in the row buffer for a read/write
13311308Santhony.gutierrez@amd.com    tRCD = Param.Latency("RAS to CAS delay")
1347039Snate@binkert.org
135    # the time from issuing a read/write command to seeing the actual data
136    tCL = Param.Latency("CAS latency")
137
138    # minimum time between a precharge and subsequent activate
139    tRP = Param.Latency("Row precharge time")
140
141    # time to complete a burst transfer, typically the burst length
142    # divided by two due to the DDR bus, but by making it a parameter
143    # it is easier to also evaluate SDR memories like WideIO.
144    # This parameter has to account for bus width and burst length.
145    # Adjustment also necessary if cache line size is greater than
146    # data size read/written by one full burst.
147    tBURST = Param.Latency("Burst duration (for DDR burst length / 2 cycles)")
148
149    # time taken to complete one refresh cycle (N rows in all banks)
150    tRFC = Param.Latency("Refresh cycle time")
151
152    # refresh command interval, how often a "ref" command needs
153    # to be sent. It is 7.8 us for a 64ms refresh requirement
154    tREFI = Param.Latency("Refresh command interval")
155
156    # write-to-read turn around penalty, assumed same as read-to-write
157    tWTR = Param.Latency("Write to read switching time")
158
159    # time window in which a maximum number of activates are allowed
160    # to take place, set to 0 to disable
161    tXAW = Param.Latency("X activation window")
162    activation_limit = Param.Unsigned("Max number of activates in window")
163
164    # Currently rolled into other params
165    ######################################################################
166
167    # the minimum amount of time between a row being activated, and
168    # precharged (de-activated)
169    # tRAS - assumed to be 3 * tRP
170
171    # tRC  - assumed to be 4 * tRP
172
173    # burst length for an access derived from peerBlockSize
174
175# A single DDR3 x64 interface (one command and address bus), with
176# default timings based on DDR3-1600 4 Gbit parts in an 8x8
177# configuration, which would amount to 4 Gbyte of memory.
178class DDR3_1600_x64(SimpleDRAM):
179    # Assuming 64 byte cache lines, and a 1kbyte page size per module
180    # (this depends on the memory density)
181    lines_per_rowbuffer = 128
182
183    # Use two ranks
184    ranks_per_channel = 2
185
186    # DDR3 has 8 banks in all configurations
187    banks_per_rank = 8
188
189    # DDR3-1600 11-11-11
190    tRCD = '13.75ns'
191    tCL = '13.75ns'
192    tRP = '13.75ns'
193
194    # Assuming 64 byte cache lines, across an x64
195    # interface, translates to BL8, 4 clocks @ 800 MHz
196    tBURST = '5ns'
197
198    # DDR3, 4 Gbit has a tRFC of 240 CK and tCK = 1.25 ns
199    tRFC = '300ns'
200
201    # DDR3, <=85C, half for >85C
202    tREFI = '7.8us'
203
204    # Greater of 4 CK or 7.5 ns, 4 CK @ 800 MHz = 5 ns
205    tWTR = '7.5ns'
206
207    # With a 2kbyte page size, DDR3-1600 lands around 40 ns
208    tXAW = '40ns'
209    activation_limit = 4
210
211
212# A single LPDDR2-S4 x32 interface (one command/address bus), with
213# default timings based on a LPDDR2-1066 4 Gbit part in a 1x32
214# configuration.
215class LPDDR2_S4_1066_x32(SimpleDRAM):
216    # Assuming 64 byte cache lines, use a 1kbyte page size, this
217    # depends on the memory density
218    lines_per_rowbuffer = 16
219
220    # Use a single rank
221    ranks_per_channel = 1
222
223    # LPDDR2-S4 has 8 banks in all configurations
224    banks_per_rank = 8
225
226    # Fixed at 15 ns
227    tRCD = '15ns'
228
229    # 8 CK read latency, 4 CK write latency @ 533 MHz, 1.876 ns cycle time
230    tCL = '15ns'
231
232    # Pre-charge one bank 15 ns (all banks 18 ns)
233    tRP = '15ns'
234
235    # Assuming 64 byte cache lines, across a x32 DDR interface
236    # translates to two BL8, 8 clocks @ 533 MHz. Note that this is a
237    # simplification
238    tBURST = '15ns'
239
240    # LPDDR2-S4, 4 Gbit
241    tRFC = '130ns'
242    tREFI = '3.9us'
243
244    # Irrespective of speed grade, tWTR is 7.5 ns
245    tWTR = '7.5ns'
246
247    # Irrespective of density, tFAW is 50 ns
248    tXAW = '50ns'
249    activation_limit = 4
250
251# A single WideIO x128 interface (one command and address bus), with
252# default timings based on an estimated WIO-200 8 Gbit part.
253class WideIO_200_x128(SimpleDRAM):
254    # Assuming 64 byte cache lines, use a 4kbyte page size, this
255    # depends on the memory density
256    lines_per_rowbuffer = 64
257
258    # Use one rank for a one-high die stack
259    ranks_per_channel = 1
260
261    # WideIO has 4 banks in all configurations
262    banks_per_rank = 4
263
264    # WIO-200
265    tRCD = '18ns'
266    tCL = '18ns'
267    tRP = '18ns'
268
269    # Assuming 64 byte cache lines, across an x128 SDR interface,
270    # translates to BL4, 4 clocks @ 200 MHz
271    tBURST = '20ns'
272
273    # WIO 8 Gb
274    tRFC = '210ns'
275
276    # WIO 8 Gb, <=85C, half for >85C
277    tREFI = '3.9us'
278
279    # Greater of 2 CK or 15 ns, 2 CK @ 200 MHz = 10 ns
280    tWTR = '15ns'
281
282    # Two instead of four activation window
283    tXAW = '50ns'
284    activation_limit = 2
285
286# A single LPDDR3 x32 interface (one command/address bus), with
287# default timings based on a LPDDR3-1600 4 Gbit part in a 1x32
288# configuration
289class LPDDR3_1600_x32(SimpleDRAM):
290    # 4 Gbit and 8 Gbit devices use a 1 kByte page size, so ssuming 64
291    # byte cache lines, that is 16 lines
292    lines_per_rowbuffer = 16
293
294    # Use a single rank
295    ranks_per_channel = 1
296
297    # LPDDR3 has 8 banks in all configurations
298    banks_per_rank = 8
299
300    # Fixed at 15 ns
301    tRCD = '15ns'
302
303    # 12 CK read latency, 6 CK write latency @ 800 MHz, 1.25 ns cycle time
304    tCL = '15ns'
305
306    # Pre-charge one bank 15 ns (all banks 18 ns)
307    tRP = '15ns'
308
309    # Assuming 64 byte cache lines, across a x32 DDR interface
310    # translates to two bursts of BL8, 8 clocks @ 800 MHz
311    tBURST = '10ns'
312
313    # LPDDR3, 4 Gb
314    tRFC = '130ns'
315    tREFI = '3.9us'
316
317    # Irrespective of speed grade, tWTR is 7.5 ns
318    tWTR = '7.5ns'
319
320    # Irrespective of size, tFAW is 50 ns
321    tXAW = '50ns'
322    activation_limit = 4
323