cpufeature.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copied from arch/arm64/kernel/cpufeature.c
  3. *
  4. * Copyright (C) 2015 ARM Ltd.
  5. * Copyright (C) 2017 SiFive
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/of.h>
  20. #include <asm/processor.h>
  21. #include <asm/hwcap.h>
  22. unsigned long elf_hwcap __read_mostly;
  23. void riscv_fill_hwcap(void)
  24. {
  25. struct device_node *node;
  26. const char *isa;
  27. size_t i;
  28. static unsigned long isa2hwcap[256] = {0};
  29. isa2hwcap['i'] = isa2hwcap['I'] = COMPAT_HWCAP_ISA_I;
  30. isa2hwcap['m'] = isa2hwcap['M'] = COMPAT_HWCAP_ISA_M;
  31. isa2hwcap['a'] = isa2hwcap['A'] = COMPAT_HWCAP_ISA_A;
  32. isa2hwcap['f'] = isa2hwcap['F'] = COMPAT_HWCAP_ISA_F;
  33. isa2hwcap['d'] = isa2hwcap['D'] = COMPAT_HWCAP_ISA_D;
  34. isa2hwcap['c'] = isa2hwcap['C'] = COMPAT_HWCAP_ISA_C;
  35. elf_hwcap = 0;
  36. /*
  37. * We don't support running Linux on hertergenous ISA systems. For
  38. * now, we just check the ISA of the first processor.
  39. */
  40. node = of_find_node_by_type(NULL, "cpu");
  41. if (!node) {
  42. pr_warning("Unable to find \"cpu\" devicetree entry");
  43. return;
  44. }
  45. if (of_property_read_string(node, "riscv,isa", &isa)) {
  46. pr_warning("Unable to find \"riscv,isa\" devicetree entry");
  47. return;
  48. }
  49. for (i = 0; i < strlen(isa); ++i)
  50. elf_hwcap |= isa2hwcap[(unsigned char)(isa[i])];
  51. pr_info("elf_hwcap is 0x%lx", elf_hwcap);
  52. }