2004-09-16 02:02:19 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2007-10-16 02:07:52 +04:00
|
|
|
// $Id: apic.h,v 1.36 2007-10-15 22:07:52 sshwarts Exp $
|
2005-03-19 23:44:01 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-10-16 02:07:52 +04:00
|
|
|
// Copyright (c) 2002 Zwane Mwaikambo, Stanislav Shwartsman
|
2004-09-16 02:02:19 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2005-03-19 23:44:01 +03:00
|
|
|
//
|
2004-09-16 02:02:19 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef BX_CPU_APIC_H
|
|
|
|
# define BX_CPU_APIC_H 1
|
|
|
|
|
2005-04-10 23:42:48 +04:00
|
|
|
#if BX_CPU_LEVEL == 6 && BX_SUPPORT_SSE >= 2
|
2006-01-10 09:13:26 +03:00
|
|
|
#define BX_IMPLEMENT_XAPIC 1
|
|
|
|
#endif
|
|
|
|
|
2004-09-22 00:19:19 +04:00
|
|
|
#if BX_SUPPORT_APIC
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
#define APIC_LEVEL_TRIGGERED 1
|
|
|
|
#define APIC_EDGE_TRIGGERED 0
|
2005-12-26 22:42:09 +03:00
|
|
|
|
2004-09-16 02:02:19 +04:00
|
|
|
class BOCHSAPI bx_generic_apic_c : public logfunctions {
|
|
|
|
protected:
|
2006-03-02 01:32:24 +03:00
|
|
|
bx_phy_address base_addr;
|
2004-09-16 02:02:19 +04:00
|
|
|
Bit8u id;
|
|
|
|
#define APIC_UNKNOWN_ID 0xff
|
|
|
|
public:
|
2006-03-07 01:03:16 +03:00
|
|
|
bx_generic_apic_c(bx_phy_address base);
|
2006-03-02 01:32:24 +03:00
|
|
|
virtual ~bx_generic_apic_c() { }
|
2005-12-26 22:42:09 +03:00
|
|
|
// init is called during RESET and when an INIT message is delivered
|
2006-03-02 01:32:24 +03:00
|
|
|
virtual void init() { }
|
|
|
|
virtual void reset() { }
|
|
|
|
bx_phy_address get_base(void) const { return base_addr; }
|
|
|
|
void set_base(bx_phy_address newbase);
|
|
|
|
void set_id(Bit8u newid);
|
|
|
|
Bit8u get_id() const { return id; }
|
2006-06-05 09:39:21 +04:00
|
|
|
bx_bool is_selected(bx_phy_address addr, unsigned len);
|
2006-03-02 01:32:24 +03:00
|
|
|
void read(bx_phy_address addr, void *data, unsigned len);
|
2006-06-05 09:39:21 +04:00
|
|
|
virtual void read_aligned(bx_phy_address address, Bit32u *data) = 0;
|
|
|
|
void write(bx_phy_address address, void *value, unsigned len);
|
|
|
|
virtual void write_aligned(bx_phy_address address, Bit32u *data) = 0;
|
2004-09-16 02:02:19 +04:00
|
|
|
};
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
#ifdef BX_INCLUDE_LOCAL_APIC
|
|
|
|
|
|
|
|
#define BX_CPU_APIC(i) (&(BX_CPU(i)->local_apic))
|
|
|
|
|
|
|
|
#ifdef BX_IMPLEMENT_XAPIC
|
|
|
|
# define BX_LAPIC_VERSION_ID 0x00050014 // P4 has 6 LVT entries
|
|
|
|
#else
|
|
|
|
# define BX_LAPIC_VERSION_ID 0x00040010 // P6 has 4 LVT entries
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BX_LAPIC_BASE_ADDR 0xfee00000 // default Local APIC address
|
2006-10-03 01:49:49 +04:00
|
|
|
#define BX_NUM_LOCAL_APICS BX_SMP_PROCESSORS
|
|
|
|
#define BX_LAPIC_MAX_INTS 256
|
2004-09-16 02:02:19 +04:00
|
|
|
|
2005-04-29 22:38:35 +04:00
|
|
|
class BOCHSAPI bx_local_apic_c : public bx_generic_apic_c
|
|
|
|
{
|
2005-11-29 01:19:01 +03:00
|
|
|
Bit32u spurious_vector;
|
|
|
|
bx_bool software_enabled;
|
|
|
|
bx_bool focus_disable;
|
|
|
|
|
2005-04-29 22:38:35 +04:00
|
|
|
Bit32u task_priority; // Task priority (TPR)
|
|
|
|
Bit32u log_dest; // Logical destination (LDR)
|
|
|
|
Bit32u dest_format; // Destination format (DFR)
|
|
|
|
|
|
|
|
// ISR=in-service register. When an IRR bit is cleared, the corresponding
|
|
|
|
// bit in ISR is set.
|
2006-10-03 01:49:49 +04:00
|
|
|
Bit8u isr[BX_LAPIC_MAX_INTS];
|
2004-09-16 02:02:19 +04:00
|
|
|
// TMR=trigger mode register. Cleared for edge-triggered interrupts
|
2005-11-29 01:19:01 +03:00
|
|
|
// and set for level-triggered interrupts. If set, local APIC must send
|
|
|
|
// EOI message to all other APICs.
|
2006-10-03 01:49:49 +04:00
|
|
|
Bit8u tmr[BX_LAPIC_MAX_INTS];
|
2005-11-29 01:19:01 +03:00
|
|
|
// IRR=interrupt request register. When an interrupt is triggered by
|
|
|
|
// the I/O APIC or another processor, it sets a bit in irr. The bit is
|
2004-09-16 02:02:19 +04:00
|
|
|
// cleared when the interrupt is acknowledged by the processor.
|
2006-10-03 01:49:49 +04:00
|
|
|
Bit8u irr[BX_LAPIC_MAX_INTS];
|
2005-04-29 22:38:35 +04:00
|
|
|
|
|
|
|
#define APIC_ERR_ILLEGAL_ADDR 0x80
|
|
|
|
#define APIC_ERR_RX_ILLEGAL_VEC 0x40
|
|
|
|
#define APIC_ERR_TX_ILLEGAL_VEC 0x20
|
|
|
|
#define APIC_ERR_RX_ACCEPT_ERR 0x08
|
|
|
|
#define APIC_ERR_TX_ACCEPT_ERR 0x04
|
|
|
|
#define APIC_ERR_RX_CHECKSUM 0x02
|
|
|
|
#define APIC_ERR_TX_CHECKSUM 0x01
|
|
|
|
|
2005-12-11 23:01:54 +03:00
|
|
|
// Error status Register (ESR)
|
|
|
|
Bit32u error_status, shadow_error_status;
|
|
|
|
|
2005-04-29 22:38:35 +04:00
|
|
|
Bit32u icr_hi; // Interrupt command register (ICR)
|
|
|
|
Bit32u icr_lo;
|
|
|
|
|
2005-04-26 23:19:58 +04:00
|
|
|
#define APIC_LVT_ENTRIES 6
|
2006-05-28 01:44:40 +04:00
|
|
|
Bit32u lvt[APIC_LVT_ENTRIES];
|
2004-09-16 02:02:19 +04:00
|
|
|
#define APIC_LVT_TIMER 0
|
|
|
|
#define APIC_LVT_THERMAL 1
|
|
|
|
#define APIC_LVT_PERFORM 2
|
|
|
|
#define APIC_LVT_LINT0 3
|
|
|
|
#define APIC_LVT_LINT1 4
|
|
|
|
#define APIC_LVT_ERROR 5
|
|
|
|
|
2005-04-29 22:38:35 +04:00
|
|
|
Bit32u timer_initial; // Initial timer count
|
|
|
|
Bit32u timer_current; // current timer count
|
|
|
|
|
|
|
|
Bit32u timer_divconf; // Timer divide configuration register
|
2006-05-23 20:42:50 +04:00
|
|
|
Bit32u timer_divide_factor;
|
2005-04-29 22:38:35 +04:00
|
|
|
|
|
|
|
// Internal timer state, not accessible from bus
|
|
|
|
bx_bool timer_active;
|
|
|
|
int timer_handle;
|
|
|
|
Bit64u ticksInitial;
|
|
|
|
|
2004-09-16 02:02:19 +04:00
|
|
|
/* APIC delivery modes */
|
|
|
|
#define APIC_DM_FIXED 0
|
|
|
|
#define APIC_DM_LOWPRI 1
|
|
|
|
#define APIC_DM_SMI 2
|
|
|
|
/* RESERVED 3 */
|
|
|
|
#define APIC_DM_NMI 4
|
|
|
|
#define APIC_DM_INIT 5
|
|
|
|
#define APIC_DM_SIPI 6
|
|
|
|
#define APIC_DM_EXTINT 7
|
|
|
|
|
2005-01-13 22:03:40 +03:00
|
|
|
BX_CPU_C *cpu;
|
2004-09-16 02:02:19 +04:00
|
|
|
|
2005-04-29 22:38:35 +04:00
|
|
|
// corresponding BX_CPU_ID for the local APIC
|
|
|
|
unsigned cpu_id;
|
2004-09-16 02:02:19 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
bx_bool INTR;
|
2005-01-13 22:03:40 +03:00
|
|
|
bx_local_apic_c(BX_CPU_C *cpu);
|
2006-10-03 01:49:49 +04:00
|
|
|
virtual ~bx_local_apic_c() { }
|
2006-03-02 01:32:24 +03:00
|
|
|
virtual void reset(void);
|
|
|
|
virtual void init(void);
|
|
|
|
void set_id(Bit8u newid); // redefine to set cpu->name
|
2006-06-05 09:39:21 +04:00
|
|
|
virtual void write_aligned(bx_phy_address addr, Bit32u *data);
|
|
|
|
virtual void read_aligned(bx_phy_address address, Bit32u *data);
|
2006-03-02 01:32:24 +03:00
|
|
|
void startup_msg(Bit32u vector);
|
2004-10-16 23:34:17 +04:00
|
|
|
// on local APIC, trigger means raise the CPU's INTR line. For now
|
2004-09-16 02:02:19 +04:00
|
|
|
// I also have to raise pc_system.INTR but that should be replaced
|
|
|
|
// with the cpu-specific INTR signals.
|
2006-05-23 20:42:50 +04:00
|
|
|
void trigger_irq(unsigned num, unsigned trigger_mode, bx_bool bypass_irr_isr = 0);
|
2006-03-02 01:32:24 +03:00
|
|
|
void untrigger_irq(unsigned num, unsigned trigger_mode);
|
|
|
|
Bit8u acknowledge_int(void); // only the local CPU should call this
|
|
|
|
int highest_priority_int(Bit8u *array);
|
2005-04-27 22:09:27 +04:00
|
|
|
void receive_EOI(Bit32u value);
|
2006-01-10 09:13:26 +03:00
|
|
|
void send_ipi(void);
|
2005-11-29 01:19:01 +03:00
|
|
|
void write_spurious_interrupt_register(Bit32u value);
|
|
|
|
void service_local_apic(void);
|
|
|
|
void print_status(void);
|
2006-01-10 09:13:26 +03:00
|
|
|
bx_bool match_logical_addr (Bit8u address);
|
2006-03-02 01:32:24 +03:00
|
|
|
bx_bool deliver(Bit8u vector, Bit8u delivery_mode, Bit8u trig_mode);
|
|
|
|
Bit8u get_tpr(void);
|
|
|
|
void set_tpr(Bit8u tpr);
|
|
|
|
Bit8u get_ppr(void);
|
|
|
|
Bit8u get_apr(void);
|
2005-12-26 22:42:09 +03:00
|
|
|
bx_bool is_focus(Bit8u vector);
|
|
|
|
static void periodic_smf(void *);
|
|
|
|
void periodic(void);
|
|
|
|
void set_divide_configuration(Bit32u value);
|
|
|
|
void set_initial_timer_count(Bit32u value);
|
2006-05-27 19:54:49 +04:00
|
|
|
void register_state(bx_param_c *parent);
|
2004-09-16 02:02:19 +04:00
|
|
|
};
|
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
#endif /* BX_INCLUDE_LOCAL_APIC */
|
|
|
|
|
2005-04-29 22:38:35 +04:00
|
|
|
// For P6 and Pentium family processors the local APIC ID feild is 4 bits.
|
2005-12-26 22:42:09 +03:00
|
|
|
#ifdef BX_IMPLEMENT_XAPIC
|
|
|
|
#define APIC_MAX_ID 0xff
|
|
|
|
#define APIC_ID_MASK 0xff
|
|
|
|
#else
|
|
|
|
#define APIC_MAX_ID 0x0f
|
|
|
|
#define APIC_ID_MASK 0x0f
|
|
|
|
#endif
|
2005-04-29 22:38:35 +04:00
|
|
|
|
2006-01-10 09:13:26 +03:00
|
|
|
int apic_bus_deliver_lowest_priority(Bit8u vector, Bit8u dest, bx_bool trig_mode, bx_bool broadcast);
|
|
|
|
int apic_bus_deliver_interrupt(Bit8u vector, Bit8u dest, Bit8u delivery_mode, Bit8u dest_mode, bx_bool level, bx_bool trig_mode);
|
|
|
|
int apic_bus_broadcast_interrupt(Bit8u vector, Bit8u delivery_mode, bx_bool trig_mode, int exclude_cpu);
|
2004-09-16 02:02:19 +04:00
|
|
|
|
|
|
|
#endif // if BX_SUPPORT_APIC
|
|
|
|
|
|
|
|
#endif
|