1*5d9d9091SRichard Lowe/* 2*5d9d9091SRichard Lowe * CDDL HEADER START 3*5d9d9091SRichard Lowe * 4*5d9d9091SRichard Lowe * The contents of this file are subject to the terms of the 5*5d9d9091SRichard Lowe * Common Development and Distribution License (the "License"). 6*5d9d9091SRichard Lowe * You may not use this file except in compliance with the License. 7*5d9d9091SRichard Lowe * 8*5d9d9091SRichard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*5d9d9091SRichard Lowe * or http://www.opensolaris.org/os/licensing. 10*5d9d9091SRichard Lowe * See the License for the specific language governing permissions 11*5d9d9091SRichard Lowe * and limitations under the License. 12*5d9d9091SRichard Lowe * 13*5d9d9091SRichard Lowe * When distributing Covered Code, include this CDDL HEADER in each 14*5d9d9091SRichard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*5d9d9091SRichard Lowe * If applicable, add the following below this CDDL HEADER, with the 16*5d9d9091SRichard Lowe * fields enclosed by brackets "[]" replaced with your own identifying 17*5d9d9091SRichard Lowe * information: Portions Copyright [yyyy] [name of copyright owner] 18*5d9d9091SRichard Lowe * 19*5d9d9091SRichard Lowe * CDDL HEADER END 20*5d9d9091SRichard Lowe */ 21*5d9d9091SRichard Lowe/* 22*5d9d9091SRichard Lowe * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23*5d9d9091SRichard Lowe * Use is subject to license terms. 24*5d9d9091SRichard Lowe */ 25*5d9d9091SRichard Lowe 26*5d9d9091SRichard Lowe/* 27*5d9d9091SRichard Lowe * Copyright 2019 Joyent, Inc. 28*5d9d9091SRichard Lowe */ 29*5d9d9091SRichard Lowe 30*5d9d9091SRichard Lowe#include <sys/asm_linkage.h> 31*5d9d9091SRichard Lowe#include <sys/asm_misc.h> 32*5d9d9091SRichard Lowe 33*5d9d9091SRichard Lowe/* 34*5d9d9091SRichard Lowe * Implementation as specific by ACPI 3.0 specification 35*5d9d9091SRichard Lowe * section 5.2.10.1 36*5d9d9091SRichard Lowe * 37*5d9d9091SRichard Lowe * Global Lock Structure within the FACS 38*5d9d9091SRichard Lowe * 39*5d9d9091SRichard Lowe * |-----------------------------------------------------------------------| 40*5d9d9091SRichard Lowe * | Field | Bit Length | Bit Offset | Description | 41*5d9d9091SRichard Lowe * |---------|------------|------------|-----------------------------------| 42*5d9d9091SRichard Lowe * | Pending | 1 | 0 | Non-zero indicates that a request | 43*5d9d9091SRichard Lowe * | | | | for ownership of the global lock | 44*5d9d9091SRichard Lowe * | | | | is pending. | 45*5d9d9091SRichard Lowe * |---------|------------|------------|-----------------------------------| 46*5d9d9091SRichard Lowe * | Owned | 1 | 1 | Non-zero indicates that the Global| 47*5d9d9091SRichard Lowe * | | | | lock is owned. | 48*5d9d9091SRichard Lowe * |---------|------------|------------|-----------------------------------| 49*5d9d9091SRichard Lowe * | Reserved| 30 | 2 | Reserved for future use | 50*5d9d9091SRichard Lowe * |---------|------------|------------|-----------------------------------| 51*5d9d9091SRichard Lowe */ 52*5d9d9091SRichard Lowe 53*5d9d9091SRichard Lowe/* Offset of GlobalLock element in FACS structure */ 54*5d9d9091SRichard Lowe#define GlobalLock 0x10 55*5d9d9091SRichard Lowe 56*5d9d9091SRichard Lowe ENTRY(__acpi_acquire_global_lock) 57*5d9d9091SRichard Lowe movq $0xff, %rax / error return if FACS is null 58*5d9d9091SRichard Lowe orq %rdi, %rdi / %rdi contains pointer to FACS 59*5d9d9091SRichard Lowe jz 1f 60*5d9d9091SRichard Lowe leaq GlobalLock(%rdi), %rdi / make %rdi point at the lock 61*5d9d9091SRichard Lowe0: 62*5d9d9091SRichard Lowe movl (%rdi), %eax / get current value of Global Lock 63*5d9d9091SRichard Lowe movl %eax, %edx 64*5d9d9091SRichard Lowe andl $0xFFFFFFFE, %edx / Clear pending bit 65*5d9d9091SRichard Lowe btsl $1, %edx / Check and set owner bit 66*5d9d9091SRichard Lowe adcl $0, %edx / If owned, set pending bit 67*5d9d9091SRichard Lowe lock 68*5d9d9091SRichard Lowe cmpxchgl %edx, (%rdi) / Attempt to set new value 69*5d9d9091SRichard Lowe jnz 0b / If not set, try again 70*5d9d9091SRichard Lowe cmpb $3, %dl / Was it acquired or marked pending? 71*5d9d9091SRichard Lowe sbbq %rax, %rax / acquired = -1, pending = 0 72*5d9d9091SRichard Lowe1: 73*5d9d9091SRichard Lowe ret 74*5d9d9091SRichard Lowe SET_SIZE(__acpi_acquire_global_lock) 75*5d9d9091SRichard Lowe 76*5d9d9091SRichard Lowe 77*5d9d9091SRichard Lowe ENTRY(__acpi_release_global_lock) 78*5d9d9091SRichard Lowe xorq %rax, %rax / error return if FACS is null 79*5d9d9091SRichard Lowe orq %rdi, %rdi / %rdi contains pointer to FACS 80*5d9d9091SRichard Lowe jz 1f 81*5d9d9091SRichard Lowe leaq GlobalLock(%rdi), %rdi / make %rdi point at the lock 82*5d9d9091SRichard Lowe0: 83*5d9d9091SRichard Lowe movl (%rdi), %eax 84*5d9d9091SRichard Lowe movl %eax, %edx 85*5d9d9091SRichard Lowe andl $0xFFFFFFFC, %edx 86*5d9d9091SRichard Lowe lock 87*5d9d9091SRichard Lowe cmpxchgl %edx, (%rdi) 88*5d9d9091SRichard Lowe jnz 0b 89*5d9d9091SRichard Lowe andq $1, %rax 90*5d9d9091SRichard Lowe1: 91*5d9d9091SRichard Lowe ret 92*5d9d9091SRichard Lowe SET_SIZE(__acpi_release_global_lock) 93*5d9d9091SRichard Lowe 94*5d9d9091SRichard Lowe 95*5d9d9091SRichard Lowe/* 96*5d9d9091SRichard Lowe * execute WBINVD instruction 97*5d9d9091SRichard Lowe */ 98*5d9d9091SRichard Lowe 99*5d9d9091SRichard Lowe ENTRY(__acpi_wbinvd) 100*5d9d9091SRichard Lowe wbinvd 101*5d9d9091SRichard Lowe ret 102*5d9d9091SRichard Lowe SET_SIZE(__acpi_wbinvd) 103*5d9d9091SRichard Lowe 104