Skip to content

Commit

Permalink
Redo cpuid feature detection
Browse files Browse the repository at this point in the history
We already have a proper cpuid feature API used in
userland, but Linux took it out for KERNEL use, to
plug into the Linux API. We do not have a kernel API to
use, so we might as well use the userland one.

This makes it nice and consistent, and more easy to read.

Signed-off-by: Jorgen Lundman <lundman@lundman.net>
  • Loading branch information
lundman committed Mar 16, 2024
1 parent da258e8 commit a6aab9d
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 305 deletions.
47 changes: 46 additions & 1 deletion include/os/macos/spl/sys/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,53 @@
#include <sys/types.h>

extern uint32_t getcpuid(void);
extern uint64_t spl_cpuid_features(void);

#if defined(__amd64__) || defined(__i386__)

extern int __cpuid_count(unsigned int __level, unsigned int __sublevel,
unsigned int __eax, unsigned int __ebx,
unsigned int __ecx, unsigned int __edx);

#define __cpuid_count(level, count, a, b, c, d) \
__asm__("xchg{l}\t{%%}ebx, %1\n\t" \
"cpuid\n\t" \
"xchg{l}\t{%%}ebx, %1\n\t" \
: "=a" (a), "=r" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))

#define __cpuid(level, a, b, c, d) \
__asm__("xchg{l}\t{%%}ebx, %1\n\t" \
"cpuid\n\t" \
"xchg{l}\t{%%}ebx, %1\n\t" \
: "=a" (a), "=r" (b), "=c" (c), "=d" (d) \
: "0" (level))

static inline unsigned int
__get_cpuid_max(unsigned int __ext, unsigned int *__sig)
{
unsigned int __eax, __ebx, __ecx, __edx;
__cpuid(__ext, __eax, __ebx, __ecx, __edx);
if (__sig)
*__sig = __ebx;
return (__eax);
}

/* macOS does have do_cpuid() macro */
static inline int
__get_cpuid(unsigned int __level,
unsigned int *__eax, unsigned int *__ebx,
unsigned int *__ecx, unsigned int *__edx)
{
unsigned int __ext = __level & 0x80000000;
if (__get_cpuid_max(__ext, 0) < __level)
return (0);
__cpuid(__level, *__eax, *__ebx, *__ecx, *__edx);
return (1);
}

#endif // x86

typedef int processorid_t;
extern int spl_processor_init(void);

#endif /* _SPL_PROCESSOR_H */
Loading

0 comments on commit a6aab9d

Please sign in to comment.