1/* 2 * Copyright (c) 2014 Advanced Micro Devices, Inc. 3 * Copyright (c) 2003 The Regents of The University of Michigan 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * Authors: Steve Reinhardt 30 */ 31 32/** 33 * @file 34 * Declarations of a non-full system Page Table. 35 */ 36 37#ifndef __MEM_PAGE_TABLE_HH__ 38#define __MEM_PAGE_TABLE_HH__ 39 40#include <string> 41#include <unordered_map> 42 43#include "base/intmath.hh" 44#include "base/types.hh" 45#include "mem/request.hh" 46#include "sim/serialize.hh" 47 48class ThreadContext; 49 50class EmulationPageTable : public Serializable 51{ 52 public: 53 struct Entry 54 { 55 Addr paddr; 56 uint64_t flags; 57 58 Entry(Addr paddr, uint64_t flags) : paddr(paddr), flags(flags) {} 59 Entry() {} 60 }; 61 62 protected: 63 typedef std::unordered_map<Addr, Entry> PTable; 64 typedef PTable::iterator PTableItr; 65 PTable pTable; 66 67 const Addr pageSize; 68 const Addr offsetMask; 69 70 const uint64_t _pid; 71 const std::string _name; 72 73 public: 74 75 EmulationPageTable( 76 const std::string &__name, uint64_t _pid, Addr _pageSize) : 77 pageSize(_pageSize), offsetMask(mask(floorLog2(_pageSize))), 78 _pid(_pid), _name(__name) 79 { 80 assert(isPowerOf2(pageSize)); 81 } 82 83 uint64_t pid() const { return _pid; }; 84 85 virtual ~EmulationPageTable() {}; 86 87 /* generic page table mapping flags 88 * unset | set 89 * bit 0 - no-clobber | clobber 90 * bit 2 - cacheable | uncacheable 91 * bit 3 - read-write | read-only 92 */ 93 enum MappingFlags : uint32_t { 94 Clobber = 1, 95 Uncacheable = 4, 96 ReadOnly = 8, 97 }; 98 99 virtual void initState(ThreadContext* tc) {}; 100 101 // for DPRINTF compatibility 102 const std::string name() const { return _name; } 103 104 Addr pageAlign(Addr a) { return (a & ~offsetMask); } 105 Addr pageOffset(Addr a) { return (a & offsetMask); } 106 107 /** 108 * Maps a virtual memory region to a physical memory region. 109 * @param vaddr The starting virtual address of the region. 110 * @param paddr The starting physical address where the region is mapped. 111 * @param size The length of the region. 112 * @param flags Generic mapping flags that can be set by or-ing values 113 * from MappingFlags enum. 114 */ 115 virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags = 0); 116 virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr); 117 virtual void unmap(Addr vaddr, int64_t size); 118 119 /** 120 * Check if any pages in a region are already allocated 121 * @param vaddr The starting virtual address of the region. 122 * @param size The length of the region. 123 * @return True if no pages in the region are mapped. 124 */ 125 virtual bool isUnmapped(Addr vaddr, int64_t size); 126 127 /** 128 * Lookup function 129 * @param vaddr The virtual address. 130 * @return The page table entry corresponding to vaddr. 131 */ 132 const Entry *lookup(Addr vaddr); 133 134 /** 135 * Translate function 136 * @param vaddr The virtual address. 137 * @param paddr Physical address from translation. 138 * @return True if translation exists 139 */ 140 bool translate(Addr vaddr, Addr &paddr); 141 142 /** 143 * Simplified translate function (just check for translation) 144 * @param vaddr The virtual address. 145 * @return True if translation exists 146 */ 147 bool translate(Addr vaddr) { Addr dummy; return translate(vaddr, dummy); } 148 149 /** 150 * Perform a translation on the memory request, fills in paddr 151 * field of req. 152 * @param req The memory request. 153 */
| 1/* 2 * Copyright (c) 2014 Advanced Micro Devices, Inc. 3 * Copyright (c) 2003 The Regents of The University of Michigan 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * Authors: Steve Reinhardt 30 */ 31 32/** 33 * @file 34 * Declarations of a non-full system Page Table. 35 */ 36 37#ifndef __MEM_PAGE_TABLE_HH__ 38#define __MEM_PAGE_TABLE_HH__ 39 40#include <string> 41#include <unordered_map> 42 43#include "base/intmath.hh" 44#include "base/types.hh" 45#include "mem/request.hh" 46#include "sim/serialize.hh" 47 48class ThreadContext; 49 50class EmulationPageTable : public Serializable 51{ 52 public: 53 struct Entry 54 { 55 Addr paddr; 56 uint64_t flags; 57 58 Entry(Addr paddr, uint64_t flags) : paddr(paddr), flags(flags) {} 59 Entry() {} 60 }; 61 62 protected: 63 typedef std::unordered_map<Addr, Entry> PTable; 64 typedef PTable::iterator PTableItr; 65 PTable pTable; 66 67 const Addr pageSize; 68 const Addr offsetMask; 69 70 const uint64_t _pid; 71 const std::string _name; 72 73 public: 74 75 EmulationPageTable( 76 const std::string &__name, uint64_t _pid, Addr _pageSize) : 77 pageSize(_pageSize), offsetMask(mask(floorLog2(_pageSize))), 78 _pid(_pid), _name(__name) 79 { 80 assert(isPowerOf2(pageSize)); 81 } 82 83 uint64_t pid() const { return _pid; }; 84 85 virtual ~EmulationPageTable() {}; 86 87 /* generic page table mapping flags 88 * unset | set 89 * bit 0 - no-clobber | clobber 90 * bit 2 - cacheable | uncacheable 91 * bit 3 - read-write | read-only 92 */ 93 enum MappingFlags : uint32_t { 94 Clobber = 1, 95 Uncacheable = 4, 96 ReadOnly = 8, 97 }; 98 99 virtual void initState(ThreadContext* tc) {}; 100 101 // for DPRINTF compatibility 102 const std::string name() const { return _name; } 103 104 Addr pageAlign(Addr a) { return (a & ~offsetMask); } 105 Addr pageOffset(Addr a) { return (a & offsetMask); } 106 107 /** 108 * Maps a virtual memory region to a physical memory region. 109 * @param vaddr The starting virtual address of the region. 110 * @param paddr The starting physical address where the region is mapped. 111 * @param size The length of the region. 112 * @param flags Generic mapping flags that can be set by or-ing values 113 * from MappingFlags enum. 114 */ 115 virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags = 0); 116 virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr); 117 virtual void unmap(Addr vaddr, int64_t size); 118 119 /** 120 * Check if any pages in a region are already allocated 121 * @param vaddr The starting virtual address of the region. 122 * @param size The length of the region. 123 * @return True if no pages in the region are mapped. 124 */ 125 virtual bool isUnmapped(Addr vaddr, int64_t size); 126 127 /** 128 * Lookup function 129 * @param vaddr The virtual address. 130 * @return The page table entry corresponding to vaddr. 131 */ 132 const Entry *lookup(Addr vaddr); 133 134 /** 135 * Translate function 136 * @param vaddr The virtual address. 137 * @param paddr Physical address from translation. 138 * @return True if translation exists 139 */ 140 bool translate(Addr vaddr, Addr &paddr); 141 142 /** 143 * Simplified translate function (just check for translation) 144 * @param vaddr The virtual address. 145 * @return True if translation exists 146 */ 147 bool translate(Addr vaddr) { Addr dummy; return translate(vaddr, dummy); } 148 149 /** 150 * Perform a translation on the memory request, fills in paddr 151 * field of req. 152 * @param req The memory request. 153 */
|