source: rtems/bsps/powerpc/shared/start/pgtbl_setup.c @ efdb4a7

5
Last change on this file since efdb4a7 was efdb4a7, checked in by Sebastian Huber <sebastian.huber@…>, on 11/09/18 at 08:37:53

bsp/beatnik: Fix warnings

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[efdb4a7]1#include <sys/param.h>
[ea29ba6]2#include <rtems.h>
3#include <libcpu/mmu.h>
4#include <rtems/bspIo.h>
5#include <libcpu/pte121.h>
6
7/* Default setup of the page tables. This is a weak
8 * alias, so applications may easily override this
9 * default setup.
10 *
11 * NOTE: while it is possible to change the individual
12 *       mappings, the page table itself MUST be
13 *       allocated at the top of the physical memory!
14 *       bspstart.c RELIES on this.
15 *       Also, the 'setup' routine must reduce
16 *       *pmemsize by the size of the page table.
17 */
[0b8a6d7]18/* to align the pointer to the (next) page boundary */
19#define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE-1)&PAGE_MASK)
20
[ea29ba6]21
[ac7af4a]22/*
[f774fc06]23 * Authorship
24 * ----------
25 * This software was created by
26 *     Till Straumann <strauman@slac.stanford.edu>, 4/2002,
27 *         Stanford Linear Accelerator Center, Stanford University.
[ac7af4a]28 *
[f774fc06]29 * Acknowledgement of sponsorship
30 * ------------------------------
31 * This software was produced by
32 *     the Stanford Linear Accelerator Center, Stanford University,
33 *         under Contract DE-AC03-76SFO0515 with the Department of Energy.
[ac7af4a]34 *
[f774fc06]35 * Government disclaimer of liability
36 * ----------------------------------
37 * Neither the United States nor the United States Department of Energy,
38 * nor any of their employees, makes any warranty, express or implied, or
39 * assumes any legal liability or responsibility for the accuracy,
40 * completeness, or usefulness of any data, apparatus, product, or process
41 * disclosed, or represents that its use would not infringe privately owned
42 * rights.
[ac7af4a]43 *
[f774fc06]44 * Stanford disclaimer of liability
45 * --------------------------------
46 * Stanford University makes no representations or warranties, express or
47 * implied, nor assumes any liability for the use of this software.
[ac7af4a]48 *
[f774fc06]49 * Stanford disclaimer of copyright
50 * --------------------------------
51 * Stanford University, owner of the copyright, hereby disclaims its
52 * copyright and all other rights in this software.  Hence, anyone may
[ac7af4a]53 * freely use it for any purpose without restriction.
54 *
[f774fc06]55 * Maintenance of notices
56 * ----------------------
57 * In the interest of clarity regarding the origin and status of this
58 * SLAC software, this and all the preceding Stanford University notices
59 * are to remain affixed to any copy or derivative of this software made
60 * or distributed by the recipient and are to be affixed to any copy of
61 * software made or distributed by the recipient that contains a copy or
62 * derivative of this software.
[ac7af4a]63 *
[f774fc06]64 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
[ac7af4a]65 */
[ea29ba6]66
[fb252a68]67Triv121PgTbl __BSP_default_pgtbl_setup(unsigned int *pmemsize);
68Triv121PgTbl BSP_pgtbl_setup(unsigned int *)
69  __attribute__ (( weak, alias("__BSP_default_pgtbl_setup") ));
[27e966f]70
71/* get those from the linker script.
72 * NOTE THAT THE CORRECTNESS OF THE LINKER SCRIPT IS CRUCIAL
73 */
74extern unsigned long __DATA_START__[], _etext[];
[ea29ba6]75
76Triv121PgTbl
77__BSP_default_pgtbl_setup(unsigned int *pmemsize)
78{
79Triv121PgTbl    pt;
80unsigned                ldPtSize,tmp;
81
82  /* Allocate a page table large enough to map
83   * the entire physical memory. We put the page
84   * table at the top of the physical memory.
85   */
86
87  /* get minimal size (log base 2) of PT for
88   * this board's memory
89   */
90  ldPtSize = triv121PgTblLdMinSize(*pmemsize);
91  ldPtSize++; /* double this amount -- then why? */
92
93  /* allocate the page table at the top of the physical
94   * memory - THIS IS NOT AN OPTION - bspstart.c RELIES
95   * ON THIS LAYOUT! (the size, however may be changed)
96   */
97  if ( (pt = triv121PgTblInit(*pmemsize - (1<<ldPtSize), ldPtSize)) ) {
98        /* map text and RO data read-only */
99        tmp = triv121PgTblMap(
100                                                pt,
101                                                TRIV121_121_VSID,
102                                                0,
[64f8ae4]103                                                (PAGE_ALIGN((unsigned long)_etext) - 0) >> PG_SHIFT,
[ea29ba6]104                                                0, /* WIMG */
105                                                TRIV121_PP_RO_PAGE);
106        if (TRIV121_MAP_SUCCESS != tmp) {
[6128a4a]107                printk("Unable to map page index %i; reverting to BAT0\n",
[ea29ba6]108                                tmp);
109                pt = 0;
110        } else {
111                /* map the rest (without the page table itself) RW */
112                tmp = triv121PgTblMap(
113                                                pt,
114                                                TRIV121_121_VSID,
[64f8ae4]115                                                (unsigned long)__DATA_START__,
116                                                (*pmemsize - (1<<ldPtSize) -  (unsigned long)__DATA_START__ )>> PG_SHIFT,
[ea29ba6]117                                                0, /* WIMG */
118                                                TRIV121_PP_RW_PAGE);
119                if (TRIV121_MAP_SUCCESS != tmp) {
[6128a4a]120                        printk("Unable to map page index %i; reverting to BAT0\n",
[ea29ba6]121                                        tmp);
122                        pt = 0;
123                }
124        }
125  } else {
126        printk("WARNING: unable to allocate page table, keeping DBAT0\n");
127  }
128  if (pt) {
129#ifdef SHOW_MORE_INIT_SETTINGS
130        printk("Setting up page table mappings; protecting text/read-only data from write access\n");
131#endif
132        /* SUCCESS; reduce available memory by size of the page table */
133        *pmemsize -= (1<<ldPtSize);
134  }
135  return pt;
136}
Note: See TracBrowser for help on using the repository browser.