summaryrefslogtreecommitdiffstats
path: root/src/include/kernel/segmentmgr.H
blob: cf1a02b1a4fb1b6c1e5f5563d11dfda072f6f0fd (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
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/include/kernel/segmentmgr.H $
//
//  IBM CONFIDENTIAL
//
//  COPYRIGHT International Business Machines Corp. 2011
//
//  p1
//
//  Object Code Only (OCO) source materials
//  Licensed Internal Code Source Materials
//  IBM HostBoot Licensed Internal Code
//
//  The source code for this program is not published or other-
//  wise divested of its trade secrets, irrespective of what has
//  been deposited with the U.S. Copyright Office.
//
//  Origin: 30
//
//  IBM_PROLOG_END
/** @file segmentmgr.H
 *  Provides definition of the SegmentManager class.
 */

#ifndef __KERNEL_SEGMENTMGR_H
#define __KERNEL_SEGMENTMGR_H

#include <kernel/task.H>

// Forward declaration.
class Segment;

/** @class SegmentManager
 *  @brief Container of Segments.  Responsible for managing the SLB.
 *
 *  @note This class is not thread-safe on its own.  Expectation is that
 *        the virtual memory manager will serialize internal operations.
 */
class SegmentManager
{
    public:
        /** Segment Identifiers */
        enum SegmentIds
        {
            /** Base Segment (0-1TB). */
            BASE_SEGMENT_ID = 0,
            /** Task Stack Segment (1-2TB). */
            STACK_SEGMENT_ID = 1,
            /** MMIO Space Segment (2-3TB). */
            MMIO_SEGMENT_ID = 2,

            MAX_SEGMENTS = 4
        };

        /**
         * Constructor.  Initializes instance variables.
         */
        SegmentManager()
            {
                for(int i = 0; i < MAX_SEGMENTS; i++)
                    iv_segments[i] = NULL;
            };
        /**
         * Destructor.
         * No action necessary.  Associated segments are owned externally,
         * such as in Singletons.
         */
        ~SegmentManager() {};

        /**
         * @brief Responsible for directing page faults to the owning segment.
         *
         * @param[in] i_task - Task causing the page fault.
         * @param[in] i_addr - Effective address accessed to cause fault.
         *
         * @return true - Page fault was successfully handled.
         *
         * If the page fault is not successfully handled the expectation is
         * that the VMM will perform appropriate action, such as killing the
         * task.
         */
        static bool handlePageFault(task_t* i_task, uint64_t i_addr);

        /**
         * @brief Adds a segment to the container.
         *
         * @param[in] i_segment - Segment object to associate to segment.
         * @param[in] i_segId - Segment identifier (which TB) to associate.
         *
         * @note Ownership of the Segment object (for freeing memory) remains
         *       with the callee.
         */
        static void addSegment(Segment* i_segment, size_t i_segId);

        /**
         * @brief Update SLB on this hardware thread with associated segments.
         */
        static void initSLB();

    private:
        /** See handlePageFault. */
        bool _handlePageFault(task_t* i_task, uint64_t i_addr);
        /** See addSegment. */
        void _addSegment(Segment* i_segment, size_t i_segId);
        /** See initSLB. */
        void _initSLB();

        /** Array of segment objects to associated segment IDs. */
        Segment* iv_segments[MAX_SEGMENTS];
};

#endif
OpenPOWER on IntegriCloud