4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * API definitions to setup MMU TLB and PTE
8 * Copyright (C) 2007 Texas Instruments, Inc.
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 #include "MMURegAcM.h"
23 #include <linux/types.h>
24 #include <linux/err.h>
26 #define MMU_BASE_VAL_MASK 0xFC00
27 #define MMU_PAGE_MAX 3
28 #define MMU_ELEMENTSIZE_MAX 3
29 #define MMU_ADDR_MASK 0xFFFFF000
30 #define MMU_TTB_MASK 0xFFFFC000
31 #define MMU_SECTION_ADDR_MASK 0xFFF00000
32 #define MMU_SSECTION_ADDR_MASK 0xFF000000
33 #define MMU_PAGE_TABLE_MASK 0xFFFFFC00
34 #define MMU_LARGE_PAGE_MASK 0xFFFF0000
35 #define MMU_SMALL_PAGE_MASK 0xFFFFF000
37 #define MMU_LOAD_TLB 0x00000001
38 #define MMU_GFLUSH 0x60
41 * hw_mmu_page_size_t: Enumerated Type used to specify the MMU Page Size(SLSS)
43 enum hw_mmu_page_size_t {
51 * FUNCTION : mmu_set_cam_entry
55 * Identifier : base_address
56 * Type : void __iomem *
57 * Description : Base Address of instance of MMU module
59 * Identifier : page_sz
61 * Description : It indicates the page size
63 * Identifier : preserved_bit
65 * Description : It indicates the TLB entry is preserved entry
68 * Identifier : valid_bit
70 * Description : It indicates the TLB entry is valid entry or not
73 * Identifier : virtual_addr_tag
75 * Description : virtual Address
80 * Description : 0 -- No errors occurred
81 * RET_BAD_NULL_PARAM -- A Pointer Parameter
83 * RET_PARAM_OUT_OF_RANGE -- Input Parameter out
86 * PURPOSE: : Set MMU_CAM reg
88 * METHOD: : Check the Input parameters and set the CAM entry.
90 static hw_status mmu_set_cam_entry(void __iomem *base_address,
92 const u32 preserved_bit,
94 const u32 virtual_addr_tag);
97 * FUNCTION : mmu_set_ram_entry
101 * Identifier : base_address
102 * Type : void __iomem *
103 * Description : Base Address of instance of MMU module
105 * Identifier : physical_addr
107 * Description : Physical Address to which the corresponding
108 * virtual Address shouldpoint
110 * Identifier : endianism
111 * Type : hw_endianism_t
112 * Description : endianism for the given page
114 * Identifier : element_size
115 * Type : hw_element_size_t
116 * Description : The element size ( 8,16, 32 or 64 bit)
118 * Identifier : mixed_size
119 * Type : hw_mmu_mixed_size_t
120 * Description : Element Size to follow CPU or TLB
125 * Description : 0 -- No errors occurred
126 * RET_BAD_NULL_PARAM -- A Pointer Parameter
128 * RET_PARAM_OUT_OF_RANGE -- Input Parameter
131 * PURPOSE: : Set MMU_CAM reg
133 * METHOD: : Check the Input parameters and set the RAM entry.
135 static hw_status mmu_set_ram_entry(void __iomem *base_address,
136 const u32 physical_addr,
137 enum hw_endianism_t endianism,
138 enum hw_element_size_t element_size,
139 enum hw_mmu_mixed_size_t mixed_size);
143 hw_status hw_mmu_enable(void __iomem *base_address)
145 hw_status status = 0;
147 MMUMMU_CNTLMMU_ENABLE_WRITE32(base_address, HW_SET);
152 hw_status hw_mmu_disable(void __iomem *base_address)
154 hw_status status = 0;
156 MMUMMU_CNTLMMU_ENABLE_WRITE32(base_address, HW_CLEAR);
161 hw_status hw_mmu_num_locked_set(void __iomem *base_address,
162 u32 num_locked_entries)
164 hw_status status = 0;
166 MMUMMU_LOCK_BASE_VALUE_WRITE32(base_address, num_locked_entries);
171 hw_status hw_mmu_victim_num_set(void __iomem *base_address,
172 u32 victim_entry_num)
174 hw_status status = 0;
176 MMUMMU_LOCK_CURRENT_VICTIM_WRITE32(base_address, victim_entry_num);
181 hw_status hw_mmu_event_ack(void __iomem *base_address, u32 irq_mask)
183 hw_status status = 0;
185 MMUMMU_IRQSTATUS_WRITE_REGISTER32(base_address, irq_mask);
190 hw_status hw_mmu_event_disable(void __iomem *base_address, u32 irq_mask)
192 hw_status status = 0;
195 irq_reg = MMUMMU_IRQENABLE_READ_REGISTER32(base_address);
197 MMUMMU_IRQENABLE_WRITE_REGISTER32(base_address, irq_reg & ~irq_mask);
202 hw_status hw_mmu_event_enable(void __iomem *base_address, u32 irq_mask)
204 hw_status status = 0;
207 irq_reg = MMUMMU_IRQENABLE_READ_REGISTER32(base_address);
209 MMUMMU_IRQENABLE_WRITE_REGISTER32(base_address, irq_reg | irq_mask);
214 hw_status hw_mmu_event_status(void __iomem *base_address, u32 *irq_mask)
216 hw_status status = 0;
218 *irq_mask = MMUMMU_IRQSTATUS_READ_REGISTER32(base_address);
223 hw_status hw_mmu_fault_addr_read(void __iomem *base_address, u32 *addr)
225 hw_status status = 0;
227 /* read values from register */
228 *addr = MMUMMU_FAULT_AD_READ_REGISTER32(base_address);
233 hw_status hw_mmu_ttb_set(void __iomem *base_address, u32 ttb_phys_addr)
235 hw_status status = 0;
238 load_ttb = ttb_phys_addr & ~0x7FUL;
239 /* write values to register */
240 MMUMMU_TTB_WRITE_REGISTER32(base_address, load_ttb);
245 hw_status hw_mmu_twl_enable(void __iomem *base_address)
247 hw_status status = 0;
249 MMUMMU_CNTLTWL_ENABLE_WRITE32(base_address, HW_SET);
254 hw_status hw_mmu_twl_disable(void __iomem *base_address)
256 hw_status status = 0;
258 MMUMMU_CNTLTWL_ENABLE_WRITE32(base_address, HW_CLEAR);
263 hw_status hw_mmu_tlb_add(void __iomem *base_address,
268 struct hw_mmu_map_attrs_t *map_attrs,
269 s8 preserved_bit, s8 valid_bit)
271 hw_status status = 0;
273 u32 virtual_addr_tag;
274 enum hw_mmu_page_size_t mmu_pg_size;
276 /*Check the input Parameters */
278 case HW_PAGE_SIZE4KB:
279 mmu_pg_size = HW_MMU_SMALL_PAGE;
282 case HW_PAGE_SIZE64KB:
283 mmu_pg_size = HW_MMU_LARGE_PAGE;
286 case HW_PAGE_SIZE1MB:
287 mmu_pg_size = HW_MMU_SECTION;
290 case HW_PAGE_SIZE16MB:
291 mmu_pg_size = HW_MMU_SUPERSECTION;
298 lock_reg = MMUMMU_LOCK_READ_REGISTER32(base_address);
300 /* Generate the 20-bit tag from virtual address */
301 virtual_addr_tag = ((virtual_addr & MMU_ADDR_MASK) >> 12);
303 /* Write the fields in the CAM Entry Register */
304 mmu_set_cam_entry(base_address, mmu_pg_size, preserved_bit, valid_bit,
307 /* Write the different fields of the RAM Entry Register */
308 /* endianism of the page,Element Size of the page (8, 16, 32, 64 bit) */
309 mmu_set_ram_entry(base_address, physical_addr, map_attrs->endianism,
310 map_attrs->element_size, map_attrs->mixed_size);
312 /* Update the MMU Lock Register */
313 /* currentVictim between lockedBaseValue and (MMU_Entries_Number - 1) */
314 MMUMMU_LOCK_CURRENT_VICTIM_WRITE32(base_address, entry_num);
316 /* Enable loading of an entry in TLB by writing 1
317 into LD_TLB_REG register */
318 MMUMMU_LD_TLB_WRITE_REGISTER32(base_address, MMU_LOAD_TLB);
320 MMUMMU_LOCK_WRITE_REGISTER32(base_address, lock_reg);
325 hw_status hw_mmu_pte_set(const u32 pg_tbl_va,
328 u32 page_sz, struct hw_mmu_map_attrs_t *map_attrs)
330 hw_status status = 0;
331 u32 pte_addr, pte_val;
335 case HW_PAGE_SIZE4KB:
336 pte_addr = hw_mmu_pte_addr_l2(pg_tbl_va,
338 MMU_SMALL_PAGE_MASK);
340 ((physical_addr & MMU_SMALL_PAGE_MASK) |
341 (map_attrs->endianism << 9) | (map_attrs->
343 (map_attrs->mixed_size << 11) | 2);
346 case HW_PAGE_SIZE64KB:
348 pte_addr = hw_mmu_pte_addr_l2(pg_tbl_va,
350 MMU_LARGE_PAGE_MASK);
352 ((physical_addr & MMU_LARGE_PAGE_MASK) |
353 (map_attrs->endianism << 9) | (map_attrs->
355 (map_attrs->mixed_size << 11) | 1);
358 case HW_PAGE_SIZE1MB:
359 pte_addr = hw_mmu_pte_addr_l1(pg_tbl_va,
361 MMU_SECTION_ADDR_MASK);
363 ((((physical_addr & MMU_SECTION_ADDR_MASK) |
364 (map_attrs->endianism << 15) | (map_attrs->
365 element_size << 10) |
366 (map_attrs->mixed_size << 17)) & ~0x40000) | 0x2);
369 case HW_PAGE_SIZE16MB:
371 pte_addr = hw_mmu_pte_addr_l1(pg_tbl_va,
373 MMU_SSECTION_ADDR_MASK);
375 (((physical_addr & MMU_SSECTION_ADDR_MASK) |
376 (map_attrs->endianism << 15) | (map_attrs->
377 element_size << 10) |
378 (map_attrs->mixed_size << 17)
382 case HW_MMU_COARSE_PAGE_SIZE:
383 pte_addr = hw_mmu_pte_addr_l1(pg_tbl_va,
385 MMU_SECTION_ADDR_MASK);
386 pte_val = (physical_addr & MMU_PAGE_TABLE_MASK) | 1;
393 while (--num_entries >= 0)
394 ((u32 *) pte_addr)[num_entries] = pte_val;
399 hw_status hw_mmu_pte_clear(const u32 pg_tbl_va, u32 virtual_addr, u32 page_size)
401 hw_status status = 0;
406 case HW_PAGE_SIZE4KB:
407 pte_addr = hw_mmu_pte_addr_l2(pg_tbl_va,
409 MMU_SMALL_PAGE_MASK);
412 case HW_PAGE_SIZE64KB:
414 pte_addr = hw_mmu_pte_addr_l2(pg_tbl_va,
416 MMU_LARGE_PAGE_MASK);
419 case HW_PAGE_SIZE1MB:
420 case HW_MMU_COARSE_PAGE_SIZE:
421 pte_addr = hw_mmu_pte_addr_l1(pg_tbl_va,
423 MMU_SECTION_ADDR_MASK);
426 case HW_PAGE_SIZE16MB:
428 pte_addr = hw_mmu_pte_addr_l1(pg_tbl_va,
430 MMU_SSECTION_ADDR_MASK);
437 while (--num_entries >= 0)
438 ((u32 *) pte_addr)[num_entries] = 0;
443 /* mmu_set_cam_entry */
444 static hw_status mmu_set_cam_entry(void __iomem *base_address,
446 const u32 preserved_bit,
448 const u32 virtual_addr_tag)
450 hw_status status = 0;
453 mmu_cam_reg = (virtual_addr_tag << 12);
454 mmu_cam_reg = (mmu_cam_reg) | (page_sz) | (valid_bit << 2) |
455 (preserved_bit << 3);
457 /* write values to register */
458 MMUMMU_CAM_WRITE_REGISTER32(base_address, mmu_cam_reg);
463 /* mmu_set_ram_entry */
464 static hw_status mmu_set_ram_entry(void __iomem *base_address,
465 const u32 physical_addr,
466 enum hw_endianism_t endianism,
467 enum hw_element_size_t element_size,
468 enum hw_mmu_mixed_size_t mixed_size)
470 hw_status status = 0;
473 mmu_ram_reg = (physical_addr & MMU_ADDR_MASK);
474 mmu_ram_reg = (mmu_ram_reg) | ((endianism << 9) | (element_size << 7) |
477 /* write values to register */
478 MMUMMU_RAM_WRITE_REGISTER32(base_address, mmu_ram_reg);
484 void hw_mmu_tlb_flush_all(void __iomem *base)
486 __raw_writel(1, base + MMU_GFLUSH);