diff mbox

[U-Boot,v3,2/5] x86: Add functions to set and clear bits on MSRs

Message ID 1430367963-1067-3-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass April 30, 2015, 4:26 a.m. UTC
Since we do these sorts of operations a lot, it is useful to have a simpler
API, similar to clrsetbits_le32().

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3:
- Add msr_clrbits_64() too

Changes in v2: None

 arch/x86/include/asm/msr.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Bin Meng April 30, 2015, 6:11 a.m. UTC | #1
On Thu, Apr 30, 2015 at 12:26 PM, Simon Glass <sjg@chromium.org> wrote:
> Since we do these sorts of operations a lot, it is useful to have a simpler
> API, similar to clrsetbits_le32().
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v3:
> - Add msr_clrbits_64() too

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

[snip]

Regards,
Bin
Simon Glass May 1, 2015, 12:52 a.m. UTC | #2
On 30 April 2015 at 00:11, Bin Meng <bmeng.cn@gmail.com> wrote:
> On Thu, Apr 30, 2015 at 12:26 PM, Simon Glass <sjg@chromium.org> wrote:
>> Since we do these sorts of operations a lot, it is useful to have a simpler
>> API, similar to clrsetbits_le32().
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>> Changes in v3:
>> - Add msr_clrbits_64() too
>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Applied to u-boot-x86.
diff mbox

Patch

diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h
index 1955a75..c480920 100644
--- a/arch/x86/include/asm/msr.h
+++ b/arch/x86/include/asm/msr.h
@@ -128,6 +128,34 @@  static inline void wrmsr(unsigned msr, unsigned low, unsigned high)
 #define wrmsrl(msr, val)						\
 	native_write_msr((msr), (u32)((u64)(val)), (u32)((u64)(val) >> 32))
 
+static inline void msr_clrsetbits_64(unsigned msr, u64 clear, u64 set)
+{
+	u64 val;
+
+	val = native_read_msr(msr);
+	val &= ~clear;
+	val |= set;
+	wrmsrl(msr, val);
+}
+
+static inline void msr_setbits_64(unsigned msr, u64 set)
+{
+	u64 val;
+
+	val = native_read_msr(msr);
+	val |= set;
+	wrmsrl(msr, val);
+}
+
+static inline void msr_clrbits_64(unsigned msr, u64 clear)
+{
+	u64 val;
+
+	val = native_read_msr(msr);
+	val &= ~clear;
+	wrmsrl(msr, val);
+}
+
 /* rdmsr with exception handling */
 #define rdmsr_safe(msr, p1, p2)					\
 ({								\