sysmem.h 978 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* SPDX-License-Identifier: GPL-2.0-only
  2. *
  3. * Virtual 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 *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 *base = p->screen_buffer;
  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. unsigned long *mem = dst->address;
  25. mem[offset] = val;
  26. }
  27. /* framebuffer read access */
  28. static inline unsigned long fb_read_offset(int offset, const struct fb_address *src)
  29. {
  30. unsigned long *mem = src->address;
  31. return mem[offset];
  32. }