2007-03-03 17:01:48 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 The Hewlett-Packard Development Company
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2010-05-24 07:44:15 +02:00
|
|
|
* The license below extends only to copyright in the software and shall
|
|
|
|
* not be construed as granting a license to any other intellectual
|
|
|
|
* property including but not limited to intellectual property relating
|
|
|
|
* to a hardware implementation of the functionality of the software
|
|
|
|
* licensed hereunder. You may use the software subject to the license
|
|
|
|
* terms below provided that you ensure that this notice is replicated
|
|
|
|
* unmodified and in its entirety in all distributions of the software,
|
|
|
|
* modified or unmodified, in source code or in binary form.
|
2007-03-03 17:01:48 +01:00
|
|
|
*
|
2010-05-24 07:44:15 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
2007-03-03 17:01:48 +01:00
|
|
|
* contributors may be used to endorse or promote products derived from
|
2010-05-24 07:44:15 +02:00
|
|
|
* this software without specific prior written permission.
|
2007-03-03 17:01:48 +01:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Authors: Gabe Black
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ARCH_X86_INTERRUPTS_HH__
|
|
|
|
#define __ARCH_X86_INTERRUPTS_HH__
|
|
|
|
|
2007-09-25 02:39:56 +02:00
|
|
|
#include "arch/x86/faults.hh"
|
2008-10-12 22:45:21 +02:00
|
|
|
#include "arch/x86/intmessage.hh"
|
2010-08-24 01:14:24 +02:00
|
|
|
#include "arch/x86/regs/apic.hh"
|
2008-10-12 22:44:24 +02:00
|
|
|
#include "base/bitfield.hh"
|
2007-09-25 02:39:56 +02:00
|
|
|
#include "cpu/thread_context.hh"
|
2008-10-12 20:08:00 +02:00
|
|
|
#include "dev/io_device.hh"
|
2008-10-12 22:28:54 +02:00
|
|
|
#include "dev/x86/intdev.hh"
|
2008-10-12 18:09:56 +02:00
|
|
|
#include "params/X86LocalApic.hh"
|
|
|
|
#include "sim/eventq.hh"
|
|
|
|
|
|
|
|
class ThreadContext;
|
2009-01-26 05:29:03 +01:00
|
|
|
class BaseCPU;
|
2007-03-03 17:01:48 +01:00
|
|
|
|
2008-10-21 16:12:53 +02:00
|
|
|
namespace X86ISA {
|
2007-09-25 02:39:56 +02:00
|
|
|
|
2008-10-12 22:28:54 +02:00
|
|
|
class Interrupts : public BasicPioDevice, IntDev
|
2007-09-25 02:39:56 +02:00
|
|
|
{
|
2008-10-12 18:09:56 +02:00
|
|
|
protected:
|
2008-10-12 22:44:24 +02:00
|
|
|
// Storage for the APIC registers
|
2008-10-12 18:09:56 +02:00
|
|
|
uint32_t regs[NUM_APIC_REGS];
|
2008-10-12 22:44:24 +02:00
|
|
|
|
2008-10-13 08:28:49 +02:00
|
|
|
BitUnion32(LVTEntry)
|
|
|
|
Bitfield<7, 0> vector;
|
|
|
|
Bitfield<10, 8> deliveryMode;
|
|
|
|
Bitfield<12> status;
|
|
|
|
Bitfield<13> polarity;
|
|
|
|
Bitfield<14> remoteIRR;
|
|
|
|
Bitfield<15> trigger;
|
|
|
|
Bitfield<16> masked;
|
|
|
|
Bitfield<17> periodic;
|
|
|
|
EndBitUnion(LVTEntry)
|
|
|
|
|
2008-10-12 22:44:24 +02:00
|
|
|
/*
|
|
|
|
* Timing related stuff.
|
|
|
|
*/
|
2008-10-12 20:08:00 +02:00
|
|
|
Tick latency;
|
|
|
|
Tick clock;
|
2008-10-12 18:09:56 +02:00
|
|
|
|
|
|
|
class ApicTimerEvent : public Event
|
|
|
|
{
|
2008-10-13 08:28:49 +02:00
|
|
|
private:
|
|
|
|
Interrupts *localApic;
|
2008-10-12 18:09:56 +02:00
|
|
|
public:
|
2008-10-13 08:28:49 +02:00
|
|
|
ApicTimerEvent(Interrupts *_localApic) :
|
|
|
|
Event(), localApic(_localApic)
|
2008-10-12 18:09:56 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
void process()
|
|
|
|
{
|
2008-10-13 08:28:49 +02:00
|
|
|
assert(localApic);
|
|
|
|
if (localApic->triggerTimerInterrupt()) {
|
|
|
|
localApic->setReg(APIC_INITIAL_COUNT,
|
|
|
|
localApic->readReg(APIC_INITIAL_COUNT));
|
|
|
|
}
|
2008-10-12 18:09:56 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ApicTimerEvent apicTimerEvent;
|
|
|
|
|
2008-10-12 22:45:21 +02:00
|
|
|
/*
|
|
|
|
* A set of variables to keep track of interrupts that don't go through
|
|
|
|
* the IRR.
|
|
|
|
*/
|
|
|
|
bool pendingSmi;
|
2008-10-13 08:28:49 +02:00
|
|
|
uint8_t smiVector;
|
2008-10-12 22:45:21 +02:00
|
|
|
bool pendingNmi;
|
2008-10-13 08:28:49 +02:00
|
|
|
uint8_t nmiVector;
|
2008-10-12 22:45:21 +02:00
|
|
|
bool pendingExtInt;
|
2008-10-13 08:28:49 +02:00
|
|
|
uint8_t extIntVector;
|
2008-10-12 22:45:21 +02:00
|
|
|
bool pendingInit;
|
2008-10-13 08:28:49 +02:00
|
|
|
uint8_t initVector;
|
2009-04-19 12:01:46 +02:00
|
|
|
bool pendingStartup;
|
|
|
|
uint8_t startupVector;
|
2009-04-19 12:56:36 +02:00
|
|
|
bool startedUp;
|
2008-10-12 22:45:21 +02:00
|
|
|
|
|
|
|
// This is a quick check whether any of the above (except ExtInt) are set.
|
|
|
|
bool pendingUnmaskableInt;
|
|
|
|
|
2009-04-19 13:14:01 +02:00
|
|
|
// A count of how many IPIs are in flight.
|
|
|
|
int pendingIPIs;
|
|
|
|
|
2008-10-12 22:44:24 +02:00
|
|
|
/*
|
|
|
|
* IRR and ISR maintenance.
|
|
|
|
*/
|
|
|
|
uint8_t IRRV;
|
|
|
|
uint8_t ISRV;
|
|
|
|
|
|
|
|
int
|
|
|
|
findRegArrayMSB(ApicRegIndex base)
|
|
|
|
{
|
|
|
|
int offset = 7;
|
|
|
|
do {
|
|
|
|
if (regs[base + offset] != 0) {
|
|
|
|
return offset * 32 + findMsbSet(regs[base + offset]);
|
|
|
|
}
|
|
|
|
} while (offset--);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
updateIRRV()
|
|
|
|
{
|
|
|
|
IRRV = findRegArrayMSB(APIC_INTERRUPT_REQUEST_BASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
updateISRV()
|
|
|
|
{
|
|
|
|
ISRV = findRegArrayMSB(APIC_IN_SERVICE_BASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setRegArrayBit(ApicRegIndex base, uint8_t vector)
|
|
|
|
{
|
2009-04-19 22:47:15 +02:00
|
|
|
regs[base + (vector / 32)] |= (1 << (vector % 32));
|
2008-10-12 22:44:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
clearRegArrayBit(ApicRegIndex base, uint8_t vector)
|
|
|
|
{
|
2009-04-19 22:47:15 +02:00
|
|
|
regs[base + (vector / 32)] &= ~(1 << (vector % 32));
|
2008-10-12 22:44:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
getRegArrayBit(ApicRegIndex base, uint8_t vector)
|
|
|
|
{
|
2009-04-19 22:47:15 +02:00
|
|
|
return bits(regs[base + (vector / 32)], vector % 5);
|
2008-10-12 22:44:24 +02:00
|
|
|
}
|
|
|
|
|
2008-10-13 08:28:49 +02:00
|
|
|
void requestInterrupt(uint8_t vector, uint8_t deliveryMode, bool level);
|
|
|
|
|
2009-01-26 05:29:03 +01:00
|
|
|
BaseCPU *cpu;
|
|
|
|
|
2009-04-26 11:06:21 +02:00
|
|
|
int initialApicId;
|
|
|
|
|
2007-09-25 02:39:56 +02:00
|
|
|
public:
|
2008-10-12 22:44:24 +02:00
|
|
|
/*
|
|
|
|
* Params stuff.
|
|
|
|
*/
|
2008-10-12 18:09:56 +02:00
|
|
|
typedef X86LocalApicParams Params;
|
|
|
|
|
2009-04-19 11:16:49 +02:00
|
|
|
void setCPU(BaseCPU * newCPU);
|
2009-01-26 05:29:03 +01:00
|
|
|
|
2008-10-21 16:12:53 +02:00
|
|
|
void
|
|
|
|
setClock(Tick newClock)
|
2008-10-12 20:08:00 +02:00
|
|
|
{
|
|
|
|
clock = newClock;
|
|
|
|
}
|
|
|
|
|
2008-10-12 18:09:56 +02:00
|
|
|
const Params *
|
|
|
|
params() const
|
|
|
|
{
|
|
|
|
return dynamic_cast<const Params *>(_params);
|
|
|
|
}
|
|
|
|
|
2009-04-26 11:09:13 +02:00
|
|
|
/*
|
|
|
|
* Initialize this object by registering it with the IO APIC.
|
|
|
|
*/
|
|
|
|
void init();
|
|
|
|
|
2008-10-12 22:44:24 +02:00
|
|
|
/*
|
|
|
|
* Functions to interact with the interrupt port from IntDev.
|
|
|
|
*/
|
2008-10-12 20:08:00 +02:00
|
|
|
Tick read(PacketPtr pkt);
|
|
|
|
Tick write(PacketPtr pkt);
|
2008-10-12 22:28:54 +02:00
|
|
|
Tick recvMessage(PacketPtr pkt);
|
2009-04-19 12:54:11 +02:00
|
|
|
Tick recvResponse(PacketPtr pkt);
|
2008-10-12 20:08:00 +02:00
|
|
|
|
2008-10-13 08:28:49 +02:00
|
|
|
bool
|
|
|
|
triggerTimerInterrupt()
|
|
|
|
{
|
|
|
|
LVTEntry entry = regs[APIC_LVT_TIMER];
|
|
|
|
if (!entry.masked)
|
|
|
|
requestInterrupt(entry.vector, entry.deliveryMode, entry.trigger);
|
|
|
|
return entry.periodic;
|
|
|
|
}
|
|
|
|
|
2009-04-19 11:16:49 +02:00
|
|
|
void addressRanges(AddrRangeList &range_list);
|
|
|
|
void getIntAddrRange(AddrRangeList &range_list);
|
2008-10-12 22:28:54 +02:00
|
|
|
|
2008-10-12 22:44:24 +02:00
|
|
|
Port *getPort(const std::string &if_name, int idx = -1)
|
|
|
|
{
|
|
|
|
if (if_name == "int_port")
|
|
|
|
return intPort;
|
|
|
|
return BasicPioDevice::getPort(if_name, idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions to access and manipulate the APIC's registers.
|
|
|
|
*/
|
|
|
|
|
2008-10-12 20:08:00 +02:00
|
|
|
uint32_t readReg(ApicRegIndex miscReg);
|
|
|
|
void setReg(ApicRegIndex reg, uint32_t val);
|
2008-10-21 16:12:53 +02:00
|
|
|
void
|
|
|
|
setRegNoEffect(ApicRegIndex reg, uint32_t val)
|
2008-10-12 20:08:00 +02:00
|
|
|
{
|
|
|
|
regs[reg] = val;
|
|
|
|
}
|
2008-10-12 18:09:56 +02:00
|
|
|
|
2008-10-12 22:44:24 +02:00
|
|
|
/*
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
|
2009-04-19 11:16:49 +02:00
|
|
|
Interrupts(Params * p);
|
2007-09-25 02:39:56 +02:00
|
|
|
|
2008-10-12 22:44:24 +02:00
|
|
|
/*
|
|
|
|
* Functions for retrieving interrupts for the CPU to handle.
|
|
|
|
*/
|
|
|
|
|
2008-10-21 16:12:53 +02:00
|
|
|
bool checkInterrupts(ThreadContext *tc) const;
|
|
|
|
Fault getInterrupt(ThreadContext *tc);
|
|
|
|
void updateIntrInfo(ThreadContext *tc);
|
2008-10-12 22:44:24 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Serialization.
|
|
|
|
*/
|
|
|
|
|
2011-02-07 07:14:17 +01:00
|
|
|
virtual void serialize(std::ostream &os);
|
|
|
|
virtual void unserialize(Checkpoint *cp, const std::string §ion);
|
2007-09-25 02:39:56 +02:00
|
|
|
|
2008-10-12 22:44:24 +02:00
|
|
|
/*
|
|
|
|
* Old functions needed for compatability but which will be phased out
|
|
|
|
* eventually.
|
|
|
|
*/
|
2008-10-21 16:12:53 +02:00
|
|
|
void
|
|
|
|
post(int int_num, int index)
|
2007-09-25 02:39:56 +02:00
|
|
|
{
|
2007-10-08 02:52:36 +02:00
|
|
|
panic("Interrupts::post unimplemented!\n");
|
2007-09-25 02:39:56 +02:00
|
|
|
}
|
|
|
|
|
2008-10-21 16:12:53 +02:00
|
|
|
void
|
|
|
|
clear(int int_num, int index)
|
2007-09-25 02:39:56 +02:00
|
|
|
{
|
2008-10-12 22:44:24 +02:00
|
|
|
panic("Interrupts::clear unimplemented!\n");
|
2007-09-25 02:39:56 +02:00
|
|
|
}
|
|
|
|
|
2008-10-21 16:12:53 +02:00
|
|
|
void
|
|
|
|
clearAll()
|
2007-09-25 02:39:56 +02:00
|
|
|
{
|
2008-10-21 16:12:53 +02:00
|
|
|
panic("Interrupts::clearAll unimplemented!\n");
|
2007-09-25 02:39:56 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-10-21 16:12:53 +02:00
|
|
|
} // namespace X86ISA
|
2007-03-03 17:01:48 +01:00
|
|
|
|
|
|
|
#endif // __ARCH_X86_INTERRUPTS_HH__
|