fs_translating_port_proxy.hh revision 2521
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @file
31 * Virtual Port Object Decleration. These ports incorporate some translation
32 * into their access methods. Thus you can use one to read and write data
33 * to/from virtual addresses.
34 */
35
36#ifndef __MEM_VPORT_HH__
37#define __MEM_VPORT_HH__
38
39#include "mem/port.hh"
40#include "config/full_system.hh"
41#include "arch/vtophys.hh"
42
43
44/** A class that translates a virtual address to a physical address and then
45 * calls the above read/write functions. If an execution context is provided the
46 * address can alway be translated, If not it can only be translated if it is a
47 * simple address masking operation (such as alpha super page accesses).
48 */
49
50class VirtualPort  : public FunctionalPort
51{
52  private:
53    ExecContext *xc;
54
55  public:
56    VirtualPort(ExecContext *_xc = NULL)
57        : xc(_xc)
58    {}
59
60    /** Return true if we have an exec context. This is used to prevent someone
61     * from accidently deleting the cpus statically allocated vport.
62     * @return true if an execution context isn't valid
63     */
64    bool nullExecContext() { return xc != NULL; }
65
66    /** Write a piece of data into a virtual address.
67     * @param vaddr virtual address to write to
68     * @param data data to write
69     */
70    template <typename T>
71    inline void write(Addr vaddr, T data)
72    {
73        Addr paddr;
74        if (xc)
75            paddr = TheISA::vtophys(xc,vaddr);
76        else
77            paddr = TheISA::vtophys(vaddr);
78
79        FunctionalPort::write(paddr, data);
80    }
81
82    /** Read data from a virtual address and return it.
83     * @param vaddr address to read
84     * @return data read
85     */
86
87    template <typename T>
88    inline T read(Addr vaddr)
89    {
90        Addr paddr;
91        if (xc)
92            paddr = TheISA::vtophys(xc,vaddr);
93        else
94            paddr = TheISA::vtophys(vaddr);
95
96        return FunctionalPort::read<T>(paddr);
97    }
98
99    /** Version of readblob that translates virt->phys and deals
100      * with page boundries. */
101    virtual void readBlob(Addr addr, uint8_t *p, int size);
102
103    /** Version of writeBlob that translates virt->phys and deals
104      * with page boundries. */
105    virtual void writeBlob(Addr addr, uint8_t *p, int size);
106};
107
108#endif //__MEM_VPORT_HH__
109
110