105b261ecSmrg 205b261ecSmrg/* 305b261ecSmrg * XFree86 int10 module 405b261ecSmrg * execute BIOS int 10h calls in x86 real mode environment 505b261ecSmrg * Copyright 1999 Egbert Eich 605b261ecSmrg */ 705b261ecSmrg 805b261ecSmrg#ifndef _XF86INT10_H 905b261ecSmrg#define _XF86INT10_H 1005b261ecSmrg 1105b261ecSmrg#include <X11/Xmd.h> 1205b261ecSmrg#include <X11/Xdefs.h> 1305b261ecSmrg#include "xf86Pci.h" 1405b261ecSmrg 1505b261ecSmrg#define SEG_ADDR(x) (((x) >> 4) & 0x00F000) 1605b261ecSmrg#define SEG_OFF(x) ((x) & 0x0FFFF) 1705b261ecSmrg 1805b261ecSmrg#define SET_BIOS_SCRATCH 0x1 1905b261ecSmrg#define RESTORE_BIOS_SCRATCH 0x2 2005b261ecSmrg 2105b261ecSmrg/* int10 info structure */ 2205b261ecSmrgtypedef struct { 2305b261ecSmrg int entityIndex; 2435c4bbdfSmrg uint16_t BIOSseg; 2535c4bbdfSmrg uint16_t inb40time; 2635c4bbdfSmrg ScrnInfoPtr pScrn; 2735c4bbdfSmrg void *cpuRegs; 2835c4bbdfSmrg char *BIOSScratch; 2905b261ecSmrg int Flags; 3035c4bbdfSmrg void *private; 3135c4bbdfSmrg struct _int10Mem *mem; 3205b261ecSmrg int num; 3305b261ecSmrg int ax; 3405b261ecSmrg int bx; 3505b261ecSmrg int cx; 3605b261ecSmrg int dx; 3705b261ecSmrg int si; 3805b261ecSmrg int di; 3905b261ecSmrg int es; 4005b261ecSmrg int bp; 4105b261ecSmrg int flags; 4205b261ecSmrg int stackseg; 434642e01fSmrg struct pci_device *dev; 4435c4bbdfSmrg struct pci_io_handle *io; 4505b261ecSmrg} xf86Int10InfoRec, *xf86Int10InfoPtr; 4605b261ecSmrg 4705b261ecSmrgtypedef struct _int10Mem { 4835c4bbdfSmrg uint8_t (*rb) (xf86Int10InfoPtr, int); 4935c4bbdfSmrg uint16_t (*rw) (xf86Int10InfoPtr, int); 5035c4bbdfSmrg uint32_t (*rl) (xf86Int10InfoPtr, int); 5135c4bbdfSmrg void (*wb) (xf86Int10InfoPtr, int, uint8_t); 5235c4bbdfSmrg void (*ww) (xf86Int10InfoPtr, int, uint16_t); 5335c4bbdfSmrg void (*wl) (xf86Int10InfoPtr, int, uint32_t); 5405b261ecSmrg} int10MemRec, *int10MemPtr; 5505b261ecSmrg 5605b261ecSmrgtypedef struct { 5735c4bbdfSmrg uint8_t save_msr; 5835c4bbdfSmrg uint8_t save_pos102; 5935c4bbdfSmrg uint8_t save_vse; 6035c4bbdfSmrg uint8_t save_46e8; 6105b261ecSmrg} legacyVGARec, *legacyVGAPtr; 6235c4bbdfSmrg 6305b261ecSmrg/* OS dependent functions */ 646747b715Smrgextern _X_EXPORT xf86Int10InfoPtr xf86InitInt10(int entityIndex); 656747b715Smrgextern _X_EXPORT xf86Int10InfoPtr xf86ExtendedInitInt10(int entityIndex, 6635c4bbdfSmrg int Flags); 676747b715Smrgextern _X_EXPORT void xf86FreeInt10(xf86Int10InfoPtr pInt); 686747b715Smrgextern _X_EXPORT void *xf86Int10AllocPages(xf86Int10InfoPtr pInt, int num, 6935c4bbdfSmrg int *off); 706747b715Smrgextern _X_EXPORT void xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, 7135c4bbdfSmrg int num); 7235c4bbdfSmrgextern _X_EXPORT void *xf86int10Addr(xf86Int10InfoPtr pInt, uint32_t addr); 7305b261ecSmrg 7405b261ecSmrg/* x86 executor related functions */ 756747b715Smrgextern _X_EXPORT void xf86ExecX86int10(xf86Int10InfoPtr pInt); 7605b261ecSmrg 7705b261ecSmrg#ifdef _INT10_PRIVATE 7805b261ecSmrg 7905b261ecSmrg#define I_S_DEFAULT_INT_VECT 0xFF065 8005b261ecSmrg#define SYS_SIZE 0x100000 8105b261ecSmrg#define SYS_BIOS 0xF0000 8205b261ecSmrg#if 1 8305b261ecSmrg#define BIOS_SIZE 0x10000 8435c4bbdfSmrg#else /* a bug in DGUX requires this - let's try it */ 8505b261ecSmrg#define BIOS_SIZE (0x10000 - 1) 8605b261ecSmrg#endif 8705b261ecSmrg#define LOW_PAGE_SIZE 0x600 8805b261ecSmrg#define V_RAM 0xA0000 8905b261ecSmrg#define VRAM_SIZE 0x20000 9005b261ecSmrg#define V_BIOS_SIZE 0x10000 9105b261ecSmrg#define V_BIOS 0xC0000 9205b261ecSmrg#define BIOS_SCRATCH_OFF 0x449 9305b261ecSmrg#define BIOS_SCRATCH_END 0x466 9405b261ecSmrg#define BIOS_SCRATCH_LEN (BIOS_SCRATCH_END - BIOS_SCRATCH_OFF + 1) 9505b261ecSmrg#define HIGH_MEM V_BIOS 9605b261ecSmrg#define HIGH_MEM_SIZE (SYS_BIOS - HIGH_MEM) 9705b261ecSmrg#define SEG_ADR(type, seg, reg) type((seg << 4) + (X86_##reg)) 9805b261ecSmrg#define SEG_EADR(type, seg, reg) type((seg << 4) + (X86_E##reg)) 9905b261ecSmrg 10005b261ecSmrg#define X86_TF_MASK 0x00000100 10105b261ecSmrg#define X86_IF_MASK 0x00000200 10205b261ecSmrg#define X86_IOPL_MASK 0x00003000 10305b261ecSmrg#define X86_NT_MASK 0x00004000 10405b261ecSmrg#define X86_VM_MASK 0x00020000 10505b261ecSmrg#define X86_AC_MASK 0x00040000 10635c4bbdfSmrg#define X86_VIF_MASK 0x00080000 /* virtual interrupt flag */ 10735c4bbdfSmrg#define X86_VIP_MASK 0x00100000 /* virtual interrupt pending */ 10805b261ecSmrg#define X86_ID_MASK 0x00200000 10905b261ecSmrg 11005b261ecSmrg#define MEM_RB(name, addr) (*name->mem->rb)(name, addr) 11105b261ecSmrg#define MEM_RW(name, addr) (*name->mem->rw)(name, addr) 11205b261ecSmrg#define MEM_RL(name, addr) (*name->mem->rl)(name, addr) 11305b261ecSmrg#define MEM_WB(name, addr, val) (*name->mem->wb)(name, addr, val) 11405b261ecSmrg#define MEM_WW(name, addr, val) (*name->mem->ww)(name, addr, val) 11505b261ecSmrg#define MEM_WL(name, addr, val) (*name->mem->wl)(name, addr, val) 11605b261ecSmrg 11705b261ecSmrg/* OS dependent functions */ 1186747b715Smrgextern _X_EXPORT Bool MapCurrentInt10(xf86Int10InfoPtr pInt); 11935c4bbdfSmrg 12005b261ecSmrg/* x86 executor related functions */ 1216747b715Smrgextern _X_EXPORT Bool xf86Int10ExecSetup(xf86Int10InfoPtr pInt); 12205b261ecSmrg 12305b261ecSmrg/* int.c */ 1246747b715Smrgextern _X_EXPORT xf86Int10InfoPtr Int10Current; 12505b261ecSmrgint int_handler(xf86Int10InfoPtr pInt); 12605b261ecSmrg 12705b261ecSmrg/* helper_exec.c */ 12805b261ecSmrgint setup_int(xf86Int10InfoPtr pInt); 12905b261ecSmrgvoid finish_int(xf86Int10InfoPtr, int sig); 13035c4bbdfSmrguint32_t getIntVect(xf86Int10InfoPtr pInt, int num); 13135c4bbdfSmrgvoid pushw(xf86Int10InfoPtr pInt, uint16_t val); 13205b261ecSmrgint run_bios_int(int num, xf86Int10InfoPtr pInt); 13305b261ecSmrgvoid dump_code(xf86Int10InfoPtr pInt); 13405b261ecSmrgvoid dump_registers(xf86Int10InfoPtr pInt); 13505b261ecSmrgvoid stack_trace(xf86Int10InfoPtr pInt); 13635c4bbdfSmrguint8_t bios_checksum(const uint8_t *start, int size); 13705b261ecSmrgvoid LockLegacyVGA(xf86Int10InfoPtr pInt, legacyVGAPtr vga); 13805b261ecSmrgvoid UnlockLegacyVGA(xf86Int10InfoPtr pInt, legacyVGAPtr vga); 13935c4bbdfSmrg 14005b261ecSmrg#if defined (_PC) 14135c4bbdfSmrgextern _X_EXPORT void xf86Int10SaveRestoreBIOSVars(xf86Int10InfoPtr pInt, 14235c4bbdfSmrg Bool save); 14305b261ecSmrg#endif 14405b261ecSmrgint port_rep_inb(xf86Int10InfoPtr pInt, 14535c4bbdfSmrg uint16_t port, uint32_t base, int d_f, uint32_t count); 14605b261ecSmrgint port_rep_inw(xf86Int10InfoPtr pInt, 14735c4bbdfSmrg uint16_t port, uint32_t base, int d_f, uint32_t count); 14805b261ecSmrgint port_rep_inl(xf86Int10InfoPtr pInt, 14935c4bbdfSmrg uint16_t port, uint32_t base, int d_f, uint32_t count); 15005b261ecSmrgint port_rep_outb(xf86Int10InfoPtr pInt, 15135c4bbdfSmrg uint16_t port, uint32_t base, int d_f, uint32_t count); 15205b261ecSmrgint port_rep_outw(xf86Int10InfoPtr pInt, 15335c4bbdfSmrg uint16_t port, uint32_t base, int d_f, uint32_t count); 15405b261ecSmrgint port_rep_outl(xf86Int10InfoPtr pInt, 15535c4bbdfSmrg uint16_t port, uint32_t base, int d_f, uint32_t count); 15635c4bbdfSmrg 15735c4bbdfSmrguint8_t x_inb(uint16_t port); 15835c4bbdfSmrguint16_t x_inw(uint16_t port); 15935c4bbdfSmrgvoid x_outb(uint16_t port, uint8_t val); 16035c4bbdfSmrgvoid x_outw(uint16_t port, uint16_t val); 16135c4bbdfSmrguint32_t x_inl(uint16_t port); 16235c4bbdfSmrgvoid x_outl(uint16_t port, uint32_t val); 16335c4bbdfSmrg 16435c4bbdfSmrguint8_t Mem_rb(uint32_t addr); 16535c4bbdfSmrguint16_t Mem_rw(uint32_t addr); 16635c4bbdfSmrguint32_t Mem_rl(uint32_t addr); 16735c4bbdfSmrgvoid Mem_wb(uint32_t addr, uint8_t val); 16835c4bbdfSmrgvoid Mem_ww(uint32_t addr, uint16_t val); 16935c4bbdfSmrgvoid Mem_wl(uint32_t addr, uint32_t val); 17005b261ecSmrg 17105b261ecSmrg/* helper_mem.c */ 17205b261ecSmrgvoid setup_int_vect(xf86Int10InfoPtr pInt); 17305b261ecSmrgint setup_system_bios(void *base_addr); 17405b261ecSmrgvoid reset_int_vect(xf86Int10InfoPtr pInt); 17505b261ecSmrgvoid set_return_trap(xf86Int10InfoPtr pInt); 17635c4bbdfSmrgextern _X_EXPORT void *xf86HandleInt10Options(ScrnInfoPtr pScrn, 17735c4bbdfSmrg int entityIndex); 17835c4bbdfSmrgBool int10skip(const void *options); 17905b261ecSmrgBool int10_check_bios(int scrnIndex, int codeSeg, 18035c4bbdfSmrg const unsigned char *vbiosMem); 18135c4bbdfSmrgBool initPrimary(const void *options); 18235c4bbdfSmrgextern _X_EXPORT BusType xf86int10GetBiosLocationType(const xf86Int10InfoPtr 18335c4bbdfSmrg pInt); 18435c4bbdfSmrgextern _X_EXPORT Bool xf86int10GetBiosSegment(xf86Int10InfoPtr pInt, 18535c4bbdfSmrg void *base); 18605b261ecSmrg#ifdef DEBUG 18705b261ecSmrgvoid dprint(unsigned long start, unsigned long size); 18805b261ecSmrg#endif 18905b261ecSmrg 19035c4bbdfSmrg#endif /* _INT10_PRIVATE */ 19135c4bbdfSmrg#endif /* _XF86INT10_H */ 192