source: rtems/bsps/powerpc/beatnik/flash/flashcfg.c

Last change on this file was 8266fb53, checked in by Sebastian Huber <sebastian.huber@…>, on 04/25/18 at 08:25:00

bsp/beatnik: Move source files to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * Authorship
3 * ----------
4 * This software ('beatnik' RTEMS BSP for MVME6100 and MVME5500) was
5 *     created by Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
6 *         Stanford Linear Accelerator Center, Stanford University.
7 *
8 * Acknowledgement of sponsorship
9 * ------------------------------
10 * The 'beatnik' BSP was produced by
11 *     the Stanford Linear Accelerator Center, Stanford University,
12 *         under Contract DE-AC03-76SFO0515 with the Department of Energy.
13 *
14 * Government disclaimer of liability
15 * ----------------------------------
16 * Neither the United States nor the United States Department of Energy,
17 * nor any of their employees, makes any warranty, express or implied, or
18 * assumes any legal liability or responsibility for the accuracy,
19 * completeness, or usefulness of any data, apparatus, product, or process
20 * disclosed, or represents that its use would not infringe privately owned
21 * rights.
22 *
23 * Stanford disclaimer of liability
24 * --------------------------------
25 * Stanford University makes no representations or warranties, express or
26 * implied, nor assumes any liability for the use of this software.
27 *
28 * Stanford disclaimer of copyright
29 * --------------------------------
30 * Stanford University, owner of the copyright, hereby disclaims its
31 * copyright and all other rights in this software.  Hence, anyone may
32 * freely use it for any purpose without restriction. 
33 *
34 * Maintenance of notices
35 * ----------------------
36 * In the interest of clarity regarding the origin and status of this
37 * SLAC software, this and all the preceding Stanford University notices
38 * are to remain affixed to any copy or derivative of this software made
39 * or distributed by the recipient and are to be affixed to any copy of
40 * software made or distributed by the recipient that contains a copy or
41 * derivative of this software.
42 *
43 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
44 */
45
46#include <bsp.h>
47#include <stdio.h>
48#include <inttypes.h>
49
50#define STATIC static
51
52#include <bsp/flashPgmPvt.h>
53
54/* MVME Board Specifica; board status reg. 2 where write-enable is controlled... */
55
56#define SYS_FLASHA_WP           (1<<5)
57#define SYS_FBOOTB_WP           (1<<3)
58#define SYS_FBA_WP_HDR          (1<<2)
59#define SYS_FBOOTB_WP_HDR       (1<<1)
60
61#define SYS_STATUS_2_REG        (1)
62
63/* Forward Declarations */
64STATIC struct bankdesc *
65bankcheck(int bank, int quiet);
66
67static int
68flash_wp(int bank, int enbl);
69
70STATIC uint32_t
71read_us_timer(void);
72
73/* Global Variables     */
74
75/* motload memory map   */
76static struct bankdesc mvme5500Flash[] = {
77        { 0, 2                   }, /* first entry gives number of entries */
78        { 0xf2000000, 0x08000000, 0x20000*2, 2, BSP_flash_vendor_intel, 0, 0, 0, },
79        { 0xff800000, 0x00800000, 0x20000*2, 2, BSP_flash_vendor_intel, 0, 0, 0, },
80};
81
82/* motload memory map */
83static struct bankdesc mvme6100Flash[] = {
84        { 0, 2                   }, /* first entry gives number of entries */
85        { 0xf4000000, 0x04000000, 0x20000*2, 2, BSP_flash_vendor_intel, 0, 0, 0, },
86        { 0xf8000000, 0x04000000, 0x20000*2, 2, BSP_flash_vendor_intel, 0, 0, 0, },
87};
88
89struct flash_bsp_ops BSP_flashBspOps = {
90        bankcheck    : bankcheck,
91        flash_wp     : flash_wp,
92        read_us_timer: read_us_timer,
93};
94
95/* set (enbl:1), clear (enbl:0) or query (enbl:-1) write protection
96 *
97 * RETURNS 0 on success, nonzero on error.
98 */
99static int
100flash_wp(int bank, int enbl)
101{
102BSP_BoardType b;
103A8            p;
104unsigned char   hwp = 0, swp;
105
106        /* validate 'bank' argument */
107        if ( !bankcheck( bank, 0 ) )
108                return -1;
109
110        switch ( (b=BSP_getBoardType()) ) {
111                default:
112                        fprintf(stderr,"Unknown board type %i\n",b);
113                        return -1;
114                       
115                case MVME5500:
116                        /* bit enables both banks; no readback of jumper available */
117                        p = (A8)(BSP_MV64x60_DEV1_BASE + SYS_STATUS_2_REG);
118                        swp = SYS_FLASHA_WP;
119                        break;
120
121                case MVME6100:
122                        {
123
124                                p = (A8)(BSP_MV64x60_DEV1_BASE + SYS_STATUS_2_REG);
125                                if ( 0 == bank ) {
126                                        hwp = SYS_FBA_WP_HDR;
127                                        swp = SYS_FLASHA_WP;
128                                } else {
129                                        hwp = SYS_FBOOTB_WP_HDR;
130                                        swp = SYS_FBOOTB_WP;
131                                }
132                                if ( enbl && (*p & hwp) ) {
133                                        fprintf(stderr,"HW write protection enabled (jumper)\n");
134                                        return -1;
135                                }
136                        }
137                        break;
138        }
139        if ( -1 == enbl ) {
140                /* query */
141                return *p & (swp | hwp);
142        } else {
143                if ( enbl ) {
144                        *p |= swp;
145                } else {
146                        *p &= ~swp;
147                }
148        }
149        return 0;
150}
151
152/* Lookup bank description in table */
153STATIC struct bankdesc *
154bankcheck(int bank, int quiet)
155{
156struct bankdesc *b;
157        switch ( BSP_getBoardType() ) {
158                case MVME5500:  b = mvme5500Flash; break;
159                case MVME6100:  b = mvme6100Flash; break;
160                default:
161                        fprintf(stderr,"Unknown/unsupported board type\n");
162                        return 0;
163        }
164        if ( bank >= b->size || bank < 0 ) {
165                if ( !quiet )
166                        fprintf(stderr,"Invalid flash bank #: %i; (too big)\n", bank);
167                return 0;
168        }
169        return b + bank + 1;
170}
171
172STATIC uint32_t read_us_timer(void)
173{
174uint32_t now, mhz;
175
176        /* we burn cycles anyways... */
177        mhz = BSP_bus_frequency/BSP_time_base_divisor/1000;
178
179        asm volatile("mftb %0":"=r"(now));
180
181        return now/mhz;
182}
Note: See TracBrowser for help on using the repository browser.