cppc_msr.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * cppc_msr.c: MSR Interface for CPPC
  3. * Copyright (c) 2016, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. */
  15. #include <acpi/cppc_acpi.h>
  16. #include <asm/msr.h>
  17. /* Refer to drivers/acpi/cppc_acpi.c for the description of functions */
  18. bool cpc_ffh_supported(void)
  19. {
  20. return true;
  21. }
  22. int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val)
  23. {
  24. int err;
  25. err = rdmsrl_safe_on_cpu(cpunum, reg->address, val);
  26. if (!err) {
  27. u64 mask = GENMASK_ULL(reg->bit_offset + reg->bit_width - 1,
  28. reg->bit_offset);
  29. *val &= mask;
  30. *val >>= reg->bit_offset;
  31. }
  32. return err;
  33. }
  34. int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
  35. {
  36. u64 rd_val;
  37. int err;
  38. err = rdmsrl_safe_on_cpu(cpunum, reg->address, &rd_val);
  39. if (!err) {
  40. u64 mask = GENMASK_ULL(reg->bit_offset + reg->bit_width - 1,
  41. reg->bit_offset);
  42. val <<= reg->bit_offset;
  43. val &= mask;
  44. rd_val &= ~mask;
  45. rd_val |= val;
  46. err = wrmsrl_safe_on_cpu(cpunum, reg->address, rd_val);
  47. }
  48. return err;
  49. }