From 7815d33433569aa98844af2b3df4b3f5b26373a2 Mon Sep 17 00:00:00 2001 From: emaste Date: Thu, 4 Sep 2014 18:43:40 +0000 Subject: [PATCH] MFC fbd(4) and vt_fb disentanglement: r268472 (ray): Should check fb_read method presence instead of double check for fb_write. r269620 (nwhitehorn): Retire various intertwined bits of fbd(4) and vt_fb, in particular the pixel modification indirection. No actual drivers use it and those that might (e.g. creatorfb) use custom implementations of vd_bitbltchr(). Relnotes: No Sponsored by: The FreeBSD Foundation git-svn-id: svn://svn.freebsd.org/base/stable/10@271117 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/dev/fb/fbd.c | 111 +++------------------------------ sys/dev/vt/hw/efifb/efifb.c | 4 -- sys/dev/vt/hw/fb/vt_early_fb.c | 1 - sys/dev/vt/hw/fb/vt_fb.c | 86 ++++++++++++++++++------- sys/dev/vt/hw/fb/vt_fb.h | 2 - sys/dev/vt/hw/ofwfb/ofwfb.c | 1 - sys/powerpc/ps3/ps3_syscons.c | 6 +- sys/sys/fbio.h | 21 ------- 8 files changed, 71 insertions(+), 161 deletions(-) diff --git a/sys/dev/fb/fbd.c b/sys/dev/fb/fbd.c index 753923bf4..8c6b036f4 100644 --- a/sys/dev/fb/fbd.c +++ b/sys/dev/fb/fbd.c @@ -165,6 +165,10 @@ fb_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot, struct fb_info *info; info = dev->si_drv1; + + if ((info->fb_flags & FB_FLAG_NOMMAP) || info->fb_pbase == 0) + return (ENODEV); + if (offset < info->fb_size) { *paddr = info->fb_pbase + offset; return (0); @@ -172,103 +176,6 @@ fb_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot, return (EINVAL); } - -static void -vt_fb_mem_wr1(struct fb_info *sc, uint32_t o, uint8_t v) -{ - - KASSERT((o < sc->fb_size), ("Offset %#08x out of fb size", o)); - *(uint8_t *)(sc->fb_vbase + o) = v; -} - -static void -vt_fb_mem_wr2(struct fb_info *sc, uint32_t o, uint16_t v) -{ - - KASSERT((o < sc->fb_size), ("Offset %#08x out of fb size", o)); - *(uint16_t *)(sc->fb_vbase + o) = v; -} - -static void -vt_fb_mem_wr4(struct fb_info *sc, uint32_t o, uint32_t v) -{ - - KASSERT((o < sc->fb_size), ("Offset %#08x out of fb size", o)); - *(uint32_t *)(sc->fb_vbase + o) = v; -} - -static void -vt_fb_mem_copy(struct fb_info *sc, uint32_t offset_to, uint32_t offset_from, - uint32_t size) -{ - - memmove((void *)(sc->fb_vbase + offset_to), (void *)(sc->fb_vbase + - offset_from), size); -} - -static void -vt_fb_indir_wr1(struct fb_info *sc, uint32_t o, uint8_t v) -{ - - KASSERT((o < sc->fb_size), ("Offset %#08x out of fb size", o)); - sc->fb_write(sc->fb_priv, o, &v, 1); -} - -static void -vt_fb_indir_wr2(struct fb_info *sc, uint32_t o, uint16_t v) -{ - - KASSERT((o < sc->fb_size), ("Offset %#08x out of fb size", o)); - sc->fb_write(sc->fb_priv, o, &v, 2); -} - -static void -vt_fb_indir_wr4(struct fb_info *sc, uint32_t o, uint32_t v) -{ - - KASSERT((o < sc->fb_size), ("Offset %#08x out of fb size", o)); - sc->fb_write(sc->fb_priv, o, &v, 4); -} - -static void -vt_fb_indir_copy(struct fb_info *sc, uint32_t offset_to, uint32_t offset_from, - uint32_t size) -{ - - sc->copy(sc->fb_priv, offset_to, offset_from, size); -} - -int -fb_probe(struct fb_info *info) -{ - - if (info->fb_size == 0) - return (ENXIO); - - if (info->fb_write != NULL) { - if (info->fb_write == NULL) { - return (EINVAL); - } - info->fb_flags |= FB_FLAG_NOMMAP; - info->wr1 = &vt_fb_indir_wr1; - info->wr2 = &vt_fb_indir_wr2; - info->wr4 = &vt_fb_indir_wr4; - info->copy = &vt_fb_indir_copy; - } else if (info->fb_vbase != 0) { - if (info->fb_pbase == 0) { - info->fb_flags |= FB_FLAG_NOMMAP; - } - info->wr1 = &vt_fb_mem_wr1; - info->wr2 = &vt_fb_mem_wr2; - info->wr4 = &vt_fb_mem_wr4; - info->copy = &vt_fb_mem_copy; - } else - return (ENXIO); - - return (0); -} - - static int fb_init(struct fb_list_entry *entry, int unit) { @@ -329,10 +236,6 @@ fbd_register(struct fb_info* info) return (0); } - err = fb_probe(info); - if (err) - return (err); - entry = malloc(sizeof(struct fb_list_entry), M_DEVBUF, M_WAITOK|M_ZERO); entry->fb_info = info; @@ -342,8 +245,10 @@ fbd_register(struct fb_info* info) if (err) return (err); - if (first) - vt_fb_attach(info); + if (first) { + if (vt_fb_attach(info) == CN_DEAD) + return (ENXIO); + } return (0); } diff --git a/sys/dev/vt/hw/efifb/efifb.c b/sys/dev/vt/hw/efifb/efifb.c index b6ea1dbe4..546bbf6db 100644 --- a/sys/dev/vt/hw/efifb/efifb.c +++ b/sys/dev/vt/hw/efifb/efifb.c @@ -154,12 +154,8 @@ vt_efifb_init(struct vt_device *vd) info->fb_width = MIN(info->fb_width, VT_FB_DEFAULT_WIDTH); info->fb_height = MIN(info->fb_height, VT_FB_DEFAULT_HEIGHT); - fb_probe(info); vt_fb_init(vd); - /* Clear the screen. */ - vt_fb_blank(vd, TC_BLACK); - return (CN_INTERNAL); } diff --git a/sys/dev/vt/hw/fb/vt_early_fb.c b/sys/dev/vt/hw/fb/vt_early_fb.c index 5e818f7f4..a618ca3bd 100644 --- a/sys/dev/vt/hw/fb/vt_early_fb.c +++ b/sys/dev/vt/hw/fb/vt_early_fb.c @@ -296,7 +296,6 @@ vt_efb_init(struct vt_device *vd) #else vt_efb_initialize(info); #endif - fb_probe(info); vt_fb_init(vd); return (CN_INTERNAL); diff --git a/sys/dev/vt/hw/fb/vt_fb.c b/sys/dev/vt/hw/fb/vt_fb.c index 61545138b..1c4b9a74a 100644 --- a/sys/dev/vt/hw/fb/vt_fb.c +++ b/sys/dev/vt/hw/fb/vt_fb.c @@ -61,6 +61,30 @@ static struct vt_driver vt_fb_driver = { VT_DRIVER_DECLARE(vt_fb, vt_fb_driver); +static void +vt_fb_mem_wr1(struct fb_info *sc, uint32_t o, uint8_t v) +{ + + KASSERT((o < sc->fb_size), ("Offset %#08x out of fb size", o)); + *(uint8_t *)(sc->fb_vbase + o) = v; +} + +static void +vt_fb_mem_wr2(struct fb_info *sc, uint32_t o, uint16_t v) +{ + + KASSERT((o < sc->fb_size), ("Offset %#08x out of fb size", o)); + *(uint16_t *)(sc->fb_vbase + o) = v; +} + +static void +vt_fb_mem_wr4(struct fb_info *sc, uint32_t o, uint32_t v) +{ + + KASSERT((o < sc->fb_size), ("Offset %#08x out of fb size", o)); + *(uint32_t *)(sc->fb_vbase + o) = v; +} + int vt_fb_ioctl(struct vt_device *vd, u_long cmd, caddr_t data, struct thread *td) { @@ -134,20 +158,22 @@ vt_fb_setpixel(struct vt_device *vd, int x, int y, term_color_t color) c = info->fb_cmap[color]; o = info->fb_stride * y + x * FBTYPE_GET_BYTESPP(info); + KASSERT((info->fb_vbase != 0), ("Unmapped framebuffer")); + switch (FBTYPE_GET_BYTESPP(info)) { case 1: - info->wr1(info, o, c); + vt_fb_mem_wr1(info, o, c); break; case 2: - info->wr2(info, o, c); + vt_fb_mem_wr2(info, o, c); break; case 3: - info->wr1(info, o, (c >> 16) & 0xff); - info->wr1(info, o + 1, (c >> 8) & 0xff); - info->wr1(info, o + 2, c & 0xff); + vt_fb_mem_wr1(info, o, (c >> 16) & 0xff); + vt_fb_mem_wr1(info, o + 1, (c >> 8) & 0xff); + vt_fb_mem_wr1(info, o + 2, c & 0xff); break; case 4: - info->wr4(info, o, c); + vt_fb_mem_wr4(info, o, c); break; default: /* panic? */ @@ -183,32 +209,34 @@ vt_fb_blank(struct vt_device *vd, term_color_t color) info = vd->vd_softc; c = info->fb_cmap[color]; + KASSERT((info->fb_vbase != 0), ("Unmapped framebuffer")); + switch (FBTYPE_GET_BYTESPP(info)) { case 1: for (h = 0; h < info->fb_height; h++) for (o = 0; o < info->fb_stride; o++) - info->wr1(info, h*info->fb_stride + o, c); + vt_fb_mem_wr1(info, h*info->fb_stride + o, c); break; case 2: for (h = 0; h < info->fb_height; h++) for (o = 0; o < info->fb_stride; o += 2) - info->wr2(info, h*info->fb_stride + o, c); + vt_fb_mem_wr2(info, h*info->fb_stride + o, c); break; case 3: for (h = 0; h < info->fb_height; h++) for (o = 0; o < info->fb_stride; o += 3) { - info->wr1(info, h*info->fb_stride + o, + vt_fb_mem_wr1(info, h*info->fb_stride + o, (c >> 16) & 0xff); - info->wr1(info, h*info->fb_stride + o + 1, + vt_fb_mem_wr1(info, h*info->fb_stride + o + 1, (c >> 8) & 0xff); - info->wr1(info, h*info->fb_stride + o + 2, + vt_fb_mem_wr1(info, h*info->fb_stride + o + 2, c & 0xff); } break; case 4: for (h = 0; h < info->fb_height; h++) for (o = 0; o < info->fb_stride; o += 4) - info->wr4(info, h*info->fb_stride + o, c); + vt_fb_mem_wr4(info, h*info->fb_stride + o, c); break; default: /* panic? */ @@ -241,6 +269,8 @@ vt_fb_bitbltchr(struct vt_device *vd, const uint8_t *src, const uint8_t *mask, info->fb_height)) return; + KASSERT((info->fb_vbase != 0), ("Unmapped framebuffer")); + line = (info->fb_stride * top) + (left * bpp); for (l = 0; l < height; l++) { ch = src; @@ -254,19 +284,19 @@ vt_fb_bitbltchr(struct vt_device *vd, const uint8_t *src, const uint8_t *mask, switch(bpp) { case 1: - info->wr1(info, o, cc); + vt_fb_mem_wr1(info, o, cc); break; case 2: - info->wr2(info, o, cc); + vt_fb_mem_wr2(info, o, cc); break; case 3: /* Packed mode, so unaligned. Byte access. */ - info->wr1(info, o, (cc >> 16) & 0xff); - info->wr1(info, o + 1, (cc >> 8) & 0xff); - info->wr1(info, o + 2, cc & 0xff); + vt_fb_mem_wr1(info, o, (cc >> 16) & 0xff); + vt_fb_mem_wr1(info, o + 1, (cc >> 8) & 0xff); + vt_fb_mem_wr1(info, o + 2, cc & 0xff); break; case 4: - info->wr4(info, o, cc); + vt_fb_mem_wr4(info, o, cc); break; default: /* panic? */ @@ -303,6 +333,8 @@ vt_fb_maskbitbltchr(struct vt_device *vd, const uint8_t *src, const uint8_t *mas info->fb_height)) return; + KASSERT((info->fb_vbase != 0), ("Unmapped framebuffer")); + line = (info->fb_stride * top) + (left * bpp); for (l = 0; l < height; l++) { ch = src; @@ -325,19 +357,19 @@ vt_fb_maskbitbltchr(struct vt_device *vd, const uint8_t *src, const uint8_t *mas switch(bpp) { case 1: - info->wr1(info, o, cc); + vt_fb_mem_wr1(info, o, cc); break; case 2: - info->wr2(info, o, cc); + vt_fb_mem_wr2(info, o, cc); break; case 3: /* Packed mode, so unaligned. Byte access. */ - info->wr1(info, o, (cc >> 16) & 0xff); - info->wr1(info, o + 1, (cc >> 8) & 0xff); - info->wr1(info, o + 2, cc & 0xff); + vt_fb_mem_wr1(info, o, (cc >> 16) & 0xff); + vt_fb_mem_wr1(info, o + 1, (cc >> 8) & 0xff); + vt_fb_mem_wr1(info, o + 2, cc & 0xff); break; case 4: - info->wr4(info, o, cc); + vt_fb_mem_wr4(info, o, cc); break; default: /* panic? */ @@ -393,6 +425,12 @@ vt_fb_init(struct vt_device *vd) vd->vd_height = info->fb_height; vd->vd_width = info->fb_width; + if (info->fb_size == 0) + return (CN_DEAD); + + if (info->fb_pbase == 0) + info->fb_flags |= FB_FLAG_NOMMAP; + if (info->fb_cmsize <= 0) { err = vt_fb_init_cmap(info->fb_cmap, FBTYPE_GET_BPP(info)); if (err) diff --git a/sys/dev/vt/hw/fb/vt_fb.h b/sys/dev/vt/hw/fb/vt_fb.h index 1ffb250cf..9b1d56bf7 100644 --- a/sys/dev/vt/hw/fb/vt_fb.h +++ b/sys/dev/vt/hw/fb/vt_fb.h @@ -36,8 +36,6 @@ int vt_fb_attach(struct fb_info *info); void vt_fb_resume(void); void vt_fb_suspend(void); -int fb_probe(struct fb_info *info); - vd_init_t vt_fb_init; vd_blank_t vt_fb_blank; vd_bitbltchr_t vt_fb_bitbltchr; diff --git a/sys/dev/vt/hw/ofwfb/ofwfb.c b/sys/dev/vt/hw/ofwfb/ofwfb.c index c7c50e103..bec89e4ef 100644 --- a/sys/dev/vt/hw/ofwfb/ofwfb.c +++ b/sys/dev/vt/hw/ofwfb/ofwfb.c @@ -399,7 +399,6 @@ ofwfb_init(struct vt_device *vd) sc->fb.fb_pbase = fb_phys; ofwfb_initialize(vd); - fb_probe(&sc->fb); vt_fb_init(vd); return (CN_INTERNAL); diff --git a/sys/powerpc/ps3/ps3_syscons.c b/sys/powerpc/ps3/ps3_syscons.c index 41388ef06..047a5ce77 100644 --- a/sys/powerpc/ps3/ps3_syscons.c +++ b/sys/powerpc/ps3/ps3_syscons.c @@ -188,12 +188,8 @@ ps3fb_init(struct vt_device *vd) lv1_gpu_context_attribute(sc->sc_fbcontext, L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP, 1, 0, 0, 0); - fb_probe(&sc->fb_info); - sc->fb_info.fb_flags &= ~FB_FLAG_NOMMAP; /* Set wrongly by fb_probe */ vt_fb_init(vd); - - /* Clear the screen. */ - vt_fb_blank(vd, TC_BLACK); + sc->fb_info.fb_flags &= ~FB_FLAG_NOMMAP; /* Set wrongly by vt_fb_init */ return (CN_INTERNAL); } diff --git a/sys/sys/fbio.h b/sys/sys/fbio.h index d1f12dd88..a88e305a4 100644 --- a/sys/sys/fbio.h +++ b/sys/sys/fbio.h @@ -115,19 +115,6 @@ struct fb_info; typedef int fb_enter_t(void *priv); typedef int fb_leave_t(void *priv); -typedef int fb_write_t(void *priv, int offset, void *data, int size); -typedef int fb_read_t(void *priv, int offset, void *data, int size); - -/* XXX: should use priv instead of fb_info too. */ -typedef void fb_copy_t(struct fb_info *sc, uint32_t offset_to, uint32_t offset_from, - uint32_t size); -typedef void fb_wr1_t(struct fb_info *sc, uint32_t offset, uint8_t value); -typedef void fb_wr2_t(struct fb_info *sc, uint32_t offset, uint16_t value); -typedef void fb_wr4_t(struct fb_info *sc, uint32_t offset, uint32_t value); - -typedef int fb_ioctl_t(struct cdev *, u_long, caddr_t, int, struct thread *); -typedef int fb_mmap_t(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, - int prot, vm_memattr_t *memattr); struct fb_info { /* Raw copy of fbtype. Do not change. */ @@ -138,16 +125,8 @@ struct fb_info { int fb_cmsize; /* size of color map (entries) */ int fb_size; /* total size in bytes */ - /* Methods. */ - fb_write_t *fb_write; /* if NULL, direct mem write. */ - fb_read_t *fb_read; /* if NULL, direct mem read. */ - struct cdev *fb_cdev; - fb_wr1_t *wr1; - fb_wr2_t *wr2; - fb_wr4_t *wr4; - fb_copy_t *copy; fb_enter_t *enter; fb_leave_t *leave; -- 2.45.0