summaryrefslogtreecommitdiffstats
path: root/src/usr/runtime/tce.H
blob: 487a4bf6799c87b376e65215fc713b5761efd9e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/runtime/tce.H $                                       */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013,2014              */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#ifndef __TCE_H
#define __TCE_H

#include <stdint.h>
#include <builtins.h>
#include <errl/errlentry.H>
#include <devicefw/userif.H>




struct TceEntry
{
    // TCE Table
    union
    {
        uint64_t WholeTceEntry;
        struct {
            uint64_t realPageNumber    :52;   // real page number
            uint64_t valid             :1;    // The tces is valid for IO
            uint64_t reserved          :9;    // reserved bits
            uint64_t writeAccess       :1;    // Write access allowed
            uint64_t readAccess        :1;    // Read access allowed
        };

    };
};


/** @class TceMgr
 *  @brief   Responsible for managing the TCE entries
 *
 */
    class TceMgr
    {

      private:
        /** Indicator of TCEs being intialized */
        int tceEntryInit;

        /** Pointer to the Mapped TCE Table */
        TceEntry *tceTableVaPtr;
        /** physical address of the TCE Table */
        uint64_t tceTablePhysAddr;

        //** Max number of TCE entries - via size*/
        uint64_t maxTceEntries;

        /** size of the Tce Table */
        uint64_t tceTableSize;


        /**
         * @brief Responsible for mapping the TCE Table
         *
         * @return errlHndl_t - Return error log if unsuccessful
         *
         */
        errlHndl_t mapTceTable(void);

      public:
        /**
         * @brief Constructor.  Initializes instance variables.
         * @param[in/default] i_tableAddr - Starting address of the TCE
         *         table.. Default address is TCE_TABLE_ADDR. This was added
         *         for testing TCE entries and not using the "real" table
         * @param[in/default] i_tableSize - Size of the TCE table. Default value
         *         is TCE_TABLE_SIZE
         */
        TceMgr(uint64_t i_tableAddr = TCE_TABLE_ADDR,
                uint64_t i_tableSize = TCE_TABLE_SIZE);

        /**
         * Destructor.
         * No action necessary.
         */
        ~TceMgr();

        /** Max TCE Entries for the TCE Table */
        enum
        {
            NUM_TCE_TABLE_ENTRIES   = 0x80000,       // 512k entries
        };

        enum
        {
            INVALID_TOKEN_ENTRY   = 0xFFFFFFFFFFFFFFFF,
        };



        /**
         * @brief Responsible for initalizing the TCE Table and mapping the
         *         TCEtable
         *
         * @return errlHndl_t - Return error log if unsuccessful
         *
         */
        errlHndl_t createTceTable();


        /**
         * @brief Responsible for setting up the Processors to point to the TCE
         *         table
         *
         * @return errlHndl_t - Return error log if unsuccessful
         *
         */
        errlHndl_t initTceInHdw();


        /**
         * @brief Responsible for allocating TCE Entries
         *
         * @param[in] i_startingAddress - Starting address to TCE
         * @param[in] i_size - Size of the address space
         * @param[out] startingToken - Starting Entry into the table.
         *          (this is an offset into the array based on the
         *           TCE index * PAGESIZE.  Each TCE entry maps to a
         *           pagesize of memory)
         *
         * @return errl - Return Error Handle if failed.
         *
         */
        errlHndl_t allocateTces(uint64_t i_startingAddress,
                                  uint64_t i_size,
                                  uint64_t& o_startingToken);

        /**
         * @brief Responsible for deallocating TCE Entries
         *
         * @param[in] i_startingToken - Token indicating the starting entry to
         *                              remove
         * @param[in] i_size - Size of memory space to remove TCE entries
         *                     associated
         *
         * @return errl - Return Error Handle if fatal failure occurred.
         *
         */
        errlHndl_t deallocateTces(uint64_t i_startingToken,
                                    uint64_t i_size);


    };

#endif

OpenPOWER on IntegriCloud