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 8 /* keeps track of a bit address in framebuffer memory */ 9 struct fb_address { 10 void __iomem *address; 11 int bits; 12 }; 13 14 /* initialize the bit address pointer to the beginning of the frame buffer */ 15 static inline struct fb_address fb_address_init(struct fb_info *p) 16 { 17 void __iomem *base = p->screen_base; 18 struct fb_address ptr; 19 20 ptr.address = PTR_ALIGN_DOWN(base, BITS_PER_LONG / BITS_PER_BYTE); 21 ptr.bits = (base - ptr.address) * BITS_PER_BYTE; 22 return ptr; 23 } 24 25 /* framebuffer write access */ 26 static inline void fb_write_offset(unsigned long val, int offset, const struct fb_address *dst) 27 { 28 #if BITS_PER_LONG == 32 29 fb_writel(val, dst->address + offset * (BITS_PER_LONG / BITS_PER_BYTE)); 30 #else 31 fb_writeq(val, dst->address + offset * (BITS_PER_LONG / BITS_PER_BYTE)); 32 #endif 33 } 34 35 /* framebuffer read access */ 36 static inline unsigned long fb_read_offset(int offset, const struct fb_address *src) 37 { 38 #if BITS_PER_LONG == 32 39 return fb_readl(src->address + offset * (BITS_PER_LONG / BITS_PER_BYTE)); 40 #else 41 return fb_readq(src->address + offset * (BITS_PER_LONG / BITS_PER_BYTE)); 42 #endif 43 } 44