mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-22 11:17:19 +00:00
6c03ba71f8
This commit reworks the code responsible for identification of the CPUs during runtime. It is necessary to provide a way for workarounds and erratums to be applied only for certain HW versions. The copy of MIDR is now stored in pcpu to provide a fast and convenient way for assambly code to read it (pcpu is used quite often so there is a chance it's inside the cache). The MIDR is also better way of identification than using user-friendly cpu_desc structure, because it can be compiled into comparision of single u32 with only one access to the memory - this is crucial for some erratums which are called from performance-critical places. Changes in cpu_identify makes this function safe to be called on non-boot CPUs. New function CPU_MATCH was implemented which returns boolean value based on mathing masked MIDR with chip identification. Example of usage: printf("is thunder: %d\n", CPU_MATCH(CPU_IMPL_MASK | CPU_PART_MASK, CPU_IMPL_CAVIUM, CPU_PART_THUNDER, 0, 0)); printf("is generic: %d\n", CPU_MATCH(CPU_IMPL_MASK | CPU_PART_MASK, CPU_IMPL_ARM, CPU_PART_FOUNDATION, 0, 0)); Reviewed by: andrew Obtained from: Semihalf Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D3030
77 lines
2.4 KiB
C
77 lines
2.4 KiB
C
/*-
|
|
* Copyright (c) 1999 Luoqi Chen <luoqi@freebsd.org>
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. 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.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
*
|
|
* from: FreeBSD: src/sys/i386/include/globaldata.h,v 1.27 2001/04/27
|
|
* $FreeBSD$
|
|
*/
|
|
|
|
#ifndef _MACHINE_PCPU_H_
|
|
#define _MACHINE_PCPU_H_
|
|
|
|
#include <machine/cpu.h>
|
|
#include <machine/cpufunc.h>
|
|
|
|
#define ALT_STACK_SIZE 128
|
|
|
|
#define PCPU_MD_FIELDS \
|
|
u_int pc_acpi_id; /* ACPI CPU id */ \
|
|
u_int pc_midr; /* stored MIDR value */ \
|
|
char __pad[121]
|
|
|
|
#ifdef _KERNEL
|
|
|
|
struct pcb;
|
|
struct pcpu;
|
|
|
|
static inline struct pcpu *
|
|
get_pcpu(void)
|
|
{
|
|
struct pcpu *pcpu;
|
|
|
|
__asm __volatile("mov %0, x18" : "=&r"(pcpu));
|
|
return (pcpu);
|
|
}
|
|
|
|
static inline struct thread *
|
|
get_curthread(void)
|
|
{
|
|
struct thread *td;
|
|
|
|
__asm __volatile("ldr %0, [x18]" : "=&r"(td));
|
|
return (td);
|
|
}
|
|
|
|
#define curthread get_curthread()
|
|
|
|
#define PCPU_GET(member) (get_pcpu()->pc_ ## member)
|
|
#define PCPU_ADD(member, value) (get_pcpu()->pc_ ## member += (value))
|
|
#define PCPU_INC(member) PCPU_ADD(member, 1)
|
|
#define PCPU_PTR(member) (&get_pcpu()->pc_ ## member)
|
|
#define PCPU_SET(member,value) (get_pcpu()->pc_ ## member = (value))
|
|
|
|
#endif /* _KERNEL */
|
|
|
|
#endif /* !_MACHINE_PCPU_H_ */
|