cfbmem.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* SPDX-License-Identifier: GPL-2.0-only
  2. *
  3. * I/O memory framebuffer access for drawing routines
  4. *
  5. * Copyright (C) 2025 Zsolt Kajtar (soci@c64.rulez.org)
  6. */
  7. /* keeps track of a bit address in framebuffer memory */
  8. struct fb_address {
  9. void __iomem *address;
  10. int bits;
  11. };
  12. /* initialize the bit address pointer to the beginning of the frame buffer */
  13. static inline struct fb_address fb_address_init(struct fb_info *p)
  14. {
  15. void __iomem *base = p->screen_base;
  16. struct fb_address ptr;
  17. ptr.address = PTR_ALIGN_DOWN(base, BITS_PER_LONG / BITS_PER_BYTE);
  18. ptr.bits = (base - ptr.address) * BITS_PER_BYTE;
  19. return ptr;
  20. }
  21. /* framebuffer write access */
  22. static inline void fb_write_offset(unsigned long val, int offset, const struct fb_address *dst)
  23. {
  24. #if BITS_PER_LONG == 32
  25. fb_writel(val, dst->address + offset * (BITS_PER_LONG / BITS_PER_BYTE));
  26. #else
  27. fb_writeq(val, dst->address + offset * (BITS_PER_LONG / BITS_PER_BYTE));
  28. #endif
  29. }
  30. /* framebuffer read access */
  31. static inline unsigned long fb_read_offset(int offset, const struct fb_address *src)
  32. {
  33. #if BITS_PER_LONG == 32
  34. return fb_readl(src->address + offset * (BITS_PER_LONG / BITS_PER_BYTE));
  35. #else
  36. return fb_readq(src->address + offset * (BITS_PER_LONG / BITS_PER_BYTE));
  37. #endif
  38. }