[707] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
[802] | 3 | from math import log, ceil |
---|
[707] | 4 | from mapping import * |
---|
| 5 | |
---|
| 6 | ####################################################################################### |
---|
[714] | 7 | # file : arch.py (for the tsar_generic_iob architecture) |
---|
[707] | 8 | # date : may 2014 |
---|
| 9 | # author : Alain Greiner |
---|
| 10 | ####################################################################################### |
---|
[802] | 11 | # This file contains a mapping generator for the "tsar_generic_iob" platform. |
---|
[707] | 12 | # This includes both the hardware architecture (clusters, processors, peripherals, |
---|
| 13 | # physical space segmentation) and the mapping of all kernel objects (global vsegs). |
---|
| 14 | # This platform includes 6 external peripherals, accessible through two IO_Bridge |
---|
[730] | 15 | # components located in cluster [0,0] and cluster [x_size-1, y_size-1]. |
---|
| 16 | # Available peripherals are: TTY, BDV, FBF, ROM, NIC, CMA. |
---|
[714] | 17 | # |
---|
| 18 | # The "constructor" parameters are: |
---|
| 19 | # - x_size : number of clusters in a row |
---|
| 20 | # - y_size : number of clusters in a column |
---|
| 21 | # - nb_procs : number of processors per cluster |
---|
| 22 | # |
---|
[754] | 23 | # The "hidden" parameters (defined below) are: |
---|
[714] | 24 | # - nb_ttys : number of TTY channels |
---|
| 25 | # - nb_nics : number of NIC channels |
---|
| 26 | # - fbf_width : frame_buffer width = frame_buffer heigth |
---|
| 27 | # - x_io : cluster_io x coordinate |
---|
| 28 | # - y_io : cluster_io y coordinate |
---|
| 29 | # - x_width : number of bits for x coordinate |
---|
| 30 | # - y_width : number of bits for y coordinate |
---|
| 31 | # - paddr_width : number of bits for physical address |
---|
| 32 | # - irq_per_proc : number of input IRQs per processor |
---|
| 33 | # - use_ramdisk : use a ramdisk when True |
---|
| 34 | # - peri_increment : address increment for replicated peripherals |
---|
[707] | 35 | #################################################################################### |
---|
| 36 | |
---|
[714] | 37 | ######################## |
---|
| 38 | def arch( x_size = 2, |
---|
| 39 | y_size = 2, |
---|
| 40 | nb_procs = 2 ): |
---|
| 41 | |
---|
| 42 | ### define architecture constants |
---|
| 43 | |
---|
[734] | 44 | nb_ttys = 1 |
---|
[802] | 45 | nb_nics = 2 |
---|
[764] | 46 | fbf_width = 128 |
---|
[734] | 47 | x_io = 0 |
---|
| 48 | y_io = 0 |
---|
| 49 | x_width = 4 |
---|
| 50 | y_width = 4 |
---|
[802] | 51 | p_width = int(ceil(log(nb_procs, 2))) |
---|
[734] | 52 | paddr_width = 40 |
---|
| 53 | irq_per_proc = 4 |
---|
| 54 | use_ramdisk = False |
---|
| 55 | peri_increment = 0x10000 |
---|
| 56 | distributed_ptabs = True |
---|
[802] | 57 | |
---|
[707] | 58 | ### parameters checking |
---|
[714] | 59 | |
---|
[802] | 60 | assert( nb_procs <= (1 << p_width) ) |
---|
[707] | 61 | |
---|
[802] | 62 | assert( (x_size == 1) or (x_size == 2) or (x_size == 4) |
---|
[764] | 63 | or (x_size == 8) or (x_size == 16) ) |
---|
[707] | 64 | |
---|
[802] | 65 | assert( (y_size == 1) or (y_size == 2) or (y_size == 4) |
---|
[707] | 66 | or (y_size == 8) or (y_size == 16) ) |
---|
| 67 | |
---|
[714] | 68 | assert( nb_ttys == 1 ) |
---|
[707] | 69 | |
---|
| 70 | assert( ((x_io == 0) and (y_io == 0)) or |
---|
| 71 | ((x_io == x_size-1) and (y_io == y_size-1)) ) |
---|
| 72 | |
---|
[714] | 73 | platform_name = 'tsar_iob_%d_%d_%d' % ( x_size, y_size, nb_procs ) |
---|
[802] | 74 | |
---|
[707] | 75 | ### define physical segments |
---|
| 76 | |
---|
| 77 | ram_base = 0x0000000000 |
---|
[714] | 78 | ram_size = 0x4000000 # 64 Mbytes |
---|
[707] | 79 | |
---|
[802] | 80 | xcu_base = 0x00B0000000 |
---|
| 81 | xcu_size = 0x1000 # 4 Kbytes |
---|
[707] | 82 | |
---|
| 83 | dma_base = 0x00B1000000 |
---|
[714] | 84 | dma_size = 0x1000 * nb_procs # 4 Kbytes * nb_procs |
---|
[707] | 85 | |
---|
[802] | 86 | mmc_base = 0x00B2000000 |
---|
[714] | 87 | mmc_size = 0x1000 # 4 Kbytes |
---|
[707] | 88 | |
---|
| 89 | offset_io = ((x_io << y_width) + y_io) << (paddr_width - x_width - y_width) |
---|
| 90 | |
---|
| 91 | bdv_base = 0x00B3000000 + offset_io |
---|
[714] | 92 | bdv_size = 0x1000 # 4kbytes |
---|
[707] | 93 | |
---|
| 94 | tty_base = 0x00B4000000 + offset_io |
---|
[714] | 95 | tty_size = 0x4000 # 16 Kbytes |
---|
[707] | 96 | |
---|
| 97 | nic_base = 0x00B5000000 + offset_io |
---|
[714] | 98 | nic_size = 0x80000 # 512 kbytes |
---|
[707] | 99 | |
---|
| 100 | cma_base = 0x00B6000000 + offset_io |
---|
[714] | 101 | cma_size = 0x1000 * 2 * nb_nics # 4 kbytes * 2 * nb_nics |
---|
[707] | 102 | |
---|
| 103 | fbf_base = 0x00B7000000 + offset_io |
---|
[714] | 104 | fbf_size = fbf_width * fbf_width # fbf_width * fbf_width bytes |
---|
[707] | 105 | |
---|
| 106 | pic_base = 0x00B8000000 + offset_io |
---|
[714] | 107 | pic_size = 0x1000 # 4 Kbytes |
---|
[707] | 108 | |
---|
| 109 | iob_base = 0x00BE000000 + offset_io |
---|
[714] | 110 | iob_size = 0x1000 # 4kbytes |
---|
[707] | 111 | |
---|
| 112 | rom_base = 0x00BFC00000 + offset_io |
---|
[714] | 113 | rom_size = 0x4000 # 16 Kbytes |
---|
[707] | 114 | |
---|
[754] | 115 | ### define bootloader vsegs base addresses and sizes |
---|
[707] | 116 | |
---|
[714] | 117 | boot_mapping_vbase = 0x00000000 # ident |
---|
[764] | 118 | boot_mapping_size = 0x00080000 # 512 Kbytes |
---|
[707] | 119 | |
---|
[762] | 120 | boot_code_vbase = 0x00080000 # ident |
---|
[802] | 121 | boot_code_size = 0x00040000 # 256 Kbytes |
---|
| 122 | |
---|
[762] | 123 | boot_data_vbase = 0x000C0000 # ident |
---|
[764] | 124 | boot_data_size = 0x00080000 # 512 Kbytes |
---|
[707] | 125 | |
---|
[762] | 126 | boot_stack_vbase = 0x00140000 # ident |
---|
[714] | 127 | boot_stack_size = 0x00050000 # 320 Kbytes |
---|
[707] | 128 | |
---|
[754] | 129 | ### define kernel vsegs base addresses and sizes |
---|
[707] | 130 | |
---|
[802] | 131 | kernel_code_vbase = 0x80000000 |
---|
[714] | 132 | kernel_code_size = 0x00020000 # 128 Kbytes |
---|
[707] | 133 | |
---|
| 134 | kernel_data_vbase = 0x80020000 |
---|
[762] | 135 | kernel_data_size = 0x00020000 # 128 Kbytes |
---|
[707] | 136 | |
---|
[762] | 137 | kernel_uncdata_vbase = 0x80040000 |
---|
| 138 | kernel_uncdata_size = 0x00010000 # 64 Kbytes |
---|
[707] | 139 | |
---|
[762] | 140 | kernel_init_vbase = 0x80050000 |
---|
[714] | 141 | kernel_init_size = 0x00010000 # 64 Kbytes |
---|
[707] | 142 | |
---|
| 143 | kernel_sched_vbase = 0xF0000000 # distributed in all clusters |
---|
[764] | 144 | kernel_sched_size = 0x2000 * nb_procs # 8 kbytes per processor |
---|
[707] | 145 | |
---|
| 146 | ### create mapping |
---|
| 147 | |
---|
[802] | 148 | mapping = Mapping( name = platform_name, |
---|
| 149 | x_size = x_size, |
---|
| 150 | y_size = y_size, |
---|
| 151 | procs_max = nb_procs, |
---|
| 152 | x_width = x_width, |
---|
| 153 | y_width = y_width, |
---|
| 154 | p_width = p_width, |
---|
| 155 | paddr_width = paddr_width, |
---|
| 156 | coherence = True, |
---|
| 157 | irq_per_proc = irq_per_proc, |
---|
| 158 | use_ramdisk = use_ramdisk, |
---|
| 159 | x_io = x_io, |
---|
[714] | 160 | y_io = y_io, |
---|
[802] | 161 | peri_increment = peri_increment, |
---|
| 162 | ram_base = ram_base, |
---|
| 163 | ram_size = ram_size ) |
---|
[707] | 164 | |
---|
| 165 | ### external peripherals (accessible in cluster[0,0] only for this mapping) |
---|
| 166 | |
---|
| 167 | iob = mapping.addPeriph( 'IOB', base = iob_base, size = iob_size, ptype = 'IOB' ) |
---|
| 168 | |
---|
| 169 | bdv = mapping.addPeriph( 'BDV', base = bdv_base, size = bdv_size, ptype = 'IOC', subtype = 'BDV' ) |
---|
| 170 | |
---|
| 171 | tty = mapping.addPeriph( 'TTY', base = tty_base, size = tty_size, ptype = 'TTY', channels = nb_ttys ) |
---|
| 172 | |
---|
[802] | 173 | nic = mapping.addPeriph( 'NIC', base = nic_base, size = nic_size, ptype = 'NIC', channels = nb_nics ) |
---|
[707] | 174 | |
---|
| 175 | cma = mapping.addPeriph( 'CMA', base = cma_base, size = cma_size, ptype = 'CMA', channels = 2*nb_nics ) |
---|
| 176 | |
---|
[714] | 177 | fbf = mapping.addPeriph( 'FBF', base = fbf_base, size = fbf_size, ptype = 'FBF', arg = fbf_width ) |
---|
[707] | 178 | |
---|
| 179 | rom = mapping.addPeriph( 'ROM', base = rom_base, size = rom_size, ptype = 'ROM' ) |
---|
| 180 | |
---|
| 181 | pic = mapping.addPeriph( 'PIC', base = pic_base, size = pic_size, ptype = 'PIC', channels = 32 ) |
---|
| 182 | |
---|
[710] | 183 | mapping.addIrq( pic, index = 0, isrtype = 'ISR_NIC_RX', channel = 0 ) |
---|
| 184 | mapping.addIrq( pic, index = 1, isrtype = 'ISR_NIC_RX', channel = 1 ) |
---|
[707] | 185 | |
---|
[710] | 186 | mapping.addIrq( pic, index = 2, isrtype = 'ISR_NIC_TX', channel = 0 ) |
---|
| 187 | mapping.addIrq( pic, index = 3, isrtype = 'ISR_NIC_TX', channel = 1 ) |
---|
[707] | 188 | |
---|
[710] | 189 | mapping.addIrq( pic, index = 4, isrtype = 'ISR_CMA' , channel = 0 ) |
---|
| 190 | mapping.addIrq( pic, index = 5, isrtype = 'ISR_CMA' , channel = 1 ) |
---|
| 191 | mapping.addIrq( pic, index = 6, isrtype = 'ISR_CMA' , channel = 2 ) |
---|
| 192 | mapping.addIrq( pic, index = 7, isrtype = 'ISR_CMA' , channel = 3 ) |
---|
[707] | 193 | |
---|
[710] | 194 | mapping.addIrq( pic, index = 8, isrtype = 'ISR_BDV' , channel = 0 ) |
---|
[707] | 195 | |
---|
[710] | 196 | mapping.addIrq( pic, index = 9, isrtype = 'ISR_TTY_RX', channel = 0 ) |
---|
| 197 | |
---|
[802] | 198 | ### hardware components replicated in all clusters |
---|
[707] | 199 | |
---|
| 200 | for x in xrange( x_size ): |
---|
| 201 | for y in xrange( y_size ): |
---|
| 202 | cluster_xy = (x << y_width) + y; |
---|
| 203 | offset = cluster_xy << (paddr_width - x_width - y_width) |
---|
| 204 | |
---|
| 205 | ram = mapping.addRam( 'RAM', base = ram_base + offset, size = ram_size ) |
---|
| 206 | |
---|
[802] | 207 | mmc = mapping.addPeriph( 'MMC', base = mmc_base + offset, size = mmc_size, |
---|
[707] | 208 | ptype = 'MMC' ) |
---|
| 209 | |
---|
[802] | 210 | dma = mapping.addPeriph( 'DMA', base = dma_base + offset, size = dma_size, |
---|
| 211 | ptype = 'DMA', channels = nb_procs ) |
---|
[707] | 212 | |
---|
[802] | 213 | xcu = mapping.addPeriph( 'XCU', base = xcu_base + offset, size = xcu_size, |
---|
[710] | 214 | ptype = 'XCU', channels = nb_procs * irq_per_proc, arg = 16 ) |
---|
[707] | 215 | |
---|
[710] | 216 | # MMC IRQ replicated in all clusters |
---|
| 217 | mapping.addIrq( xcu, index = 0, isrtype = 'ISR_MMC' ) |
---|
| 218 | |
---|
[770] | 219 | # DMA IRQ replicated in all clusters |
---|
| 220 | for i in xrange ( dma.channels ): |
---|
| 221 | mapping.addIrq( xcu, index = 1+i, isrtype = 'ISR_DMA', |
---|
| 222 | channel = i ) |
---|
| 223 | |
---|
[707] | 224 | # processors |
---|
| 225 | for p in xrange ( nb_procs ): |
---|
| 226 | mapping.addProc( x, y, p ) |
---|
| 227 | |
---|
[802] | 228 | ### global vsegs for boot_loader / identity mapping |
---|
[707] | 229 | |
---|
[730] | 230 | mapping.addGlobal( 'seg_boot_mapping', boot_mapping_vbase, boot_mapping_size, |
---|
| 231 | 'C_W_', vtype = 'BLOB' , x = 0, y = 0, pseg = 'RAM', |
---|
| 232 | identity = True ) |
---|
[707] | 233 | |
---|
[730] | 234 | mapping.addGlobal( 'seg_boot_code', boot_code_vbase, boot_code_size, |
---|
| 235 | 'CXW_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
| 236 | identity = True ) |
---|
[707] | 237 | |
---|
[730] | 238 | mapping.addGlobal( 'seg_boot_data', boot_data_vbase, boot_data_size, |
---|
| 239 | 'C_W_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
| 240 | identity = True ) |
---|
[707] | 241 | |
---|
[730] | 242 | mapping.addGlobal( 'seg_boot_stack', boot_stack_vbase, boot_stack_size, |
---|
| 243 | 'C_W_', vtype = 'BUFFER', x = 0, y = 0, pseg = 'RAM', |
---|
| 244 | identity = True ) |
---|
[707] | 245 | |
---|
[802] | 246 | ### the code global vsegs for kernel can be replicated in all clusters |
---|
[734] | 247 | ### if the page tables are distributed in all clusters. |
---|
[707] | 248 | |
---|
[734] | 249 | if distributed_ptabs: |
---|
| 250 | for x in xrange( x_size ): |
---|
| 251 | for y in xrange( y_size ): |
---|
| 252 | cluster_xy = (x << y_width) + y; |
---|
[707] | 253 | |
---|
[734] | 254 | mapping.addGlobal( 'seg_kernel_code', kernel_code_vbase, kernel_code_size, |
---|
| 255 | 'CXW_', vtype = 'ELF', x = x , y = y , pseg = 'RAM', |
---|
| 256 | binpath = 'build/kernel/kernel.elf', local = True ) |
---|
[707] | 257 | |
---|
[734] | 258 | mapping.addGlobal( 'seg_kernel_init', kernel_init_vbase, kernel_init_size, |
---|
| 259 | 'CXW_', vtype = 'ELF', x = x , y = y , pseg = 'RAM', |
---|
| 260 | binpath = 'build/kernel/kernel.elf', local = True ) |
---|
| 261 | else: |
---|
| 262 | mapping.addGlobal( 'seg_kernel_code', kernel_code_vbase, kernel_code_size, |
---|
| 263 | 'CXW_', vtype = 'ELF', x = 0 , y = 0 , pseg = 'RAM', |
---|
| 264 | binpath = 'build/kernel/kernel.elf', local = False ) |
---|
[707] | 265 | |
---|
[734] | 266 | mapping.addGlobal( 'seg_kernel_init', kernel_init_vbase, kernel_init_size, |
---|
| 267 | 'CXW_', vtype = 'ELF', x = 0 , y = 0 , pseg = 'RAM', |
---|
| 268 | binpath = 'build/kernel/kernel.elf', local = False ) |
---|
| 269 | |
---|
[730] | 270 | ### shared global vsegs for kernel |
---|
[707] | 271 | |
---|
[802] | 272 | mapping.addGlobal( 'seg_kernel_data', kernel_data_vbase, kernel_data_size, |
---|
| 273 | 'C_W_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
[730] | 274 | binpath = 'build/kernel/kernel.elf', local = False ) |
---|
| 275 | |
---|
| 276 | mapping.addGlobal( 'seg_kernel_uncdata', kernel_uncdata_vbase, kernel_uncdata_size, |
---|
[802] | 277 | '__W_', vtype = 'ELF', x = 0, y = 0, pseg = 'RAM', |
---|
[730] | 278 | binpath = 'build/kernel/kernel.elf', local = False ) |
---|
| 279 | |
---|
[707] | 280 | ### global vsegs for external peripherals / identity mapping |
---|
| 281 | |
---|
[802] | 282 | mapping.addGlobal( 'seg_iob', iob_base, iob_size, '__W_', |
---|
| 283 | vtype = 'PERI', x = 0, y = 0, pseg = 'IOB', |
---|
[730] | 284 | identity = True ) |
---|
[707] | 285 | |
---|
[802] | 286 | mapping.addGlobal( 'seg_bdv', bdv_base, bdv_size, '__W_', |
---|
[730] | 287 | vtype = 'PERI', x = 0, y = 0, pseg = 'BDV', |
---|
| 288 | identity = True ) |
---|
[707] | 289 | |
---|
[802] | 290 | mapping.addGlobal( 'seg_tty', tty_base, tty_size, '__W_', |
---|
[730] | 291 | vtype = 'PERI', x = 0, y = 0, pseg = 'TTY', |
---|
| 292 | identity = True ) |
---|
[707] | 293 | |
---|
[802] | 294 | mapping.addGlobal( 'seg_nic', nic_base, nic_size, '__W_', |
---|
[730] | 295 | vtype = 'PERI', x = 0, y = 0, pseg = 'NIC', |
---|
| 296 | identity = True ) |
---|
[707] | 297 | |
---|
[802] | 298 | mapping.addGlobal( 'seg_cma', cma_base, cma_size, '__W_', |
---|
[730] | 299 | vtype = 'PERI', x = 0, y = 0, pseg = 'CMA', |
---|
| 300 | identity = True ) |
---|
[707] | 301 | |
---|
[802] | 302 | mapping.addGlobal( 'seg_fbf', fbf_base, fbf_size, '__W_', |
---|
[730] | 303 | vtype = 'PERI', x = 0, y = 0, pseg = 'FBF', |
---|
| 304 | identity = True ) |
---|
[707] | 305 | |
---|
[802] | 306 | mapping.addGlobal( 'seg_pic', pic_base, pic_size, '__W_', |
---|
[730] | 307 | vtype = 'PERI', x = 0, y = 0, pseg = 'PIC', |
---|
| 308 | identity = True ) |
---|
[707] | 309 | |
---|
[802] | 310 | mapping.addGlobal( 'seg_rom', rom_base, rom_size, 'CXW_', |
---|
[730] | 311 | vtype = 'PERI', x = 0, y = 0, pseg = 'ROM', |
---|
| 312 | identity = True ) |
---|
[707] | 313 | |
---|
[802] | 314 | ### global vsegs for internal peripherals, and for schedulers |
---|
[730] | 315 | ### name is indexed by (x,y) / vbase address is incremented by (cluster_xy * peri_increment) |
---|
[707] | 316 | |
---|
[714] | 317 | for x in xrange( x_size ): |
---|
| 318 | for y in xrange( y_size ): |
---|
| 319 | cluster_xy = (x << y_width) + y; |
---|
| 320 | offset = cluster_xy * peri_increment |
---|
[707] | 321 | |
---|
[714] | 322 | mapping.addGlobal( 'seg_xcu_%d_%d' %(x,y), xcu_base + offset, xcu_size, |
---|
| 323 | '__W_', vtype = 'PERI' , x = x , y = y , pseg = 'XCU' ) |
---|
[707] | 324 | |
---|
[714] | 325 | mapping.addGlobal( 'seg_dma_%d_%d' %(x,y), dma_base + offset, dma_size, |
---|
| 326 | '__W_', vtype = 'PERI' , x = x , y = y , pseg = 'DMA' ) |
---|
[707] | 327 | |
---|
[714] | 328 | mapping.addGlobal( 'seg_mmc_%d_%d' %(x,y), mmc_base + offset, mmc_size, |
---|
| 329 | '__W_', vtype = 'PERI' , x = x , y = y , pseg = 'MMC' ) |
---|
[707] | 330 | |
---|
[714] | 331 | mapping.addGlobal( 'seg_sched_%d_%d' %(x,y), kernel_sched_vbase + offset, kernel_sched_size, |
---|
| 332 | 'C_W_', vtype = 'SCHED', x = x , y = y , pseg = 'RAM' ) |
---|
| 333 | |
---|
[707] | 334 | ### return mapping ### |
---|
| 335 | |
---|
| 336 | return mapping |
---|
| 337 | |
---|
| 338 | ################################# platform test ####################################################### |
---|
| 339 | |
---|
| 340 | if __name__ == '__main__': |
---|
| 341 | |
---|
[730] | 342 | mapping = arch( x_size = 2, |
---|
| 343 | y_size = 2, |
---|
| 344 | nb_procs = 2 ) |
---|
[707] | 345 | |
---|
| 346 | # print mapping.netbsd_dts() |
---|
| 347 | |
---|
| 348 | print mapping.xml() |
---|
| 349 | |
---|
| 350 | # print mapping.giet_vsegs() |
---|
| 351 | |
---|
[802] | 352 | |
---|
[707] | 353 | # Local Variables: |
---|
| 354 | # tab-width: 4; |
---|
| 355 | # c-basic-offset: 4; |
---|
| 356 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 357 | # indent-tabs-mode: nil; |
---|
| 358 | # End: |
---|
| 359 | # |
---|
| 360 | # vim: filetype=python:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 361 | |
---|