logic_pio.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 HiSilicon Limited, All Rights Reserved.
  4. * Author: Gabriele Paoloni <gabriele.paoloni@huawei.com>
  5. * Author: Zhichang Yuan <yuanzhichang@hisilicon.com>
  6. */
  7. #ifndef __LINUX_LOGIC_PIO_H
  8. #define __LINUX_LOGIC_PIO_H
  9. #include <linux/fwnode.h>
  10. enum {
  11. LOGIC_PIO_INDIRECT, /* Indirect IO flag */
  12. LOGIC_PIO_CPU_MMIO, /* Memory-mapped IO flag */
  13. };
  14. struct logic_pio_hwaddr {
  15. struct list_head list;
  16. struct fwnode_handle *fwnode;
  17. resource_size_t hw_start;
  18. resource_size_t io_start;
  19. resource_size_t size; /* range size populated */
  20. unsigned long flags;
  21. void *hostdata;
  22. const struct logic_pio_host_ops *ops;
  23. };
  24. struct logic_pio_host_ops {
  25. u32 (*in)(void *hostdata, unsigned long addr, size_t dwidth);
  26. void (*out)(void *hostdata, unsigned long addr, u32 val,
  27. size_t dwidth);
  28. u32 (*ins)(void *hostdata, unsigned long addr, void *buffer,
  29. size_t dwidth, unsigned int count);
  30. void (*outs)(void *hostdata, unsigned long addr, const void *buffer,
  31. size_t dwidth, unsigned int count);
  32. };
  33. #ifdef CONFIG_INDIRECT_PIO
  34. u8 logic_inb(unsigned long addr);
  35. void logic_outb(u8 value, unsigned long addr);
  36. void logic_outw(u16 value, unsigned long addr);
  37. void logic_outl(u32 value, unsigned long addr);
  38. u16 logic_inw(unsigned long addr);
  39. u32 logic_inl(unsigned long addr);
  40. void logic_outb(u8 value, unsigned long addr);
  41. void logic_outw(u16 value, unsigned long addr);
  42. void logic_outl(u32 value, unsigned long addr);
  43. void logic_insb(unsigned long addr, void *buffer, unsigned int count);
  44. void logic_insl(unsigned long addr, void *buffer, unsigned int count);
  45. void logic_insw(unsigned long addr, void *buffer, unsigned int count);
  46. void logic_outsb(unsigned long addr, const void *buffer, unsigned int count);
  47. void logic_outsw(unsigned long addr, const void *buffer, unsigned int count);
  48. void logic_outsl(unsigned long addr, const void *buffer, unsigned int count);
  49. #ifndef inb
  50. #define inb logic_inb
  51. #endif
  52. #ifndef inw
  53. #define inw logic_inw
  54. #endif
  55. #ifndef inl
  56. #define inl logic_inl
  57. #endif
  58. #ifndef outb
  59. #define outb logic_outb
  60. #endif
  61. #ifndef outw
  62. #define outw logic_outw
  63. #endif
  64. #ifndef outl
  65. #define outl logic_outl
  66. #endif
  67. #ifndef insb
  68. #define insb logic_insb
  69. #endif
  70. #ifndef insw
  71. #define insw logic_insw
  72. #endif
  73. #ifndef insl
  74. #define insl logic_insl
  75. #endif
  76. #ifndef outsb
  77. #define outsb logic_outsb
  78. #endif
  79. #ifndef outsw
  80. #define outsw logic_outsw
  81. #endif
  82. #ifndef outsl
  83. #define outsl logic_outsl
  84. #endif
  85. /*
  86. * We reserve 0x4000 bytes for Indirect IO as so far this library is only
  87. * used by the HiSilicon LPC Host. If needed, we can reserve a wider IO
  88. * area by redefining the macro below.
  89. */
  90. #define PIO_INDIRECT_SIZE 0x4000
  91. #else
  92. #define PIO_INDIRECT_SIZE 0
  93. #endif /* CONFIG_INDIRECT_PIO */
  94. #define MMIO_UPPER_LIMIT (IO_SPACE_LIMIT - PIO_INDIRECT_SIZE)
  95. struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode);
  96. unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode,
  97. resource_size_t hw_addr, resource_size_t size);
  98. int logic_pio_register_range(struct logic_pio_hwaddr *newrange);
  99. void logic_pio_unregister_range(struct logic_pio_hwaddr *range);
  100. resource_size_t logic_pio_to_hwaddr(unsigned long pio);
  101. unsigned long logic_pio_trans_cpuaddr(resource_size_t hw_addr);
  102. #endif /* __LINUX_LOGIC_PIO_H */