source: rtems/c/src/lib/libbsp/arm/altera-cyclone-v/hwlib/src/hwmgr/alt_address_space.c @ 0b03ca39

4.115
Last change on this file since 0b03ca39 was 0b03ca39, checked in by Ralf Kirchner <ralf.kirchner@…>, on 02/14/14 at 14:00:31

bsp/altera-cyclone-v: Add Alteras hwlib

Add files from Alteras hwlib

  • Property mode set to 100644
File size: 7.4 KB
Line 
1
2/******************************************************************************
3*
4* alt_address_space.c - API for the Altera SoC FPGA address space.
5*
6******************************************************************************/
7
8/******************************************************************************
9*
10* Copyright 2013 Altera Corporation. All Rights Reserved.
11*
12* Redistribution and use in source and binary forms, with or without
13* modification, are permitted provided that the following conditions are met:
14*
15* 1. Redistributions of source code must retain the above copyright notice,
16* this list of conditions and the following disclaimer.
17*
18* 2. Redistributions in binary form must reproduce the above copyright notice,
19* this list of conditions and the following disclaimer in the documentation
20* and/or other materials provided with the distribution.
21*
22* 3. The name of the author may not be used to endorse or promote products
23* derived from this software without specific prior written permission.
24*
25* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR
26* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO
28* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
30* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34* OF SUCH DAMAGE.
35*
36******************************************************************************/
37
38#include <stddef.h>
39#include "alt_address_space.h"
40#include "socal/alt_l3.h"
41#include "socal/socal.h"
42
43
44/******************************************************************************/
45ALT_STATUS_CODE alt_addr_space_remap(ALT_ADDR_SPACE_MPU_ATTR_t mpu_attr,
46                                     ALT_ADDR_SPACE_NONMPU_ATTR_t nonmpu_attr,
47                                     ALT_ADDR_SPACE_H2F_BRIDGE_ATTR_t h2f_bridge_attr,
48                                     ALT_ADDR_SPACE_LWH2F_BRIDGE_ATTR_t lwh2f_bridge_attr)
49{
50    uint32_t remap_reg_val = 0;
51
52    // Parameter checking and validation...
53    if (mpu_attr == ALT_ADDR_SPACE_MPU_ZERO_AT_BOOTROM)
54    {
55        remap_reg_val |= ALT_L3_REMAP_MPUZERO_SET(ALT_L3_REMAP_MPUZERO_E_BOOTROM);
56    }
57    else if (mpu_attr == ALT_ADDR_SPACE_MPU_ZERO_AT_OCRAM)
58    {
59        remap_reg_val |= ALT_L3_REMAP_MPUZERO_SET(ALT_L3_REMAP_MPUZERO_E_OCRAM);
60    }
61    else
62    {
63        return ALT_E_INV_OPTION;
64    }
65
66    if (nonmpu_attr == ALT_ADDR_SPACE_NONMPU_ZERO_AT_SDRAM)
67    {
68        remap_reg_val |= ALT_L3_REMAP_NONMPUZERO_SET(ALT_L3_REMAP_NONMPUZERO_E_SDRAM);
69    }
70    else if (nonmpu_attr == ALT_ADDR_SPACE_NONMPU_ZERO_AT_OCRAM)
71    {
72        remap_reg_val |= ALT_L3_REMAP_NONMPUZERO_SET(ALT_L3_REMAP_NONMPUZERO_E_OCRAM);
73    }
74    else
75    {
76        return ALT_E_INV_OPTION;
77    }
78
79    if (h2f_bridge_attr == ALT_ADDR_SPACE_H2F_INACCESSIBLE)
80    {
81        remap_reg_val |= ALT_L3_REMAP_H2F_SET(ALT_L3_REMAP_H2F_E_INVISIBLE);
82    }
83    else if (h2f_bridge_attr == ALT_ADDR_SPACE_H2F_ACCESSIBLE)
84    {
85        remap_reg_val |= ALT_L3_REMAP_H2F_SET(ALT_L3_REMAP_H2F_E_VISIBLE);
86    }
87    else
88    {
89        return ALT_E_INV_OPTION;
90    }
91
92    if (lwh2f_bridge_attr == ALT_ADDR_SPACE_LWH2F_INACCESSIBLE)
93    {
94        remap_reg_val |= ALT_L3_REMAP_LWH2F_SET(ALT_L3_REMAP_LWH2F_E_INVISIBLE);
95    }
96    else if (lwh2f_bridge_attr == ALT_ADDR_SPACE_LWH2F_ACCESSIBLE)
97    {
98        remap_reg_val |= ALT_L3_REMAP_LWH2F_SET(ALT_L3_REMAP_LWH2F_E_VISIBLE);
99    }
100    else
101    {
102        return ALT_E_INV_OPTION;
103    }
104
105    // Perform the remap.
106    alt_write_word(ALT_L3_REMAP_ADDR, remap_reg_val);
107
108    return ALT_E_SUCCESS;
109}
110
111/******************************************************************************/
112// Remap the MPU address space view of address 0 to access the SDRAM controller.
113// This is done by setting the L2 cache address filtering register start address
114// to 0 and leaving the address filtering address end address value
115// unmodified. This causes all physical addresses in the range
116// address_filter_start <= physical_address < address_filter_end to be directed
117// to the to the AXI Master Port M1 which is connected to the SDRAM
118// controller. All other addresses are directed to AXI Master Port M0 which
119// connect the MPU subsystem to the L3 interconnect.
120//
121// It is unnecessary to modify the MPU remap options in the L3 remap register
122// because those options only affect addresses in the MPU subsystem address
123// ranges that are now redirected to the SDRAM controller and never reach the L3
124// interconnect anyway.
125ALT_STATUS_CODE alt_mpu_addr_space_remap_0_to_sdram(void)
126{
127    uint32_t addr_filt_end = (alt_read_word(L2_CACHE_ADDR_FILTERING_END_ADDR) &
128                              L2_CACHE_ADDR_FILTERING_END_ADDR_MASK);
129    return alt_l2_addr_filter_cfg_set(0x0, addr_filt_end);
130}
131
132/******************************************************************************/
133// Return the L2 cache address filtering registers configuration settings in the
134// user provided start and end address range out parameters.
135ALT_STATUS_CODE alt_l2_addr_filter_cfg_get(uint32_t* addr_filt_start,
136                                           uint32_t* addr_filt_end)
137{
138    if (addr_filt_start == NULL || addr_filt_end == NULL)
139    {
140        return ALT_E_BAD_ARG;
141    }
142
143    uint32_t addr_filt_start_reg = alt_read_word(L2_CACHE_ADDR_FILTERING_START_ADDR);
144    uint32_t addr_filt_end_reg   = alt_read_word(L2_CACHE_ADDR_FILTERING_END_ADDR);
145
146    *addr_filt_start = (addr_filt_start_reg & L2_CACHE_ADDR_FILTERING_START_ADDR_MASK);
147    *addr_filt_end = (addr_filt_end_reg & L2_CACHE_ADDR_FILTERING_END_ADDR_MASK);
148    return ALT_E_SUCCESS;
149}
150
151/******************************************************************************/
152ALT_STATUS_CODE alt_l2_addr_filter_cfg_set(uint32_t addr_filt_start,
153                                           uint32_t addr_filt_end)
154{
155    // Address filtering start and end values must be 1 MB aligned.
156    if (  (addr_filt_start & ~L2_CACHE_ADDR_FILTERING_START_ADDR_MASK)
157       || (addr_filt_end & ~L2_CACHE_ADDR_FILTERING_END_ADDR_MASK)  )
158    {
159        return ALT_E_ARG_RANGE;
160    }
161
162    // While it is possible to set the address filtering end value above its
163    // reset value and thereby access a larger SDRAM address range, it is not
164    // recommended. Doing so would potentially obscure any mapped HPS to FPGA
165    // bridge address spaces and peripherals on the L3 interconnect.
166    if (addr_filt_end > L2_CACHE_ADDR_FILTERING_END_RESET)
167    {
168        return ALT_E_ARG_RANGE;
169    }
170
171    // NOTE: ARM (ARM DDI 0246F CoreLink Level 2 Cache Controller L2C-310 TRM)
172    // recommends programming the Address Filtering End Register before the
173    // Address Filtering Start Register to avoid unpredictable behavior between
174    // the two writes.
175    alt_write_word(L2_CACHE_ADDR_FILTERING_END_ADDR, addr_filt_end);
176    // It is recommended that address filtering always remain enabled.
177    addr_filt_start |= L2_CACHE_ADDR_FILTERING_ENABLE_MASK;
178    alt_write_word(L2_CACHE_ADDR_FILTERING_START_ADDR, addr_filt_start);
179
180    return ALT_E_SUCCESS;
181}
182
183/******************************************************************************/
184/******************************************************************************/
Note: See TracBrowser for help on using the repository browser.