1 /* This is the memory initialization functions, the function
2 * implemented below initializes each memory controller
3 * found and specified by the input grlib_mctrl_handler structure.
5 * After the memory controllers have been initialized the stack
8 * (C) Copyright 2010, 2015
9 * Daniel Hellstrom, Cobham Gaisler, daniel@gaisler.com.
11 * SPDX-License-Identifier: GPL-2.0+
19 .globl _nomem_memory_ctrl_init
20 .globl _nomem_mctrl_init, _nomem_ahbmctrl_init
21 .extern _nomem_find_apb
22 .extern _nomem_find_ahb
26 * _nomem_memory_controller_init(struct grlib_mctrl_handler *mem_handlers)
28 * Initialize AMBA devices, _nomem_amba_init() has prepared i0-i5
29 * with the AHB buses on the system.
31 * For each entry in mem_handlers find the VENDOR:DEVICE and handle it
32 * by calling the handler function pointer.
35 * i6, i7, o6, l7, l6, g3, g4, g5, g6, g7 is used by caller
36 * o7 is return address
37 * l5 reserved for this function for future use.
40 * - o0 Pointer to memory handler array
43 * - o0 Number of memory controllers found
46 * - o0 (Current AHB slave conf address)
47 * - l0 (mem handler entry address)
48 * - l1 (Return value, number of memory controllers found)
49 * - o7 (function pointer)
50 * - l0, l1, l2, l3, l4, g1, g2 (used by _nomem_ambapp_find_buses)
51 * - o0, o1, o2, o3, o4, o5 (Used as arguments)
53 * - g1 ( level 1 return address)
54 * - g2 ( level 2 return address)
57 _nomem_memory_ctrl_init:
58 /* At this point all AHB buses has been found and the I/O Areas of
59 * all AHB buses is stored in the i0-i5 registers. Max 6 buses. Next,
60 * memory controllers are found by searching all buses for matching
61 * VENDOR:DEVICE. The VENDOR:DEVICE to search for are taken from the
62 * mem_handlers array. For each match the function pointer stored in
63 * the mem_handler entry is called to handle the hardware setup.
65 mov %o7, %g1 /* Save return address */
67 mov %g0, %l1 /* The return value */
69 .L_do_one_mem_handler:
70 ld [%l0 + MH_FUNC], %o7
72 be .L_all_mctrl_handled
75 /*** Scan for memory controller ***/
77 /* Set up argments, o5 not used by _nomem_find_apb */
78 ldub [%l0 + MH_TYPE], %o5
81 ldub [%l0 + MH_INDEX], %o2
82 ld [%l0 + MH_VENDOR_DEVICE], %o1
84 /* An empty config? */
88 /* Select function (APB or AHB) */
90 bne .L_find_ahb_memctrl
93 call _nomem_find_apb /* Scan for APB slave device */
99 * REG ADR = ((iobar >> 12) & (iobar << 4) & 0xfff00) | "APB Base"
101 ld [%o3 + AMBA_APB_IOBAR_OFS], %o5
107 sethi %hi(0xfff00000), %o2
109 or %o5, %o2, %o5 /* Register base address */
111 ba .L_call_one_mem_handler
115 call _nomem_find_ahb /* Scan for AHB Slave or Master.
116 * o5 determine type. */
120 /* Call the handler function if the hardware was found
123 * o1 = Configuration address
125 * o3 = APB Base register (if APB Slave)
128 * i0-i7, l0, l1, l5, g1, g3-g7 may no be used.
130 .L_call_one_mem_handler:
133 mov %l0, %o0 /* Mem handler pointer */
134 mov %o3, %o1 /* AMBA PnP Configuration address */
135 mov %o4, %o2 /* AHB Bus index */
136 ld [%l0 + MH_FUNC], %o7 /* Get Function pointer */
138 mov %o5, %o3 /* APB Register Base Address */
140 inc %l1 /* Number of Memory controllers
143 /* Do next entry in mem_handlers */
145 ba .L_do_one_mem_handler
146 add %l0, MH_STRUCT_SIZE, %l0
148 .L_all_mctrl_handled:
149 mov %g1, %o7 /* Restore return address */
155 /* Generic Memory controller initialization routine (APB Registers)
157 * o0 = mem_handler structure pointer
158 * o1 = Configuration address
160 * o3 = APB Base register
166 ld [%o0 + MH_PRIV], %o0 /* Get Private structure */
167 ld [%o0], %o1 /* Get Reg Mask */
169 add %o0, REGS_OFS, %o0 /* Point to first reg */
181 add %o0, REGS_SIZE, %o0
188 /* No more registers to write */
194 /* Generic Memory controller initialization routine (AHB Registers)
196 * o0 = mem_handler structure pointer
197 * o1 = Configuration address of memory controller
203 _nomem_ahbmctrl_init:
204 ld [%o0 + MH_PRIV], %o0 /* Get Private structure */
206 /* Get index of AHB MBAR to get registers from */
210 /* Get Address of MBAR in PnP info */
213 add %o5, %o1, %o5 /* Address of MBAR */
215 /* Get Address of registers from PnP information
216 * Address is in AHB I/O format, i.e. relative to bus
218 * ADR = (iobar & (iobar << 16) & 0xfff00000)
219 * IOADR = (ADR >> 12) | "APB Base"
224 sethi %hi(0xfff00000), %o4
225 and %o5, %o4, %o5 /* ADR */
228 or %o5, %o4, %o3 /* IOADR in o3 */
230 ld [%o0], %o1 /* Get Reg Mask */
232 add %o0, REGS_OFS, %o0 /* Point to first reg */
244 add %o0, REGS_SIZE, %o0
251 /* No more registers to write */