bios_uv.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * BIOS run time interface routines.
  4. *
  5. * (C) Copyright 2020 Hewlett Packard Enterprise Development LP
  6. * Copyright (C) 2007-2017 Silicon Graphics, Inc. All rights reserved.
  7. * Copyright (c) Russ Anderson <rja@sgi.com>
  8. */
  9. #include <linux/efi.h>
  10. #include <linux/export.h>
  11. #include <linux/slab.h>
  12. #include <asm/efi.h>
  13. #include <linux/io.h>
  14. #include <asm/pgalloc.h>
  15. #include <asm/uv/bios.h>
  16. #include <asm/uv/uv_hub.h>
  17. unsigned long uv_systab_phys __ro_after_init = EFI_INVALID_TABLE_ADDR;
  18. struct uv_systab *uv_systab;
  19. static s64 __uv_bios_call(enum uv_bios_cmd which, u64 a1, u64 a2, u64 a3,
  20. u64 a4, u64 a5)
  21. {
  22. struct uv_systab *tab = uv_systab;
  23. s64 ret;
  24. if (!tab || !tab->function)
  25. /*
  26. * BIOS does not support UV systab
  27. */
  28. return BIOS_STATUS_UNIMPLEMENTED;
  29. ret = efi_call_virt_pointer(tab, function, (u64)which, a1, a2, a3, a4, a5);
  30. return ret;
  31. }
  32. static s64 uv_bios_call(enum uv_bios_cmd which, u64 a1, u64 a2, u64 a3, u64 a4,
  33. u64 a5)
  34. {
  35. s64 ret;
  36. if (down_interruptible(&__efi_uv_runtime_lock))
  37. return BIOS_STATUS_ABORT;
  38. ret = __uv_bios_call(which, a1, a2, a3, a4, a5);
  39. up(&__efi_uv_runtime_lock);
  40. return ret;
  41. }
  42. static s64 uv_bios_call_irqsave(enum uv_bios_cmd which, u64 a1, u64 a2, u64 a3,
  43. u64 a4, u64 a5)
  44. {
  45. unsigned long bios_flags;
  46. s64 ret;
  47. if (down_interruptible(&__efi_uv_runtime_lock))
  48. return BIOS_STATUS_ABORT;
  49. local_irq_save(bios_flags);
  50. ret = __uv_bios_call(which, a1, a2, a3, a4, a5);
  51. local_irq_restore(bios_flags);
  52. up(&__efi_uv_runtime_lock);
  53. return ret;
  54. }
  55. long sn_partition_id;
  56. EXPORT_SYMBOL_GPL(sn_partition_id);
  57. long sn_coherency_id;
  58. EXPORT_SYMBOL_GPL(sn_coherency_id);
  59. long sn_region_size;
  60. EXPORT_SYMBOL_GPL(sn_region_size);
  61. long system_serial_number;
  62. int uv_type;
  63. s64 uv_bios_get_sn_info(int fc, int *uvtype, long *partid, long *coher,
  64. long *region, long *ssn)
  65. {
  66. s64 ret;
  67. u64 v0, v1;
  68. union partition_info_u part;
  69. ret = uv_bios_call_irqsave(UV_BIOS_GET_SN_INFO, fc,
  70. (u64)(&v0), (u64)(&v1), 0, 0);
  71. if (ret != BIOS_STATUS_SUCCESS)
  72. return ret;
  73. part.val = v0;
  74. if (uvtype)
  75. *uvtype = part.hub_version;
  76. if (partid)
  77. *partid = part.partition_id;
  78. if (coher)
  79. *coher = part.coherence_id;
  80. if (region)
  81. *region = part.region_size;
  82. if (ssn)
  83. *ssn = v1;
  84. return ret;
  85. }
  86. int
  87. uv_bios_mq_watchlist_alloc(unsigned long addr, unsigned int mq_size,
  88. unsigned long *intr_mmr_offset)
  89. {
  90. u64 watchlist;
  91. s64 ret;
  92. /*
  93. * bios returns watchlist number or negative error number.
  94. */
  95. ret = (int)uv_bios_call_irqsave(UV_BIOS_WATCHLIST_ALLOC, addr,
  96. mq_size, (u64)intr_mmr_offset,
  97. (u64)&watchlist, 0);
  98. if (ret < BIOS_STATUS_SUCCESS)
  99. return ret;
  100. return watchlist;
  101. }
  102. EXPORT_SYMBOL_GPL(uv_bios_mq_watchlist_alloc);
  103. int
  104. uv_bios_mq_watchlist_free(int blade, int watchlist_num)
  105. {
  106. return (int)uv_bios_call_irqsave(UV_BIOS_WATCHLIST_FREE,
  107. blade, watchlist_num, 0, 0, 0);
  108. }
  109. EXPORT_SYMBOL_GPL(uv_bios_mq_watchlist_free);
  110. s64
  111. uv_bios_change_memprotect(u64 paddr, u64 len, enum uv_memprotect perms)
  112. {
  113. return uv_bios_call_irqsave(UV_BIOS_MEMPROTECT, paddr, len,
  114. perms, 0, 0);
  115. }
  116. EXPORT_SYMBOL_GPL(uv_bios_change_memprotect);
  117. s64
  118. uv_bios_reserved_page_pa(u64 buf, u64 *cookie, u64 *addr, u64 *len)
  119. {
  120. return uv_bios_call_irqsave(UV_BIOS_GET_PARTITION_ADDR, (u64)cookie,
  121. (u64)addr, buf, (u64)len, 0);
  122. }
  123. EXPORT_SYMBOL_GPL(uv_bios_reserved_page_pa);
  124. s64 uv_bios_freq_base(u64 clock_type, u64 *ticks_per_second)
  125. {
  126. return uv_bios_call(UV_BIOS_FREQ_BASE, clock_type,
  127. (u64)ticks_per_second, 0, 0, 0);
  128. }
  129. /*
  130. * uv_bios_set_legacy_vga_target - Set Legacy VGA I/O Target
  131. * @decode: true to enable target, false to disable target
  132. * @domain: PCI domain number
  133. * @bus: PCI bus number
  134. *
  135. * Returns:
  136. * 0: Success
  137. * -EINVAL: Invalid domain or bus number
  138. * -ENOSYS: Capability not available
  139. * -EBUSY: Legacy VGA I/O cannot be retargeted at this time
  140. */
  141. int uv_bios_set_legacy_vga_target(bool decode, int domain, int bus)
  142. {
  143. return uv_bios_call(UV_BIOS_SET_LEGACY_VGA_TARGET,
  144. (u64)decode, (u64)domain, (u64)bus, 0, 0);
  145. }
  146. extern s64 uv_bios_get_master_nasid(u64 size, u64 *master_nasid)
  147. {
  148. return uv_bios_call(UV_BIOS_EXTRA, 0, UV_BIOS_EXTRA_MASTER_NASID, 0,
  149. size, (u64)master_nasid);
  150. }
  151. EXPORT_SYMBOL_GPL(uv_bios_get_master_nasid);
  152. extern s64 uv_bios_get_heapsize(u64 nasid, u64 size, u64 *heap_size)
  153. {
  154. return uv_bios_call(UV_BIOS_EXTRA, nasid, UV_BIOS_EXTRA_GET_HEAPSIZE,
  155. 0, size, (u64)heap_size);
  156. }
  157. EXPORT_SYMBOL_GPL(uv_bios_get_heapsize);
  158. extern s64 uv_bios_install_heap(u64 nasid, u64 heap_size, u64 *bios_heap)
  159. {
  160. return uv_bios_call(UV_BIOS_EXTRA, nasid, UV_BIOS_EXTRA_INSTALL_HEAP,
  161. 0, heap_size, (u64)bios_heap);
  162. }
  163. EXPORT_SYMBOL_GPL(uv_bios_install_heap);
  164. extern s64 uv_bios_obj_count(u64 nasid, u64 size, u64 *objcnt)
  165. {
  166. return uv_bios_call(UV_BIOS_EXTRA, nasid, UV_BIOS_EXTRA_OBJECT_COUNT,
  167. 0, size, (u64)objcnt);
  168. }
  169. EXPORT_SYMBOL_GPL(uv_bios_obj_count);
  170. extern s64 uv_bios_enum_objs(u64 nasid, u64 size, u64 *objbuf)
  171. {
  172. return uv_bios_call(UV_BIOS_EXTRA, nasid, UV_BIOS_EXTRA_ENUM_OBJECTS,
  173. 0, size, (u64)objbuf);
  174. }
  175. EXPORT_SYMBOL_GPL(uv_bios_enum_objs);
  176. extern s64 uv_bios_enum_ports(u64 nasid, u64 obj_id, u64 size, u64 *portbuf)
  177. {
  178. return uv_bios_call(UV_BIOS_EXTRA, nasid, UV_BIOS_EXTRA_ENUM_PORTS,
  179. obj_id, size, (u64)portbuf);
  180. }
  181. EXPORT_SYMBOL_GPL(uv_bios_enum_ports);
  182. extern s64 uv_bios_get_geoinfo(u64 nasid, u64 size, u64 *buf)
  183. {
  184. return uv_bios_call(UV_BIOS_GET_GEOINFO, nasid, (u64)buf, size, 0, 0);
  185. }
  186. EXPORT_SYMBOL_GPL(uv_bios_get_geoinfo);
  187. extern s64 uv_bios_get_pci_topology(u64 size, u64 *buf)
  188. {
  189. return uv_bios_call(UV_BIOS_GET_PCI_TOPOLOGY, (u64)buf, size, 0, 0, 0);
  190. }
  191. EXPORT_SYMBOL_GPL(uv_bios_get_pci_topology);
  192. unsigned long get_uv_systab_phys(bool msg)
  193. {
  194. if ((uv_systab_phys == EFI_INVALID_TABLE_ADDR) ||
  195. !uv_systab_phys || efi_runtime_disabled()) {
  196. if (msg)
  197. pr_crit("UV: UVsystab: missing\n");
  198. return 0;
  199. }
  200. return uv_systab_phys;
  201. }
  202. int uv_bios_init(void)
  203. {
  204. unsigned long uv_systab_phys_addr;
  205. uv_systab = NULL;
  206. uv_systab_phys_addr = get_uv_systab_phys(1);
  207. if (!uv_systab_phys_addr)
  208. return -EEXIST;
  209. uv_systab = ioremap(uv_systab_phys_addr, sizeof(struct uv_systab));
  210. if (!uv_systab || strncmp(uv_systab->signature, UV_SYSTAB_SIG, 4)) {
  211. pr_err("UV: UVsystab: bad signature!\n");
  212. iounmap(uv_systab);
  213. return -EINVAL;
  214. }
  215. /* Starting with UV4 the UV systab size is variable */
  216. if (uv_systab->revision >= UV_SYSTAB_VERSION_UV4) {
  217. int size = uv_systab->size;
  218. iounmap(uv_systab);
  219. uv_systab = ioremap(uv_systab_phys_addr, size);
  220. if (!uv_systab) {
  221. pr_err("UV: UVsystab: ioremap(%d) failed!\n", size);
  222. return -EFAULT;
  223. }
  224. }
  225. pr_info("UV: UVsystab: Revision:%x\n", uv_systab->revision);
  226. return 0;
  227. }