scom_wsp.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <linux/of_address.h>
  17. #include <asm/cputhreads.h>
  18. #include <asm/reg_a2.h>
  19. #include <asm/scom.h>
  20. #include <asm/udbg.h>
  21. #include "wsp.h"
  22. static scom_map_t wsp_scom_map(struct device_node *dev, u64 reg, u64 count)
  23. {
  24. struct resource r;
  25. u64 xscom_addr;
  26. if (!of_get_property(dev, "scom-controller", NULL)) {
  27. pr_err("%s: device %s is not a SCOM controller\n",
  28. __func__, dev->full_name);
  29. return SCOM_MAP_INVALID;
  30. }
  31. if (of_address_to_resource(dev, 0, &r)) {
  32. pr_debug("Failed to find SCOM controller address\n");
  33. return 0;
  34. }
  35. /* Transform the SCOM address into an XSCOM offset */
  36. xscom_addr = ((reg & 0x7f000000) >> 1) | ((reg & 0xfffff) << 3);
  37. return (scom_map_t)ioremap(r.start + xscom_addr, count << 3);
  38. }
  39. static void wsp_scom_unmap(scom_map_t map)
  40. {
  41. iounmap((void *)map);
  42. }
  43. static int wsp_scom_read(scom_map_t map, u64 reg, u64 *value)
  44. {
  45. u64 __iomem *addr = (u64 __iomem *)map;
  46. *value = in_be64(addr + reg);
  47. return 0;
  48. }
  49. static int wsp_scom_write(scom_map_t map, u64 reg, u64 value)
  50. {
  51. u64 __iomem *addr = (u64 __iomem *)map;
  52. out_be64(addr + reg, value);
  53. return 0;
  54. }
  55. static const struct scom_controller wsp_scom_controller = {
  56. .map = wsp_scom_map,
  57. .unmap = wsp_scom_unmap,
  58. .read = wsp_scom_read,
  59. .write = wsp_scom_write
  60. };
  61. void scom_init_wsp(void)
  62. {
  63. scom_init(&wsp_scom_controller);
  64. }