1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 #include <linux/init.h>
  14 
  15 #include <asm/asm.h>
  16 #include <asm/asmmacro.h>
  17 #include <asm/cacheops.h>
  18 #include <asm/regdef.h>
  19 #include <asm/mipsregs.h>
  20 #include <asm/stackframe.h>
  21 #include <asm/addrspace.h>
  22 #include <asm/hazards.h>
  23 #include <asm/bmips.h>
  24 
  25 #ifdef CONFIG_CPU_BMIPS5000
  26 
  27 
  28 #define cacheop(kva, size, linesize, op)        \
  29         .set noreorder                  ;       \
  30         addu            t1, kva, size   ;       \
  31         subu            t2, linesize, 1 ;       \
  32         not             t2              ;       \
  33         and             t0, kva, t2     ;       \
  34         addiu           t1, t1, -1      ;       \
  35         and             t1, t2          ;       \
  36 9:      cache           op, 0(t0)       ;       \
  37         bne             t0, t1, 9b      ;       \
  38          addu           t0, linesize    ;       \
  39         .set reorder                    ;
  40 
  41 
  42 
  43 #define IS_SHIFT        22
  44 #define IL_SHIFT        19
  45 #define IA_SHIFT        16
  46 #define DS_SHIFT        13
  47 #define DL_SHIFT        10
  48 #define DA_SHIFT         7
  49 #define IS_MASK          7
  50 #define IL_MASK          7
  51 #define IA_MASK          7
  52 #define DS_MASK          7
  53 #define DL_MASK          7
  54 #define DA_MASK          7
  55 #define ICE_MASK        0x80000000
  56 #define DCE_MASK        0x40000000
  57 
  58 #define CP0_BRCM_CONFIG0        $22, 0
  59 #define CP0_BRCM_MODE           $22, 1
  60 #define CP0_CONFIG_K0_MASK      7
  61 
  62 #define CP0_ICACHE_TAG_LO       $28
  63 #define CP0_ICACHE_DATA_LO      $28, 1
  64 #define CP0_DCACHE_TAG_LO       $28, 2
  65 #define CP0_D_SEC_CACHE_DATA_LO $28, 3
  66 #define CP0_ICACHE_TAG_HI       $29
  67 #define CP0_ICACHE_DATA_HI      $29, 1
  68 #define CP0_DCACHE_TAG_HI       $29, 2
  69 
  70 #define CP0_BRCM_MODE_Luc_MASK          (1 << 11)
  71 #define CP0_BRCM_CONFIG0_CWF_MASK       (1 << 20)
  72 #define CP0_BRCM_CONFIG0_TSE_MASK       (1 << 19)
  73 #define CP0_BRCM_MODE_SET_MASK          (1 << 7)
  74 #define CP0_BRCM_MODE_ClkRATIO_MASK     (7 << 4)
  75 #define CP0_BRCM_MODE_BrPRED_MASK       (3 << 24)
  76 #define CP0_BRCM_MODE_BrPRED_SHIFT      24
  77 #define CP0_BRCM_MODE_BrHIST_MASK       (0x1f << 20)
  78 #define CP0_BRCM_MODE_BrHIST_SHIFT      20
  79 
  80 
  81 #define BRCM_ZSC_ALL_REGS_SELECT                0x7 << 24
  82 
  83 #define BRCM_ZSC_CONFIG_REG                     0 << 3
  84 #define BRCM_ZSC_REQ_BUFFER_REG                 2 << 3
  85 #define BRCM_ZSC_RBUS_ADDR_MAPPING_REG0         4 << 3
  86 #define BRCM_ZSC_RBUS_ADDR_MAPPING_REG1         6 << 3
  87 #define BRCM_ZSC_RBUS_ADDR_MAPPING_REG2         8 << 3
  88 
  89 #define BRCM_ZSC_SCB0_ADDR_MAPPING_REG0         0xa << 3
  90 #define BRCM_ZSC_SCB0_ADDR_MAPPING_REG1         0xc << 3
  91 
  92 #define BRCM_ZSC_SCB1_ADDR_MAPPING_REG0         0xe << 3
  93 #define BRCM_ZSC_SCB1_ADDR_MAPPING_REG1         0x10 << 3
  94 
  95 #define BRCM_ZSC_CONFIG_LMB1En                  1 << (15)
  96 #define BRCM_ZSC_CONFIG_LMB0En                  1 << (14)
  97 
  98 
  99 
 100 #define BRCM_BrPRED_ALL_TAKEN           (0x0)
 101 #define BRCM_BrPRED_ALL_NOT_TAKEN       (0x1)
 102 #define BRCM_BrPRED_BHT_ENABLE          (0x2)
 103 #define BRCM_BrPRED_PREDICT_BACKWARD    (0x3)
 104 
 105 
 106 
 107 .align 2
 108 
 109 
 110 
 111 
 112 
 113 
 114 
 115 
 116 
 117 
 118 
 119 LEAF(size_i_cache)
 120         .set    noreorder
 121 
 122         mfc0    a0, CP0_CONFIG, 1
 123         move    t0, a0
 124 
 125         
 126 
 127 
 128 
 129 
 130 
 131 
 132 
 133 
 134         srl     a0, a0, IS_SHIFT
 135         and     a0, a0, IS_MASK
 136 
 137         
 138 
 139         li      v0, 0x40
 140         sllv    v0, v0, a0
 141 
 142         
 143 
 144 
 145 
 146 
 147 
 148 
 149 
 150         move    a0, t0
 151 
 152         srl     a0, a0, IL_SHIFT
 153         and     a0, a0, IL_MASK
 154 
 155         beqz    a0, no_i_cache
 156         nop
 157 
 158         
 159 
 160         addi    a0, a0, 1
 161         li      v1, 1
 162         sll     v1, v1, a0
 163 
 164         
 165 
 166 
 167 
 168         sll     v0, v0, a0
 169 
 170         
 171 
 172 
 173 
 174 
 175 
 176 
 177 
 178         move    a0, t0
 179 
 180         srl     a0, a0, IA_SHIFT
 181         and     a0, a0, IA_MASK
 182         addi    a0, a0, 0x1
 183 
 184         
 185 
 186 
 187 
 188         multu   v0, a0  
 189         mflo    v0
 190         b       1f
 191         nop
 192 
 193 no_i_cache:
 194         move    v0, zero
 195         move    v1, zero
 196 1:
 197         jr      ra
 198         nop
 199         .set    reorder
 200 
 201 END(size_i_cache)
 202 
 203 
 204 
 205 
 206 
 207 
 208 
 209 
 210 
 211 
 212 LEAF(size_d_cache)
 213         .set    noreorder
 214 
 215         mfc0    a0, CP0_CONFIG, 1
 216         move    t0, a0
 217 
 218         
 219 
 220 
 221 
 222 
 223 
 224 
 225 
 226 
 227         srl     a0, a0, DS_SHIFT
 228         and     a0, a0, DS_MASK
 229 
 230         
 231 
 232         li      v0, 0x40
 233         sllv    v0, v0, a0
 234 
 235         
 236 
 237 
 238 
 239 
 240 
 241 
 242         move    a0, t0
 243 
 244         srl     a0, a0, DL_SHIFT
 245         and     a0, a0, DL_MASK
 246 
 247         beqz    a0, no_d_cache
 248         nop
 249 
 250         
 251 
 252         addi    a0, a0, 1
 253         li      v1, 1
 254         sll     v1, v1, a0
 255 
 256         
 257 
 258 
 259 
 260         sll     v0, v0, a0
 261 
 262         
 263 
 264 
 265 
 266 
 267 
 268 
 269         move    a0, t0
 270 
 271         srl     a0, a0, DA_SHIFT
 272         and     a0, a0, DA_MASK
 273         addi    a0, a0, 0x1
 274 
 275         
 276 
 277 
 278 
 279         multu   v0, a0  
 280         mflo    v0
 281 
 282         b       1f
 283         nop
 284 
 285 no_d_cache:
 286         move    v0, zero
 287         move    v1, zero
 288 1:
 289         jr      ra
 290         nop
 291         .set    reorder
 292 
 293 END(size_d_cache)
 294 
 295 
 296 
 297 
 298 
 299 
 300 
 301 
 302 
 303 
 304 
 305         .global enable_ID
 306         .ent    enable_ID
 307         .set    noreorder
 308 enable_ID:
 309         mfc0    t0, CP0_BRCM_CONFIG0
 310         or      t0, t0, (ICE_MASK | DCE_MASK)
 311         mtc0    t0, CP0_BRCM_CONFIG0
 312         jr      ra
 313         nop
 314 
 315         .end    enable_ID
 316         .set    reorder
 317 
 318 
 319 
 320 
 321 
 322 
 323 
 324 
 325 
 326 
 327         .globl  l1_init
 328         .ent    l1_init
 329         .set    noreorder
 330 l1_init:
 331 
 332         
 333         move    t8, ra
 334 
 335 
 336         
 337         mtc0    zero, CP0_ICACHE_TAG_LO
 338         mtc0    zero, CP0_ICACHE_TAG_HI
 339         mtc0    zero, CP0_ICACHE_DATA_LO
 340         mtc0    zero, CP0_ICACHE_DATA_HI
 341         mtc0    zero, CP0_DCACHE_TAG_LO
 342         mtc0    zero, CP0_DCACHE_TAG_HI
 343 
 344         
 345 
 346 
 347 
 348         jal     enable_ID
 349         nop
 350 
 351         jal     size_i_cache    
 352         nop
 353 
 354         
 355         la      k0, 1f
 356         lui     k1, 0x2000
 357         or      k0, k1, k0
 358         jr      k0
 359         nop
 360 1:
 361 
 362         
 363 
 364 
 365 
 366         mfc0    t0, CP0_CONFIG
 367         and     t0, t0, ~CP0_CONFIG_K0_MASK
 368         or      t0, t0, 3       
 369         mtc0    t0, CP0_CONFIG
 370 
 371         
 372 
 373 
 374 
 375         li      a0, KSEG0
 376         cacheop(a0, v0, v1, Index_Store_Tag_I)
 377 
 378         
 379 
 380 
 381         la      k0, 1f
 382         lui     k1, 0x2000
 383         or      k0, k1, k0
 384         xor     k0, k1, k0
 385         jr      k0
 386         nop
 387 1:
 388         
 389 
 390 
 391 
 392         jal     size_d_cache    
 393         nop
 394 
 395 
 396         li      a0, KSEG0
 397         cacheop(a0, v0, v1, Index_Store_Tag_D)
 398 
 399         jr      t8
 400         nop
 401 
 402         .end    l1_init
 403         .set    reorder
 404 
 405 
 406 
 407 
 408 
 409 
 410 
 411 
 412 
 413 
 414 
 415 
 416 LEAF(set_other_config)
 417         .set noreorder
 418 
 419         
 420         mfc0    t0, CP0_CACHEERR, 0
 421         li      t1, 0x4
 422         or      t0, t1
 423         mtc0    t0, CP0_CACHEERR, 0
 424 
 425         
 426         mfc0    t0, CP0_CACHEERR, 1
 427         li      t1, 0x4
 428         or      t0, t1
 429         mtc0    t0, CP0_CACHEERR, 1
 430 
 431         
 432         mfc0    t0, CP0_CACHEERR, 2
 433         li      t1, 0x4
 434         or      t0, t1
 435         mtc0    t0, CP0_CACHEERR, 2
 436 
 437         jr      ra
 438         nop
 439         .set reorder
 440 END(set_other_config)
 441 
 442 
 443 
 444 
 445 
 446 
 447 
 448 
 449 
 450 
 451 
 452 
 453 LEAF(set_branch_pred)
 454         .set noreorder
 455         mfc0    t0, CP0_BRCM_MODE
 456         li      t1, ~(CP0_BRCM_MODE_BrPRED_MASK | CP0_BRCM_MODE_BrHIST_MASK )
 457         and     t0, t0, t1
 458 
 459         
 460         li      t1, BRCM_BrPRED_BHT_ENABLE
 461         sll     t1, CP0_BRCM_MODE_BrPRED_SHIFT
 462         or      t0, t0, t1
 463 
 464         
 465         li      t1, 8
 466         sll     t1, CP0_BRCM_MODE_BrHIST_SHIFT
 467         or      t0, t0, t1
 468 
 469         mtc0    t0, CP0_BRCM_MODE
 470         jr      ra
 471         nop
 472         .set    reorder
 473 END(set_branch_pred)
 474 
 475 
 476 
 477 
 478 
 479 
 480 
 481 
 482 
 483 
 484 LEAF(set_luc)
 485         .set noreorder
 486         mfc0    t0, CP0_BRCM_MODE
 487         li      t1, ~(CP0_BRCM_MODE_Luc_MASK)
 488         and     t0, t0, t1
 489 
 490         
 491         ori     t0, t0, CP0_BRCM_MODE_Luc_MASK
 492 
 493         mtc0    t0, CP0_BRCM_MODE
 494         jr      ra
 495         nop
 496         .set    reorder
 497 END(set_luc)
 498 
 499 
 500 
 501 
 502 
 503 
 504 
 505 
 506 
 507 LEAF(set_cwf_tse)
 508         .set noreorder
 509         mfc0    t0, CP0_BRCM_CONFIG0
 510         li      t1, (CP0_BRCM_CONFIG0_CWF_MASK | CP0_BRCM_CONFIG0_TSE_MASK)
 511         or      t0, t0, t1
 512 
 513         mtc0    t0, CP0_BRCM_CONFIG0
 514         jr      ra
 515         nop
 516         .set    reorder
 517 END(set_cwf_tse)
 518 
 519 
 520 
 521 
 522 
 523 
 524 
 525 
 526 
 527 
 528 
 529 LEAF(set_clock_ratio)
 530         .set noreorder
 531 
 532         mfc0    t0, CP0_BRCM_MODE
 533         li      t1, ~(CP0_BRCM_MODE_SET_MASK | CP0_BRCM_MODE_ClkRATIO_MASK)
 534         and     t0, t0, t1
 535         li      t1, CP0_BRCM_MODE_SET_MASK
 536         or      t0, t0, t1
 537         or      t0, t0, a0
 538         mtc0    t0, CP0_BRCM_MODE
 539         jr      ra
 540         nop
 541         .set    reorder
 542 END(set_clock_ratio)
 543 
 544 
 545 
 546 
 547 
 548 
 549 
 550 
 551 LEAF(set_zephyr)
 552         .set    noreorder
 553 
 554         
 555         li      t0, 0x5a455048
 556         .word   0x4088b00f      
 557 
 558         .word   0x4008b008      
 559         li      t1, 0x09008000  
 560         or      t0, t0, t1
 561         .word   0x4088b008      
 562         sync
 563 
 564         
 565         li      t0, 0x0
 566         .word   0x4088b00f      
 567 
 568 
 569         jr      ra
 570         nop
 571         .set reorder
 572 
 573 END(set_zephyr)
 574 
 575 
 576 
 577 
 578 
 579 
 580 
 581 
 582 
 583 
 584 
 585 
 586 LEAF(set_llmb)
 587         .set noreorder
 588 
 589         li      t2, 0x90000000 | BRCM_ZSC_ALL_REGS_SELECT | BRCM_ZSC_CONFIG_REG
 590         sync
 591         cache   0x7, 0x0(t2)
 592         sync
 593         mfc0    t0, CP0_D_SEC_CACHE_DATA_LO
 594         li      t1, ~(BRCM_ZSC_CONFIG_LMB1En | BRCM_ZSC_CONFIG_LMB0En)
 595         and     t0, t0, t1
 596 
 597         beqz    a0, svlmb
 598         nop
 599 
 600 enable_lmb:
 601         li      t1, (BRCM_ZSC_CONFIG_LMB1En | BRCM_ZSC_CONFIG_LMB0En)
 602         or      t0, t0, t1
 603 
 604 svlmb:
 605         mtc0    t0, CP0_D_SEC_CACHE_DATA_LO
 606         sync
 607         cache   0xb, 0x0(t2)
 608         sync
 609 
 610         jr      ra
 611         nop
 612         .set reorder
 613 
 614 END(set_llmb)
 615 
 616 
 617 
 618 
 619 
 620 
 621 
 622 
 623 
 624 
 625         .globl  core_init
 626         .ent    core_init
 627         .set    noreorder
 628 core_init:
 629         move    t8, ra
 630 
 631         
 632         bal     set_zephyr
 633         nop
 634 
 635         
 636         li      a0, 1
 637         bal     set_llmb
 638         nop
 639 
 640         
 641         bal     set_branch_pred
 642         nop
 643 
 644         
 645         bal     set_luc
 646         nop
 647 
 648         
 649         bal     set_cwf_tse
 650         nop
 651 
 652         
 653 
 654 
 655 
 656         li      a0, 0
 657         bal     set_clock_ratio
 658         nop
 659 
 660         
 661         bal     set_other_config
 662         nop
 663 
 664         move    ra, t8
 665         jr      ra
 666         nop
 667 
 668         .set reorder
 669         .end    core_init
 670 
 671 
 672 
 673 
 674 
 675 
 676 
 677 
 678 
 679 #define RESET_CALL_RETURN_STACK_THIS_THREAD             (0x06<<16)
 680 #define RESET_JUMP_TARGET_BUFFER_THIS_THREAD            (0x04<<16)
 681 #define JTB_CS_CNTL_MASK                                (0xFF<<16)
 682 
 683         .globl  clear_jump_target_buffer
 684         .ent    clear_jump_target_buffer
 685         .set    noreorder
 686 clear_jump_target_buffer:
 687 
 688         mfc0    t0, $22, 2
 689         nop
 690         nop
 691 
 692         li      t1, ~JTB_CS_CNTL_MASK
 693         and     t0, t0, t1
 694         li      t2, RESET_CALL_RETURN_STACK_THIS_THREAD
 695         or      t0, t0, t2
 696         mtc0    t0, $22, 2
 697         nop
 698         nop
 699 
 700         and     t0, t0, t1
 701         li      t2, RESET_JUMP_TARGET_BUFFER_THIS_THREAD
 702         or      t0, t0, t2
 703         mtc0    t0, $22, 2
 704         nop
 705         nop
 706         jr      ra
 707         nop
 708 
 709         .end    clear_jump_target_buffer
 710         .set    reorder
 711 
 712 
 713 
 714 
 715 
 716 
 717 
 718 
 719         .globl  bmips_5xxx_init
 720         .ent    bmips_5xxx_init
 721         .set    noreorder
 722 bmips_5xxx_init:
 723 
 724         
 725         move    t7, ra
 726         move    t5, a0
 727 
 728         jal     l1_init
 729         nop
 730 
 731         jal     core_init
 732         nop
 733 
 734         jal     clear_jump_target_buffer
 735         nop
 736 
 737         mtc0    zero, CP0_CAUSE
 738 
 739         move    a0, t5
 740         jr      t7
 741         nop
 742 
 743         .end    bmips_5xxx_init
 744         .set    reorder
 745 
 746 
 747 #endif