metalsvm/arch/x86/include/asm/apic.h
stefan f28fd84c68 - redesign of the apic code
- add ioapic support
- currently, all irq will forwarded to the boot processor



git-svn-id: http://svn.lfbs.rwth-aachen.de/svn/scc/trunk/MetalSVM@293 315a16e6-25f9-4109-90ae-ca3045a26c18
2010-11-29 02:39:10 +00:00

137 lines
3.2 KiB
C

/*
* Copyright 2010 Stefan Lankes, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of MetalSVM.
*/
#ifndef __ARCH_APIC_H__
#define __ARCH_APIC_H__
#include <metalsvm/stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/* MP Floating Pointer Structure */
typedef struct {
uint32_t signature;
uint32_t mp_config;
uint8_t length;
uint8_t version;
uint8_t checksum;
uint8_t features[5];
} __attribute__ ((packed)) apic_mp_t;
/* MP Configuration Table */
typedef struct {
uint32_t signature;
uint16_t length;
uint8_t revision;
uint8_t checksum;
uint8_t oem_id[8];
uint8_t product_id[12];
uint32_t oem_table;
uint16_t oem_table_size;
uint16_t entry_count;
uint32_t lapic;
uint16_t extended_table_length;
uint8_t extended_table_checksum;
} __attribute__ ((packed)) apic_config_table_t;
/* APIC Processor Entry */
typedef struct {
uint8_t type;
uint8_t id;
uint8_t version;
uint8_t cpu_flags;
uint32_t cpu_signature;
uint32_t cpu_feature;
} __attribute__ ((packed)) apic_processor_entry_t;
/* IO APIC Entry */
typedef struct {
uint8_t type;
uint8_t id;
uint8_t version;
uint8_t enabled;
uint32_t addr;
} __attribute__ ((packed)) apic_io_entry_t;
/* Bus Entry */
typedef struct {
uint8_t type;
uint8_t bus_id;
char name[6];
} __attribute__ ((packed)) apic_bus_entry_t;
/* I/O Interrupt Assignment Entry */
typedef struct {
uint8_t type; // type = 3
uint8_t itype; // interrupt type
uint16_t flags; // flags , PO and EL
uint8_t src_bus; // source bus id
uint8_t src_irq; // source interrupt (from the old bus)
uint8_t dest_apic; // who it gets sent to 0xFF == all
uint8_t dest_intin; // which pin it gets sent to on the IO APIC
} __attribute__ ((packed)) apic_ioirq_entry_t;
typedef struct {
union {
struct {
uint32_t vector : 8,
delivery_mode : 3, /* 000: FIXED
* 001: lowest prio
* 111: ExtINT
*/
dest_mode : 1, /* 0: physical, 1: logical */
delivery_status : 1,
polarity : 1,
irr : 1,
trigger : 1, /* 0: edge, 1: level */
mask : 1, /* 0: enabled, 1: disabled */
__reserved_2 : 15;
} bitfield;
uint32_t whole;
} lower;
union {
struct {
uint32_t __reserved_1 : 24,
physical_dest : 4,
__reserved_2 : 4;
} physical;
struct {
uint32_t __reserved_1 : 24,
logical_dest : 8;
} logical;
uint32_t upper;
} dest;
} __attribute__ ((packed)) ioapic_route_t;
int apic_init(void);
void apic_eoi(void);
uint32_t apic_cpu_id(void);
int apic_calibration(void);
int has_apic(void);
int apic_is_enabled(void);
int ioapic_inton(uint8_t irq, uint8_t apicid);
int ioapic_intoff(uint8_t irq, uint8_t apicid);
#ifdef __cplusplus
}
#endif
#endif