fsl_law.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright 2008 Freescale Semiconductor, Inc.
  3. *
  4. * (C) Copyright 2000
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <asm/fsl_law.h>
  27. #include <asm/io.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. #define LAWAR_EN 0x80000000
  30. /* number of LAWs in the hw implementation */
  31. #if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
  32. defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555)
  33. #define FSL_HW_NUM_LAWS 8
  34. #elif defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544) || \
  35. defined(CONFIG_MPC8568) || \
  36. defined(CONFIG_MPC8641) || defined(CONFIG_MPC8610)
  37. #define FSL_HW_NUM_LAWS 10
  38. #elif defined(CONFIG_MPC8572)
  39. #define FSL_HW_NUM_LAWS 12
  40. #else
  41. #error FSL_HW_NUM_LAWS not defined for this platform
  42. #endif
  43. void set_law(u8 idx, phys_addr_t addr, enum law_size sz, enum law_trgt_if id)
  44. {
  45. volatile u32 *base = (volatile u32 *)(CFG_IMMR + 0xc08);
  46. volatile u32 *lawbar = base + 8 * idx;
  47. volatile u32 *lawar = base + 8 * idx + 2;
  48. gd->used_laws |= (1 << idx);
  49. out_be32(lawbar, addr >> 12);
  50. out_be32(lawar, LAWAR_EN | ((u32)id << 20) | (u32)sz);
  51. return ;
  52. }
  53. int set_next_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id)
  54. {
  55. u32 idx = ffz(gd->used_laws);
  56. if (idx >= FSL_HW_NUM_LAWS)
  57. return -1;
  58. set_law(idx, addr, sz, id);
  59. return idx;
  60. }
  61. int set_last_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id)
  62. {
  63. u32 idx;
  64. /* we have no LAWs free */
  65. if (gd->used_laws == -1)
  66. return -1;
  67. /* grab the last free law */
  68. idx = __ilog2(~(gd->used_laws));
  69. if (idx >= FSL_HW_NUM_LAWS)
  70. return -1;
  71. set_law(idx, addr, sz, id);
  72. return idx;
  73. }
  74. void disable_law(u8 idx)
  75. {
  76. volatile u32 *base = (volatile u32 *)(CFG_IMMR + 0xc08);
  77. volatile u32 *lawbar = base + 8 * idx;
  78. volatile u32 *lawar = base + 8 * idx + 2;
  79. gd->used_laws &= ~(1 << idx);
  80. out_be32(lawar, 0);
  81. out_be32(lawbar, 0);
  82. return;
  83. }
  84. void print_laws(void)
  85. {
  86. volatile u32 *base = (volatile u32 *)(CFG_IMMR + 0xc08);
  87. volatile u32 *lawbar = base;
  88. volatile u32 *lawar = base + 2;
  89. int i;
  90. printf("\nLocal Access Window Configuration\n");
  91. for(i = 0; i < FSL_HW_NUM_LAWS; i++) {
  92. printf("\tLAWBAR%d : 0x%08x, LAWAR%d : 0x%08x\n",
  93. i, in_be32(lawbar), i, in_be32(lawar));
  94. lawbar += 8;
  95. lawar += 8;
  96. }
  97. return;
  98. }
  99. void init_laws(void)
  100. {
  101. int i;
  102. gd->used_laws = ~((1 << FSL_HW_NUM_LAWS) - 1);
  103. for (i = 0; i < num_law_entries; i++) {
  104. if (law_table[i].index == -1)
  105. set_next_law(law_table[i].addr, law_table[i].size,
  106. law_table[i].trgt_id);
  107. else
  108. set_law(law_table[i].index, law_table[i].addr,
  109. law_table[i].size, law_table[i].trgt_id);
  110. }
  111. return ;
  112. }