gsihal.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include "gsihal_i.h"
  6. #include "gsihal_reg.h"
  7. struct gsihal_context *gsihal_ctx;
  8. int gsihal_init(enum gsi_ver gsi_ver, void __iomem *base)
  9. {
  10. int result = 0;
  11. GSIDBG("initializing GSI HAL, GSI ver %d, base = %pK\n",
  12. gsi_ver, base);
  13. if (gsihal_ctx) {
  14. GSIDBG("gsihal already initialized\n");
  15. if (base != gsihal_ctx->base) {
  16. GSIERR(
  17. "base address of early init is differnet.\n"
  18. );
  19. WARN_ON(1);
  20. }
  21. result = -EEXIST;
  22. goto bail_err_exit;
  23. }
  24. if (gsi_ver < GSI_VER_1_0 || gsi_ver >= GSI_VER_MAX) {
  25. GSIERR("invalid GSI version %d\n", gsi_ver);
  26. result = -EINVAL;
  27. goto bail_err_exit;
  28. }
  29. if (!base) {
  30. GSIERR("invalid memory io mapping addr\n");
  31. result = -EINVAL;
  32. goto bail_err_exit;
  33. }
  34. gsihal_ctx = kzalloc(sizeof(*gsihal_ctx), GFP_KERNEL);
  35. if (!gsihal_ctx) {
  36. GSIERR("kzalloc err for gsihal_ctx\n");
  37. result = -ENOMEM;
  38. goto bail_err_exit;
  39. }
  40. gsihal_ctx->gsi_ver = gsi_ver;
  41. gsihal_ctx->base = base;
  42. if (gsihal_reg_init(gsi_ver)) {
  43. GSIERR("failed to initialize gsihal regs\n");
  44. result = -EINVAL;
  45. goto bail_free_ctx;
  46. }
  47. return 0;
  48. bail_free_ctx:
  49. kfree(gsihal_ctx);
  50. gsihal_ctx = NULL;
  51. bail_err_exit:
  52. return result;
  53. }
  54. void gsihal_destroy(void)
  55. {
  56. GSIDBG("Entry\n");
  57. kfree(gsihal_ctx);
  58. gsihal_ctx = NULL;
  59. }