logic_iomem.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2021 Intel Corporation
  4. * Author: [email protected]
  5. */
  6. #ifndef __LOGIC_IOMEM_H
  7. #define __LOGIC_IOMEM_H
  8. #include <linux/types.h>
  9. #include <linux/ioport.h>
  10. /**
  11. * struct logic_iomem_ops - emulated IO memory ops
  12. * @read: read an 8, 16, 32 or 64 bit quantity from the given offset,
  13. * size is given in bytes (1, 2, 4 or 8)
  14. * (64-bit only necessary if CONFIG_64BIT is set)
  15. * @write: write an 8, 16 32 or 64 bit quantity to the given offset,
  16. * size is given in bytes (1, 2, 4 or 8)
  17. * (64-bit only necessary if CONFIG_64BIT is set)
  18. * @set: optional, for memset_io()
  19. * @copy_from: optional, for memcpy_fromio()
  20. * @copy_to: optional, for memcpy_toio()
  21. * @unmap: optional, this region is getting unmapped
  22. */
  23. struct logic_iomem_ops {
  24. unsigned long (*read)(void *priv, unsigned int offset, int size);
  25. void (*write)(void *priv, unsigned int offset, int size,
  26. unsigned long val);
  27. void (*set)(void *priv, unsigned int offset, u8 value, int size);
  28. void (*copy_from)(void *priv, void *buffer, unsigned int offset,
  29. int size);
  30. void (*copy_to)(void *priv, unsigned int offset, const void *buffer,
  31. int size);
  32. void (*unmap)(void *priv);
  33. };
  34. /**
  35. * struct logic_iomem_region_ops - ops for an IO memory handler
  36. * @map: map a range in the registered IO memory region, must
  37. * fill *ops with the ops and may fill *priv to be passed
  38. * to the ops. The offset is given as the offset into the
  39. * registered resource region.
  40. * The return value is negative for errors, or >= 0 for
  41. * success. On success, the return value is added to the
  42. * offset for later ops, to allow for partial mappings.
  43. */
  44. struct logic_iomem_region_ops {
  45. long (*map)(unsigned long offset, size_t size,
  46. const struct logic_iomem_ops **ops,
  47. void **priv);
  48. };
  49. /**
  50. * logic_iomem_add_region - register an IO memory region
  51. * @resource: the resource description for this region
  52. * @ops: the IO memory mapping ops for this resource
  53. */
  54. int logic_iomem_add_region(struct resource *resource,
  55. const struct logic_iomem_region_ops *ops);
  56. #endif /* __LOGIC_IOMEM_H */