atag.hh revision 7585
12381SN/A/*
212341Snikos.nikoleris@arm.com * Copyright (c) 2010 ARM Limited
38711SN/A * All rights reserved
48711SN/A *
58711SN/A * The license below extends only to copyright in the software and shall
68711SN/A * not be construed as granting a license to any other intellectual
78711SN/A * property including but not limited to intellectual property relating
88711SN/A * to a hardware implementation of the functionality of the software
98711SN/A * licensed hereunder.  You may use the software subject to the license
108711SN/A * terms below provided that you ensure that this notice is replicated
118711SN/A * unmodified and in its entirety in all distributions of the software,
128711SN/A * modified or unmodified, in source code or in binary form.
138711SN/A *
142381SN/A * Redistribution and use in source and binary forms, with or without
152381SN/A * modification, are permitted provided that the following conditions are
162381SN/A * met: redistributions of source code must retain the above copyright
172381SN/A * notice, this list of conditions and the following disclaimer;
182381SN/A * redistributions in binary form must reproduce the above copyright
192381SN/A * notice, this list of conditions and the following disclaimer in the
202381SN/A * documentation and/or other materials provided with the distribution;
212381SN/A * neither the name of the copyright holders nor the names of its
222381SN/A * contributors may be used to endorse or promote products derived from
232381SN/A * this software without specific prior written permission.
242381SN/A *
252381SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
262381SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
272381SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
282381SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
292381SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
302381SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
312381SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
322381SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
332381SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
342381SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
352381SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
362381SN/A *
372381SN/A * Authors: Ali Saidi
382381SN/A */
392665SN/A
402665SN/A#ifndef __ARCH_ARM_LINUX_ATAG_HH__
412772SN/A#define __ARCH_ARM_LINUX_ATAG_HH__
428715SN/A
438922SN/A#include <cstring>
442381SN/A#include <string>
452381SN/A#include "base/types.hh"
462381SN/A
472982SN/Aenum {
4810405Sandreas.hansson@arm.com    CoreTag   = 0x54410001,
492381SN/A    MemTag    = 0x54410002,
502381SN/A    RevTag    = 0x54410007,
5110405Sandreas.hansson@arm.com    SerialTag = 0x54410006,
5210405Sandreas.hansson@arm.com    CmdTag    = 0x54410009,
532381SN/A    NoneTag   = 0x00000000,
5412351Snikos.nikoleris@arm.com};
5511859Sandreas.hansson@arm.com
5611859Sandreas.hansson@arm.comclass AtagHeader
5710402SN/A{
5810405Sandreas.hansson@arm.com  protected:
5910405Sandreas.hansson@arm.com    uint32_t *storage;
602381SN/A    uint32_t _size;
619036SN/A
6210405Sandreas.hansson@arm.com  public:
6310405Sandreas.hansson@arm.com    /** Tag (normally starts with 'T''A' and 16 bits of number */
6410405Sandreas.hansson@arm.com    virtual uint32_t tag() = 0;
6510405Sandreas.hansson@arm.com    /** If the header should be 0 size */
669036SN/A    virtual bool null() { return false; }
6710405Sandreas.hansson@arm.com
6810405Sandreas.hansson@arm.com    uint32_t size() const { return _size; }
6910405Sandreas.hansson@arm.com
7010405Sandreas.hansson@arm.com    AtagHeader(uint32_t s)
719036SN/A        : _size(s)
7210405Sandreas.hansson@arm.com    {
732381SN/A        storage = new uint32_t[size()];
749031SN/A    }
759036SN/A
769036SN/A    virtual ~AtagHeader()
778922SN/A    {
7810405Sandreas.hansson@arm.com        delete[] storage;
7910405Sandreas.hansson@arm.com    }
809092SN/A
819715SN/A    uint32_t copyOut(uint8_t *p)
829715SN/A    {
8310713Sandreas.hansson@arm.com        storage[0] = null() ? 0 : size();
849092SN/A        storage[1] = tag();
859092SN/A        memcpy(p, storage, size() << 2);
8610405Sandreas.hansson@arm.com        return size() << 2;
8710405Sandreas.hansson@arm.com    }
8810405Sandreas.hansson@arm.com};
898922SN/A
9010888Sandreas.hansson@arm.comclass AtagCore : public AtagHeader
912381SN/A{
929036SN/A  public:
938922SN/A    static const uint32_t Size = 5;
949036SN/A    uint32_t tag() { return CoreTag; }
9510405Sandreas.hansson@arm.com
9610405Sandreas.hansson@arm.com    void flags(uint32_t i) { storage[2] = i; }
972381SN/A    void pagesize(uint32_t i) { storage[3] = i; }
9810888Sandreas.hansson@arm.com    void rootdev(uint32_t i) { storage[4] = i; }
9910888Sandreas.hansson@arm.com    AtagCore()
10010888Sandreas.hansson@arm.com        : AtagHeader(Size)
1012381SN/A    {}
1022381SN/A};
10310405Sandreas.hansson@arm.com
10410405Sandreas.hansson@arm.comclass AtagMem : public AtagHeader
10510888Sandreas.hansson@arm.com{
10610888Sandreas.hansson@arm.com  public:
1078922SN/A    static const uint32_t Size = 4;
1088922SN/A    uint32_t tag() { return MemTag; }
1098922SN/A
1108922SN/A    void memSize(uint32_t i) { storage[2] = i; }
1118948SN/A    void memStart(uint32_t i) { storage[3] = i; }
11210405Sandreas.hansson@arm.com    AtagMem()
1138948SN/A        : AtagHeader(Size)
1148975SN/A    {}
11510405Sandreas.hansson@arm.com};
1168922SN/A
1178948SN/Aclass AtagRev : public AtagHeader
11810405Sandreas.hansson@arm.com{
1198948SN/A  public:
1208975SN/A    static const uint32_t Size = 3;
12110405Sandreas.hansson@arm.com    uint32_t tag() { return RevTag; }
1228948SN/A
1238948SN/A    void rev(uint32_t i) { storage[2] = i; }
12410405Sandreas.hansson@arm.com    AtagRev()
1258948SN/A        : AtagHeader(Size)
1268922SN/A    {}
12710405Sandreas.hansson@arm.com};
1288922SN/A
1298948SN/A
13010405Sandreas.hansson@arm.comclass AtagSerial : public AtagHeader
1318948SN/A{
1328922SN/A  public:
13310405Sandreas.hansson@arm.com    static const uint32_t Size = 4;
1348922SN/A    uint32_t tag() { return SerialTag; }
1358948SN/A
13610405Sandreas.hansson@arm.com    void sn(uint64_t i) { storage[2] = (uint32_t)i; storage[3] = i >> 32; }
1379036SN/A    AtagSerial()
1389090SN/A        : AtagHeader(Size)
13910405Sandreas.hansson@arm.com    {}
1409036SN/A};
1419036SN/A
1429036SN/Aclass AtagCmdline : public AtagHeader
1439036SN/A{
14410405Sandreas.hansson@arm.com  public:
1459036SN/A    static const uint32_t Size = 3;
14610405Sandreas.hansson@arm.com    uint32_t tag() { return CmdTag; }
1479036SN/A
14810405Sandreas.hansson@arm.com    void cmdline(const std::string &s)
1499036SN/A    {
1509036SN/A        // Add one for null terminator
15110405Sandreas.hansson@arm.com        int len = s.length() + 1;
15210405Sandreas.hansson@arm.com
1539036SN/A        // 2 + ceiling(len/4)
1549036SN/A        _size = 2 + ((len + 3) >> 2);
1559036SN/A
15610405Sandreas.hansson@arm.com        delete[] storage;
15710405Sandreas.hansson@arm.com        storage = new uint32_t[size()];
15810405Sandreas.hansson@arm.com
1599036SN/A        strcpy((char*)&storage[2] , s.c_str());
1609036SN/A    }
1619036SN/A    AtagCmdline()
1629036SN/A        : AtagHeader(Size)
1639036SN/A    {}
1649036SN/A};
16510405Sandreas.hansson@arm.com
1669036SN/Aclass AtagNone : public AtagHeader
1679036SN/A{
1689036SN/A  public:
1699036SN/A    static const uint32_t Size = 2;
1709036SN/A    virtual bool null() { return true; }
1719036SN/A    uint32_t tag() { return NoneTag; }
1729036SN/A    AtagNone()
17310405Sandreas.hansson@arm.com        : AtagHeader(Size)
1749036SN/A    {}
1759036SN/A};
17610405Sandreas.hansson@arm.com/*
1779036SN/A//
1789036SN/A// example ARM Linux bootloader code
17910405Sandreas.hansson@arm.com// this example is distributed under the BSD licence
1809036SN/A// Code taken from http://www.simtec.co.uk/products/SWLINUX/files/booting_article.html
1819036SN/A///
18210405Sandreas.hansson@arm.com
1839036SN/A// list of possible tags
1849036SN/A#define ATAG_NONE       0x00000000
18510405Sandreas.hansson@arm.com#define ATAG_CORE       0x54410001
1869036SN/A#define ATAG_MEM        0x54410002
1879036SN/A#define ATAG_VIDEOTEXT  0x54410003
18810405Sandreas.hansson@arm.com#define ATAG_RAMDISK    0x54410004
1899036SN/A#define ATAG_INITRD2    0x54420005
1909036SN/A#define ATAG_SERIAL     0x54410006
19110405Sandreas.hansson@arm.com#define ATAG_REVISION   0x54410007
1929036SN/A#define ATAG_VIDEOLFB   0x54410008
1939036SN/A#define ATAG_CMDLINE    0x54410009
19410405Sandreas.hansson@arm.com
1959036SN/A// structures for each atag
1969036SN/Astruct atag_header {
19710405Sandreas.hansson@arm.com        u32 size; // length of tag in words including this header
1989036SN/A        u32 tag;  // tag type
19910405Sandreas.hansson@arm.com};
2009036SN/A
2019036SN/Astruct atag_core {
20210405Sandreas.hansson@arm.com        u32 flags;
20310713Sandreas.hansson@arm.com        u32 pagesize;
20410713Sandreas.hansson@arm.com        u32 rootdev;
2058922SN/A};
2068922SN/A
2078922SN/Astruct atag_mem {
2089716SN/A        u32     size;
2099716SN/A        u32     start;
2109716SN/A};
2119716SN/A
2129716SN/Astruct atag_videotext {
2139716SN/A        u8              x;
2149716SN/A        u8              y;
2159716SN/A        u16             video_page;
2169716SN/A        u8              video_mode;
2179716SN/A        u8              video_cols;
2189716SN/A        u16             video_ega_bx;
21910888Sandreas.hansson@arm.com        u8              video_lines;
2209716SN/A        u8              video_isvga;
2219716SN/A        u16             video_points;
2229716SN/A};
2239716SN/A
2249716SN/Astruct atag_ramdisk {
2259716SN/A        u32 flags;
22610888Sandreas.hansson@arm.com        u32 size;
22710405Sandreas.hansson@arm.com        u32 start;
2289778SN/A};
2299716SN/A
2309716SN/Astruct atag_initrd2 {
2319716SN/A        u32 start;
2329716SN/A        u32 size;
2339716SN/A};
23410713Sandreas.hansson@arm.com
23510713Sandreas.hansson@arm.comstruct atag_serialnr {
23610713Sandreas.hansson@arm.com        u32 low;
2379716SN/A        u32 high;
2389716SN/A};
2399716SN/A
2409716SN/Astruct atag_revision {
2419716SN/A        u32 rev;
24210713Sandreas.hansson@arm.com};
2439716SN/A
2449716SN/Astruct atag_videolfb {
2459716SN/A        u16             lfb_width;
2469716SN/A        u16             lfb_height;
2479716SN/A        u16             lfb_depth;
2489716SN/A        u16             lfb_linelength;
2499716SN/A        u32             lfb_base;
2509716SN/A        u32             lfb_size;
2519716SN/A        u8              red_size;
2529716SN/A        u8              red_pos;
2539716SN/A        u8              green_size;
2549716SN/A        u8              green_pos;
2559716SN/A        u8              blue_size;
2569716SN/A        u8              blue_pos;
25710888Sandreas.hansson@arm.com        u8              rsvd_size;
2584475SN/A        u8              rsvd_pos;
2598948SN/A};
26010656Sandreas.hansson@arm.com
26110656Sandreas.hansson@arm.comstruct atag_cmdline {
26210656Sandreas.hansson@arm.com        char    cmdline[1];
2638948SN/A};
26411168Sandreas.hansson@arm.com
2658948SN/Astruct atag {
2669524SN/A        struct atag_header hdr;
26712351Snikos.nikoleris@arm.com        union {
26812351Snikos.nikoleris@arm.com                struct atag_core         core;
26912351Snikos.nikoleris@arm.com                struct atag_mem          mem;
27012351Snikos.nikoleris@arm.com                struct atag_videotext    videotext;
27112351Snikos.nikoleris@arm.com                struct atag_ramdisk      ramdisk;
27212351Snikos.nikoleris@arm.com                struct atag_initrd2      initrd2;
27312351Snikos.nikoleris@arm.com                struct atag_serialnr     serialnr;
2749524SN/A                struct atag_revision     revision;
2759524SN/A                struct atag_videolfb     videolfb;
2769524SN/A                struct atag_cmdline      cmdline;
2779524SN/A        } u;
2789524SN/A};
27910402SN/A*/
28010402SN/A
28110402SN/A
28210402SN/A#endif // __ARCH_ARM_LINUX_ATAG_HH__
28310719SMarco.Balboni@ARM.com