mirror of
https://github.com/memtest86plus/memtest86plus.git
synced 2025-02-16 13:34:45 -06:00
* lib/assert: Add LoongArch assert support Added LoongArch break 3 assert instruction. Signed-off-by: Chao Li <lichao@loongson.cn> * lib/barrier: Add barrier method for LoongArch Added LoongArch barriers in barrier_spin_wait and barrier_halt_wait functions. Signed-off-by: Chao Li <lichao@loognson.cn> * lib/spinlock: Add LoongArch CPU pause Because the LoongArch haven't pause instruction, using eight nops to replace the pause. Signed-off-by: Chao Li <lichao@loongson.cn> * lib/string: Make LoongArch use the string function in the file Since LoongArch GCC doesn't have built-in string functions, use the string function instance in the sting.c Signed-off-by: Chao Li <lichao@loongson.cn> * lib/unistd: Add LoongArch CPU pause Because the LoongArch haven't pause instruction, using eight nops to replace the pause. Signed-off-by: Chao Li <lichao@loongson.cn> * system/acpi: Reduce the way of search RSDP for non-x86 ARCHs Searching RSDP from legacy BIOS EDBA and reserved areas is available only on i386 and x64. Signed-off-by: Chao Li <lichao@loongson.cn> * system/cache: Add LoongArch64 cache operations support Added cache operations support for LoongArch64. Signed-off-by: Chao Li <lichao@loongson.cn> * system/cpuid: Add the compile limit Make the `cpuid` function action only on i386/x64. Signed-off-by: Chao Li <lichao@loongson.cn> * system/heap: Add heap support for LoongArch64 LoongArch64 uses the low 256MB as the low memory. Signed-off-by: Chao Li <lichao@loongson.cn> * system/memrw: Add 8-bit and 16-bit memory operations Added 8-bit and 16-bit memory access operations, which 8-bit uses `movb` and 16-bit is `movw`. Signed-off-by: Chao Li <lichao@loongson.cn> * system/memrw: Add LoongArch memory access operations Added 8/16/32/64-bit memory access operations for LoongArch64. Signed-off-by: Chao Li <lichao@loongson.cn> * system: Add Loongson PCI vendor ID and Loongson 7A chipset EHCI workaround 1. Added Loongson PCI vendor ID. 2. Added Loongson 7A chipset ECHI workaround. Signed-off-by: Chao Li <lichao@loongson.cn> * system/io: Add LoongArch64 IO port operations Added IO port operations for LoongArch64. Signed-off-by: Chao Li <lichao@loongson.cn> * system/reloc64: Add LoongArch64 relocations support Added R_LARCH_RELATIVE and R_LARCH_NONE relocations support for LoongArch64. Signed-off-by: Chao Li <lichao@loongson.cn> * system/serial: Add Loongson CPU serial port support Add the serial port address perfix of Loongson CPU and obtain serial port clock method. Signed-off-by: Chao Li <lichao@loongson.cn> * system/smbus: Rename smbus.c to i2c_x86.c Renamed the smbus.c to i2c_x86.c in i386 and x64 platforms. Signed-off-by: Chao Li <lichao@loongson.cn> * system/smp: Add LoongArch SMP support Added LoongArch multi-core support and a way of map to node numbers if the NUMA is enabled. Signed-off-by: Chao Li <lichao@loongson.cn> * system/timers: Add LoongArch supports In LoongArch, there is a stable counter that is independent of other clocks, it like the TSC in x64. Using it to count the ticks per millisecond. Signed-off-by: Chao Li <lichao@loongson.cn> * system/tsc: Add LoongArch support Usually the frequency of stable counter is not same to CPU frequency, so using the performance counter for the delay operations. Signed-off-by: Chao Li <lichao@loongson.cn> * system/usbhcd: Add LoongArch MMIO perfix Added LoongArch64 MMIO address perfix, use for address the PCI memory space. Signed-off-by: Chao Li <lichao@loongson.cn> * system/usbhcd: Add Loongson 7A2000 chipset OHCI BAR offset fix If the BAR address is not fixed for the Loongson 7A2000 OHCI controller, some prots will not be usable, This change currently only affects the LoongArch platform. Signed-off-by: Chao Li <lichao@loongson.cn> * system: Add the way to IO access via MMIO Usually, it is access the IO like PCI IO via MMIO on non-X86 ARCHs, so a method to access IO via MMIO is added. Signed-off-by: Chao Li <lichao@loongson.cn> * system: Add the way to access PCI memory space via MMIO Some uniformly address ARCHs access the PCI memory depended the MMIO, so the method to access PCI memory via MMIO is added. Signed-off-by: Chao Li <lichao@loongson.cn> * app: Add LoongArch version support Reduced the version field by two characters to support ARCH name abbreviations with more than three characters, and added "la64" ARCH version display. Singed-off-by: Chao Li <lichao@loongson.cn> * test/block_move: Add block move test via ASM for LoongArch Add block move test inline assembly instance for LoongArch. Signed-off-by: Chao Li <lichao@loongson.cn> * test/mov_inv_fixed: Add LoongArch ASM version word write operation Add LoongArch ASM version word write cycle if it uses the HAND_OPTIMISED. Signed-off-by: Chao Li <lichao@loongson.cn> * boot: Adjust the AP stack size for LoongArch LoongArch exception will store all of the GP, FP and CSR on stack, it need more stack size, make LoongArch AP using 2KB stack size. Signed-off-by: Chao Li <lichao@loongson.cn> * boot/efisetup: Add LoongArch CPU halt instruction Add "idle 0" for LoongArch Signed-off-by: Chao Li <lichao@loongson.cn> * boot/efi: Limiting the ms_abi using scope Make the ms_abi only work on i386 and x64. Signed-off-by: Chao Li <lichao@loongson.cn> * system/imc/loongson: Add Loongson LoongArch IMC support Added the Loongson LoongArch CPU IMC instance, support read out the IMC sequence, currently only supports reading MC0. Signed-off-by: Chao Li <lichao@loongson.cn> * app/loongarch: Add intrrupt handler for LoongArch Added the LoongArch IRQ handler support. Signed-off-by: Chao Li <lichao@loongson.cn> * system/loongarch: Add LoongArch ARCH specific files Added LoongArch ARCH specific files: cpuid.c, cpuinfo.c, hwctrl.c, memctrl.c, temperature.c, vmem.c, registers.h They use the same pubilc API for i386 and x64 platforms. Signed-off-by: Chao Li <lichao@loongson.cn> * boot: Add LoongArch startup and header Added the header.S and startup64.S for LoongArch, CPU works on: 1. Page mode. 2. Load and store is cacheable. 3. Instructions is cacheable. 4. DMWn 0 and 1 is used. 5. To access non-cacheable areas, use the perfix 0x8000000000000000. Signed-off Chao Li <lichao@loongson.cn> * build64/la64: Add LoongArch64 build files Add infrastructure files to build memtest86 plus for LoongArch64 platform. Signed-off-by: Chao Li <lichao@loongson.cn> * workflows: Add LoongArch64 CI supports Adjust workflow logci, remvoe 32 and 64 wordsize, replace with "i386, x86_64 and la64", add LoongArch64 build CI check. Signed-off-by: Chao Li <lichao@loongson.cn> --------- Signed-off-by: Chao Li <lichao@loongson.cn> Signed-off-by: Chao Li <lichao@loognson.cn>
208 lines
5.4 KiB
C
208 lines
5.4 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef IO_H
|
|
#define IO_H
|
|
/**
|
|
* \file
|
|
*
|
|
* Provides macro definitions for the x86 IO instructions
|
|
* inb/inw/inl/outb/outw/outl and the "string versions" of the same
|
|
* (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
|
|
* versions of the single-IO instructions (inb_p/inw_p/..).
|
|
*
|
|
* This file is not meant to be obfuscating: it's just complicated
|
|
* to (a) handle it all in a way that makes gcc able to optimize it
|
|
* as well as possible and (b) trying to avoid writing the same thing
|
|
* over and over again with slight variations and possibly making a
|
|
* mistake somewhere.
|
|
*
|
|
*//*
|
|
* Derived from memtest86+ io.h.
|
|
* (original contained no copyright statement)
|
|
*/
|
|
|
|
#if defined(__x86_64) || defined(__i386__)
|
|
|
|
#ifdef SLOW_IO_BY_JUMPING
|
|
#define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
|
|
#else
|
|
#define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
|
|
#endif
|
|
|
|
#ifdef REALLY_SLOW_IO
|
|
#define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
|
|
#else
|
|
#define SLOW_DOWN_IO __SLOW_DOWN_IO
|
|
#endif
|
|
|
|
#define __OUT1(s,x) \
|
|
static inline void __out##s(unsigned x value, unsigned short port) {
|
|
|
|
#define __OUT2(s,s1,s2) \
|
|
__asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
|
|
|
|
#define __OUT(s,s1,x) \
|
|
__OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); } \
|
|
__OUT1(s##c,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); } \
|
|
__OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "d" (port)); SLOW_DOWN_IO; } \
|
|
__OUT1(s##c_p,x) __OUT2(s,s1,"") : : "a" (value), "id" (port)); SLOW_DOWN_IO; }
|
|
|
|
#define __IN1(s) \
|
|
static inline RETURN_TYPE __in##s(unsigned short port) { RETURN_TYPE _v;
|
|
|
|
#define __IN2(s,s1,s2) \
|
|
__asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
|
|
|
|
#define __IN(s,s1,i...) \
|
|
__IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); return _v; } \
|
|
__IN1(s##c) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); return _v; } \
|
|
__IN1(s##_p) __IN2(s,s1,"w") : "=a" (_v) : "d" (port) ,##i ); SLOW_DOWN_IO; return _v; } \
|
|
__IN1(s##c_p) __IN2(s,s1,"") : "=a" (_v) : "id" (port) ,##i ); SLOW_DOWN_IO; return _v; }
|
|
|
|
#define __OUTS(s) \
|
|
static inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
|
|
{ __asm__ __volatile__ ("cld ; rep ; outs" #s \
|
|
: "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
|
|
|
|
#define RETURN_TYPE unsigned char
|
|
/* __IN(b,"b","0" (0)) */
|
|
__IN(b,"")
|
|
#undef RETURN_TYPE
|
|
#define RETURN_TYPE unsigned short
|
|
/* __IN(w,"w","0" (0)) */
|
|
__IN(w,"")
|
|
#undef RETURN_TYPE
|
|
#define RETURN_TYPE unsigned int
|
|
__IN(l,"")
|
|
#undef RETURN_TYPE
|
|
|
|
__OUT(b,"b",char)
|
|
__OUT(w,"w",short)
|
|
__OUT(l,,int)
|
|
|
|
__OUTS(b)
|
|
__OUTS(w)
|
|
__OUTS(l)
|
|
|
|
/**
|
|
* Note that due to the way __builtin_constant_p() works, you
|
|
* - can't use it inside a inline function (it will never be true)
|
|
* - you don't have to worry about side effects within the __builtin..
|
|
*/
|
|
#define outb(val,port) \
|
|
((__builtin_constant_p((port)) && (port) < 256) ? \
|
|
__outbc((val),(port)) : \
|
|
__outb((val),(port)))
|
|
|
|
#define inb(port) \
|
|
((__builtin_constant_p((port)) && (port) < 256) ? \
|
|
__inbc(port) : \
|
|
__inb(port))
|
|
|
|
|
|
#define outw(val,port) \
|
|
((__builtin_constant_p((port)) && (port) < 256) ? \
|
|
__outwc((val),(port)) : \
|
|
__outw((val),(port)))
|
|
|
|
#define inw(port) \
|
|
((__builtin_constant_p((port)) && (port) < 256) ? \
|
|
__inwc(port) : \
|
|
__inw(port))
|
|
|
|
|
|
#define outl(val,port) \
|
|
((__builtin_constant_p((port)) && (port) < 256) ? \
|
|
__outlc((val),(port)) : \
|
|
__outl((val),(port)))
|
|
|
|
#define inl(port) \
|
|
((__builtin_constant_p((port)) && (port) < 256) ? \
|
|
__inlc(port) : \
|
|
__inl(port))
|
|
|
|
static __inline unsigned char
|
|
inb_p (unsigned short int __port)
|
|
{
|
|
unsigned char _v;
|
|
|
|
__asm__ __volatile__ ("\t"
|
|
"inb %w1,%0 \n\t"
|
|
"outb %%al,$0x80 \n"
|
|
: "=a" (_v)
|
|
: "Nd" (__port)
|
|
);
|
|
|
|
return _v;
|
|
}
|
|
|
|
static __inline void
|
|
outb_p (unsigned char __value, unsigned short int __port)
|
|
{
|
|
__asm__ __volatile__ ("\t"
|
|
"outb %b0,%w1 \n\t"
|
|
"outb %%al,$0x80 \n"
|
|
: /* no outputs */
|
|
: "a" (__value),
|
|
"Nd" (__port)
|
|
);
|
|
}
|
|
|
|
#elif defined(__loongarch_lp64)
|
|
|
|
#define LOONGSON_IO_PROT_BASE 0x0efdfc000000
|
|
|
|
#define __IN(s, s1) \
|
|
static inline RETURN_TYPE __in##s(unsigned short port) { \
|
|
RETURN_TYPE _v; \
|
|
__asm__ __volatile__ ( \
|
|
"li.d $t0, 0x28\n\t" \
|
|
"csrwr $t0, 0x0\n\t" \
|
|
"ld." s1 " %0, %1, 0 \n\t" \
|
|
"csrwr $t0, 0x0\n\t" \
|
|
: "=r" (_v) \
|
|
: "r" (LOONGSON_IO_PROT_BASE + port) \
|
|
: "$t0" \
|
|
); \
|
|
return _v; \
|
|
}
|
|
#define RETURN_TYPE uint8_t
|
|
__IN(b, "b");
|
|
#undef RETURN_TYPE
|
|
#define RETURN_TYPE uint16_t
|
|
__IN(w, "h");
|
|
#undef RETURN_TYPE
|
|
#define RETURN_TYPE uint32_t
|
|
__IN(l, "w");
|
|
|
|
#define __OUT(s, s1) \
|
|
static __inline void __out##s (VALUE_TYPE val, unsigned short port) { \
|
|
__asm__ __volatile__ ( \
|
|
"li.d $t0, 0x28\n\t" \
|
|
"csrwr $t0, 0x0\n\t" \
|
|
"st." s1 " %z0, %1, 0 \n\t" \
|
|
"csrwr $t0, 0x0\n\t" \
|
|
: \
|
|
: "Jr" (val), "r" (LOONGSON_IO_PROT_BASE + port) \
|
|
: "$t0" \
|
|
); \
|
|
}
|
|
#define VALUE_TYPE uint8_t
|
|
__OUT(b, "b");
|
|
#undef VALUE_TYPE
|
|
#define VALUE_TYPE uint16_t
|
|
__OUT(w, "h");
|
|
#undef VALUE_TYPE
|
|
#define VALUE_TYPE uint32_t
|
|
__OUT(l, "w");
|
|
|
|
#define outb(val,port) __outb(val,port)
|
|
#define inb(port) __inb(port)
|
|
#define outw(val,port) __outw(val,port)
|
|
#define inw(port) __inw(port)
|
|
#define outl(val,port) __outl(val,port)
|
|
#define inl(port) __inl(port)
|
|
|
|
#endif
|
|
|
|
#endif // IO_H
|