]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/mv/mv_machdep.c
Dtrace: enablings on defunct providers prevent providers from unregistering
[FreeBSD/FreeBSD.git] / sys / arm / mv / mv_machdep.c
1 /*-
2  * Copyright (c) 1994-1998 Mark Brinicombe.
3  * Copyright (c) 1994 Brini.
4  * All rights reserved.
5  *
6  * This code is derived from software written for Brini by Mark Brinicombe
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Brini.
19  * 4. The name of the company nor the name of the author may be used to
20  *    endorse or promote products derived from this software without specific
21  *    prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  * from: FreeBSD: //depot/projects/arm/src/sys/arm/at91/kb920x_machdep.c, rev 45
36  */
37
38 #include "opt_ddb.h"
39 #include "opt_platform.h"
40
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
43
44 #define _ARM32_BUS_DMA_PRIVATE
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/bus.h>
48
49 #include <vm/vm.h>
50 #include <vm/pmap.h>
51
52 #include <machine/bus.h>
53 #include <machine/frame.h> /* For trapframe_t, used in <machine/machdep.h> */
54 #include <machine/machdep.h>
55 #include <machine/pmap.h>
56
57 #include <arm/mv/mvreg.h>       /* XXX */
58 #include <arm/mv/mvvar.h>       /* XXX eventually this should be eliminated */
59 #include <arm/mv/mvwin.h>
60
61 #include <dev/fdt/fdt_common.h>
62
63 static int platform_mpp_init(void);
64
65 #define MPP_PIN_MAX             68
66 #define MPP_PIN_CELLS           2
67 #define MPP_PINS_PER_REG        8
68 #define MPP_SEL(pin,func)       (((func) & 0xf) <<              \
69     (((pin) % MPP_PINS_PER_REG) * 4))
70
71 static int
72 platform_mpp_init(void)
73 {
74         pcell_t pinmap[MPP_PIN_MAX * MPP_PIN_CELLS];
75         int mpp[MPP_PIN_MAX];
76         uint32_t ctrl_val, ctrl_offset;
77         pcell_t reg[4];
78         u_long start, size;
79         phandle_t node;
80         pcell_t pin_cells, *pinmap_ptr, pin_count;
81         ssize_t len;
82         int par_addr_cells, par_size_cells;
83         int tuple_size, tuples, rv, pins, i, j;
84         int mpp_pin, mpp_function;
85
86         /*
87          * Try to access the MPP node directly i.e. through /aliases/mpp.
88          */
89         if ((node = OF_finddevice("mpp")) != -1)
90                 if (fdt_is_compatible(node, "mrvl,mpp"))
91                         goto moveon;
92         /*
93          * Find the node the long way.
94          */
95         if ((node = OF_finddevice("/")) == -1)
96                 return (ENXIO);
97
98         if ((node = fdt_find_compatible(node, "simple-bus", 0)) == 0)
99                 return (ENXIO);
100
101         if ((node = fdt_find_compatible(node, "mrvl,mpp", 0)) == 0)
102                 /*
103                  * No MPP node. Fall back to how MPP got set by the
104                  * first-stage loader and try to continue booting.
105                  */
106                 return (0);
107 moveon:
108         /*
109          * Process 'reg' prop.
110          */
111         if ((rv = fdt_addrsize_cells(OF_parent(node), &par_addr_cells,
112             &par_size_cells)) != 0)
113                 return(ENXIO);
114
115         tuple_size = sizeof(pcell_t) * (par_addr_cells + par_size_cells);
116         len = OF_getprop(node, "reg", reg, sizeof(reg));
117         tuples = len / tuple_size;
118         if (tuple_size <= 0)
119                 return (EINVAL);
120
121         /*
122          * Get address/size. XXX we assume only the first 'reg' tuple is used.
123          */
124         rv = fdt_data_to_res(reg, par_addr_cells, par_size_cells,
125             &start, &size);
126         if (rv != 0)
127                 return (rv);
128         start += fdt_immr_va;
129
130         /*
131          * Process 'pin-count' and 'pin-map' props.
132          */
133         if (OF_getprop(node, "pin-count", &pin_count, sizeof(pin_count)) <= 0)
134                 return (ENXIO);
135         pin_count = fdt32_to_cpu(pin_count);
136         if (pin_count > MPP_PIN_MAX)
137                 return (ERANGE);
138
139         if (OF_getprop(node, "#pin-cells", &pin_cells, sizeof(pin_cells)) <= 0)
140                 pin_cells = MPP_PIN_CELLS;
141         pin_cells = fdt32_to_cpu(pin_cells);
142         if (pin_cells > MPP_PIN_CELLS)
143                 return (ERANGE);
144         tuple_size = sizeof(pcell_t) * pin_cells;
145
146         bzero(pinmap, sizeof(pinmap));
147         len = OF_getprop(node, "pin-map", pinmap, sizeof(pinmap));
148         if (len <= 0)
149                 return (ERANGE);
150         if (len % tuple_size)
151                 return (ERANGE);
152         pins = len / tuple_size;
153         if (pins > pin_count)
154                 return (ERANGE);
155         /*
156          * Fill out a "mpp[pin] => function" table. All pins unspecified in
157          * the 'pin-map' property are defaulted to 0 function i.e. GPIO.
158          */
159         bzero(mpp, sizeof(mpp));
160         pinmap_ptr = pinmap;
161         for (i = 0; i < pins; i++) {
162                 mpp_pin = fdt32_to_cpu(*pinmap_ptr);
163                 mpp_function = fdt32_to_cpu(*(pinmap_ptr + 1));
164                 mpp[mpp_pin] = mpp_function;
165                 pinmap_ptr += pin_cells;
166         }
167
168         /*
169          * Prepare and program MPP control register values.
170          */
171         ctrl_offset = 0;
172         for (i = 0; i < pin_count;) {
173                 ctrl_val = 0;
174
175                 for (j = 0; j < MPP_PINS_PER_REG; j++) {
176                         if (i + j == pin_count - 1)
177                                 break;
178                         ctrl_val |= MPP_SEL(i + j, mpp[i + j]);
179                 }
180                 i += MPP_PINS_PER_REG;
181                 bus_space_write_4(fdtbus_bs_tag, start, ctrl_offset,
182                     ctrl_val);
183
184 #if defined(SOC_MV_ORION)
185                 /*
186                  * Third MPP reg on Orion SoC is placed
187                  * non-linearly (with different offset).
188                  */
189                 if (i ==  (2 * MPP_PINS_PER_REG))
190                         ctrl_offset = 0x50;
191                 else
192 #endif
193                         ctrl_offset += 4;
194         }
195
196         return (0);
197 }
198
199 vm_offset_t
200 initarm_lastaddr(void)
201 {
202
203         if (fdt_immr_addr(MV_BASE) != 0)
204                 while (1);
205
206         /* Platform-specific initialisation */
207         return (fdt_immr_va - ARM_NOCACHE_KVA_SIZE);
208 }
209
210 void
211 initarm_gpio_init(void)
212 {
213
214         /*
215          * Re-initialise MPP. It is important to call this prior to using
216          * console as the physical connection can be routed via MPP.
217          */
218         if (platform_mpp_init() != 0)
219                 while (1);
220 }
221
222 void
223 initarm_late_init(void)
224 {
225         /*
226          * Re-initialise decode windows
227          */
228 #if !defined(SOC_MV_FREY)
229         if (soc_decode_win() != 0)
230                 printf("WARNING: could not re-initialise decode windows! "
231                     "Running with existing settings...\n");
232 #else
233         /* Disable watchdog and timers */
234         write_cpu_ctrl(CPU_TIMERS_BASE + CPU_TIMER_CONTROL, 0);
235 #endif
236 }
237
238 #define FDT_DEVMAP_MAX  (MV_WIN_CPU_MAX + 2)
239 static struct pmap_devmap fdt_devmap[FDT_DEVMAP_MAX] = {
240         { 0, 0, 0, 0, 0, }
241 };
242
243 static int
244 platform_sram_devmap(struct pmap_devmap *map)
245 {
246 #if !defined(SOC_MV_ARMADAXP)
247         phandle_t child, root;
248         u_long base, size;
249         /*
250          * SRAM range.
251          */
252         if ((child = OF_finddevice("/sram")) != 0)
253                 if (fdt_is_compatible(child, "mrvl,cesa-sram") ||
254                     fdt_is_compatible(child, "mrvl,scratchpad"))
255                         goto moveon;
256
257         if ((root = OF_finddevice("/")) == 0)
258                 return (ENXIO);
259
260         if ((child = fdt_find_compatible(root, "mrvl,cesa-sram", 0)) == 0 &&
261             (child = fdt_find_compatible(root, "mrvl,scratchpad", 0)) == 0)
262                         goto out;
263
264 moveon:
265         if (fdt_regsize(child, &base, &size) != 0)
266                 return (EINVAL);
267
268         map->pd_va = MV_CESA_SRAM_BASE; /* XXX */
269         map->pd_pa = base;
270         map->pd_size = size;
271         map->pd_prot = VM_PROT_READ | VM_PROT_WRITE;
272         map->pd_cache = PTE_NOCACHE;
273
274         return (0);
275 out:
276 #endif
277         return (ENOENT);
278
279 }
280
281 /*
282  * Supply a default do-nothing implementation of fdt_pci_devmap() via a weak
283  * alias.  Many Marvell platforms don't support a PCI interface, but to support
284  * those that do, we end up with a reference to this function below, in
285  * platform_devmap_init().  If "device pci" appears in the kernel config, the
286  * real implementation of this function in dev/fdt/fdt_pci.c overrides the weak
287  * alias defined here.
288  */
289 int mv_default_fdt_pci_devmap(phandle_t node, struct pmap_devmap *devmap,
290     vm_offset_t io_va, vm_offset_t mem_va);
291 int
292 mv_default_fdt_pci_devmap(phandle_t node, struct pmap_devmap *devmap,
293     vm_offset_t io_va, vm_offset_t mem_va)
294 {
295
296         return (0);
297 }
298 __weak_reference(mv_default_fdt_pci_devmap, fdt_pci_devmap);
299
300 /*
301  * XXX: When device entry in devmap has pd_size smaller than section size,
302  * system will freeze during initialization
303  */
304
305 /*
306  * Construct pmap_devmap[] with DT-derived config data.
307  */
308 int
309 platform_devmap_init(void)
310 {
311         phandle_t root, child;
312         pcell_t bank_count;
313         u_long base, size;
314         int i, num_mapped;
315
316         i = 0;
317         pmap_devmap_bootstrap_table = &fdt_devmap[0];
318
319         /*
320          * IMMR range.
321          */
322         fdt_devmap[i].pd_va = fdt_immr_va;
323         fdt_devmap[i].pd_pa = fdt_immr_pa;
324         fdt_devmap[i].pd_size = fdt_immr_size;
325         fdt_devmap[i].pd_prot = VM_PROT_READ | VM_PROT_WRITE;
326         fdt_devmap[i].pd_cache = PTE_NOCACHE;
327         i++;
328
329         /*
330          * SRAM range.
331          */
332         if (i < FDT_DEVMAP_MAX)
333                 if (platform_sram_devmap(&fdt_devmap[i]) == 0)
334                         i++;
335
336         /*
337          * PCI range(s).
338          * PCI range(s) and localbus.
339          */
340         if ((root = OF_finddevice("/")) == -1)
341                 return (ENXIO);
342         for (child = OF_child(root); child != 0; child = OF_peer(child)) {
343                 if (fdt_is_type(child, "pci") || fdt_is_type(child, "pciep")) {
344                         /*
345                          * Check space: each PCI node will consume 2 devmap
346                          * entries.
347                          */
348                         if (i + 1 >= FDT_DEVMAP_MAX)
349                                 return (ENOMEM);
350
351                         /*
352                          * XXX this should account for PCI and multiple ranges
353                          * of a given kind.
354                          */
355                         if (fdt_pci_devmap(child, &fdt_devmap[i], MV_PCI_VA_IO_BASE,
356                                     MV_PCI_VA_MEM_BASE) != 0)
357                                 return (ENXIO);
358                         i += 2;
359                 }
360
361                 if (fdt_is_compatible(child, "mrvl,lbc")) {
362                         /* Check available space */
363                         if (OF_getprop(child, "bank-count", (void *)&bank_count,
364                             sizeof(bank_count)) <= 0)
365                                 /* If no property, use default value */
366                                 bank_count = 1;
367                         else
368                                 bank_count = fdt32_to_cpu(bank_count);
369
370                         if ((i + bank_count) >= FDT_DEVMAP_MAX)
371                                 return (ENOMEM);
372
373                         /* Add all localbus ranges to device map */
374                         num_mapped = 0;
375
376                         if (fdt_localbus_devmap(child, &fdt_devmap[i],
377                             (int)bank_count, &num_mapped) != 0)
378                                 return (ENXIO);
379
380                         i += num_mapped;
381                 }
382         }
383
384         /*
385          * CESA SRAM range.
386          */
387         if ((child = OF_finddevice("sram")) != -1)
388                 if (fdt_is_compatible(child, "mrvl,cesa-sram"))
389                         goto moveon;
390
391         if ((child = fdt_find_compatible(root, "mrvl,cesa-sram", 0)) == 0)
392                 /* No CESA SRAM node. */
393                 return (0);
394 moveon:
395         if (i >= FDT_DEVMAP_MAX)
396                 return (ENOMEM);
397
398         if (fdt_regsize(child, &base, &size) != 0)
399                 return (EINVAL);
400
401         fdt_devmap[i].pd_va = MV_CESA_SRAM_BASE; /* XXX */
402         fdt_devmap[i].pd_pa = base;
403         fdt_devmap[i].pd_size = size;
404         fdt_devmap[i].pd_prot = VM_PROT_READ | VM_PROT_WRITE;
405         fdt_devmap[i].pd_cache = PTE_NOCACHE;
406
407         return (0);
408 }
409
410 struct arm32_dma_range *
411 bus_dma_get_range(void)
412 {
413
414         return (NULL);
415 }
416
417 int
418 bus_dma_get_range_nb(void)
419 {
420
421         return (0);
422 }
423
424 #if defined(CPU_MV_PJ4B)
425 #ifdef DDB
426 #include <ddb/ddb.h>
427
428 DB_SHOW_COMMAND(cp15, db_show_cp15)
429 {
430         u_int reg;
431
432         __asm __volatile("mrc p15, 0, %0, c0, c0, 0" : "=r" (reg));
433         db_printf("Cpu ID: 0x%08x\n", reg);
434         __asm __volatile("mrc p15, 0, %0, c0, c0, 1" : "=r" (reg));
435         db_printf("Current Cache Lvl ID: 0x%08x\n",reg);
436
437         __asm __volatile("mrc p15, 0, %0, c1, c0, 0" : "=r" (reg));
438         db_printf("Ctrl: 0x%08x\n",reg);
439         __asm __volatile("mrc p15, 0, %0, c1, c0, 1" : "=r" (reg));
440         db_printf("Aux Ctrl: 0x%08x\n",reg);
441
442         __asm __volatile("mrc p15, 0, %0, c0, c1, 0" : "=r" (reg));
443         db_printf("Processor Feat 0: 0x%08x\n", reg);
444         __asm __volatile("mrc p15, 0, %0, c0, c1, 1" : "=r" (reg));
445         db_printf("Processor Feat 1: 0x%08x\n", reg);
446         __asm __volatile("mrc p15, 0, %0, c0, c1, 2" : "=r" (reg));
447         db_printf("Debug Feat 0: 0x%08x\n", reg);
448         __asm __volatile("mrc p15, 0, %0, c0, c1, 3" : "=r" (reg));
449         db_printf("Auxiliary Feat 0: 0x%08x\n", reg);
450         __asm __volatile("mrc p15, 0, %0, c0, c1, 4" : "=r" (reg));
451         db_printf("Memory Model Feat 0: 0x%08x\n", reg);
452         __asm __volatile("mrc p15, 0, %0, c0, c1, 5" : "=r" (reg));
453         db_printf("Memory Model Feat 1: 0x%08x\n", reg);
454         __asm __volatile("mrc p15, 0, %0, c0, c1, 6" : "=r" (reg));
455         db_printf("Memory Model Feat 2: 0x%08x\n", reg);
456         __asm __volatile("mrc p15, 0, %0, c0, c1, 7" : "=r" (reg));
457         db_printf("Memory Model Feat 3: 0x%08x\n", reg);
458
459         __asm __volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (reg));
460         db_printf("Aux Func Modes Ctrl 0: 0x%08x\n",reg);
461         __asm __volatile("mrc p15, 1, %0, c15, c2, 1" : "=r" (reg));
462         db_printf("Aux Func Modes Ctrl 1: 0x%08x\n",reg);
463
464         __asm __volatile("mrc p15, 1, %0, c15, c12, 0" : "=r" (reg));
465         db_printf("CPU ID code extension: 0x%08x\n",reg);
466 }
467
468 DB_SHOW_COMMAND(vtop, db_show_vtop)
469 {
470         u_int reg;
471
472         if (have_addr) {
473                 __asm __volatile("mcr p15, 0, %0, c7, c8, 0" : : "r" (addr));
474                 __asm __volatile("mrc p15, 0, %0, c7, c4, 0" : "=r" (reg));
475                 db_printf("Physical address reg: 0x%08x\n",reg);
476         } else
477                 db_printf("show vtop <virt_addr>\n");
478 }
479 #endif /* DDB */
480 #endif /* CPU_MV_PJ4B */
481