scom_wsp.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * SCOM backend for WSP
  3. *
  4. * Copyright 2010 Benjamin Herrenschmidt, IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/cpumask.h>
  12. #include <linux/io.h>
  13. #include <linux/of.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/types.h>
  16. #include <asm/cputhreads.h>
  17. #include <asm/reg_a2.h>
  18. #include <asm/scom.h>
  19. #include <asm/udbg.h>
  20. #include "wsp.h"
  21. static scom_map_t wsp_scom_map(struct device_node *dev, u64 reg, u64 count)
  22. {
  23. struct resource r;
  24. u64 xscom_addr;
  25. if (!of_get_property(dev, "scom-controller", NULL)) {
  26. pr_err("%s: device %s is not a SCOM controller\n",
  27. __func__, dev->full_name);
  28. return SCOM_MAP_INVALID;
  29. }
  30. if (of_address_to_resource(dev, 0, &r)) {
  31. pr_debug("Failed to find SCOM controller address\n");
  32. return 0;
  33. }
  34. /* Transform the SCOM address into an XSCOM offset */
  35. xscom_addr = ((reg & 0x7f000000) >> 1) | ((reg & 0xfffff) << 3);
  36. return (scom_map_t)ioremap(r.start + xscom_addr, count << 3);
  37. }
  38. static void wsp_scom_unmap(scom_map_t map)
  39. {
  40. iounmap((void *)map);
  41. }
  42. static u64 wsp_scom_read(scom_map_t map, u32 reg)
  43. {
  44. u64 __iomem *addr = (u64 __iomem *)map;
  45. return in_be64(addr + reg);
  46. }
  47. static void wsp_scom_write(scom_map_t map, u32 reg, u64 value)
  48. {
  49. u64 __iomem *addr = (u64 __iomem *)map;
  50. return out_be64(addr + reg, value);
  51. }
  52. static const struct scom_controller wsp_scom_controller = {
  53. .map = wsp_scom_map,
  54. .unmap = wsp_scom_unmap,
  55. .read = wsp_scom_read,
  56. .write = wsp_scom_write
  57. };
  58. void scom_init_wsp(void)
  59. {
  60. scom_init(&wsp_scom_controller);
  61. }