From 2723123cafb705c78b5251329bdd932ca6b834d9 Mon Sep 17 00:00:00 2001 From: kettenis Date: Mon, 27 Aug 2018 09:30:07 +0000 Subject: [PATCH] Add an interface that allows drivers to claim a framebuffer and check whether another driver has already claimed a framebuffer. Use this in radeondrm(4) and simplefb(4) to prevent the latter from attaching if radeondrm(4) is attached to the hardware that provides the framebuffer set up by the firmware. ok mlarkin@ --- sys/dev/fdt/simplefb.c | 6 ++++- sys/dev/pci/drm/radeon/radeon_kms.c | 5 ++++ sys/dev/rasops/rasops.c | 38 ++++++++++++++++++++++++++++- sys/dev/rasops/rasops.h | 4 ++- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/sys/dev/fdt/simplefb.c b/sys/dev/fdt/simplefb.c index 3be2ac6d004..6f031953a3c 100644 --- a/sys/dev/fdt/simplefb.c +++ b/sys/dev/fdt/simplefb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: simplefb.c,v 1.4 2018/07/31 17:25:55 fcambus Exp $ */ +/* $OpenBSD: simplefb.c,v 1.5 2018/08/27 09:30:07 kettenis Exp $ */ /* * Copyright (c) 2016 Mark Kettenis * @@ -110,6 +110,10 @@ simplefb_match(struct device *parent, void *match, void *aux) { struct fdt_attach_args *faa = aux; + /* Don't attach if another driver already claimed our framebuffer. */ + if (faa->fa_nreg > 0 && rasops_check_framebuffer(faa->fa_reg[0].addr)) + return 0; + return OF_is_compatible(faa->fa_node, "simple-framebuffer"); } diff --git a/sys/dev/pci/drm/radeon/radeon_kms.c b/sys/dev/pci/drm/radeon/radeon_kms.c index acc0fbc95cb..f9e72e449cd 100644 --- a/sys/dev/pci/drm/radeon/radeon_kms.c +++ b/sys/dev/pci/drm/radeon/radeon_kms.c @@ -435,6 +435,7 @@ radeondrm_attach_kms(struct device *parent, struct device *self, void *aux) pcireg_t type; int i; uint8_t rmmio_bar; + paddr_t fb_aper; #if !defined(__sparc64__) pcireg_t addr, mask; int s; @@ -660,6 +661,10 @@ radeondrm_attach_kms(struct device *parent, struct device *self, void *aux) } #endif + fb_aper = bus_space_mmap(rdev->memt, rdev->fb_aper_offset, 0, 0, 0); + if (fb_aper != -1) + rasops_claim_framebuffer(fb_aper, rdev->fb_aper_size, self); + rdev->shutdown = true; config_mountroot(self, radeondrm_attachhook); } diff --git a/sys/dev/rasops/rasops.c b/sys/dev/rasops/rasops.c index e483ff074ad..ec2c7bac4ca 100644 --- a/sys/dev/rasops/rasops.c +++ b/sys/dev/rasops/rasops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rasops.c,v 1.55 2018/08/25 12:23:45 kettenis Exp $ */ +/* $OpenBSD: rasops.c,v 1.56 2018/08/27 09:30:07 kettenis Exp $ */ /* $NetBSD: rasops.c,v 1.35 2001/02/02 06:01:01 marcus Exp $ */ /*- @@ -1968,3 +1968,39 @@ rasops_scrollback(void *v, void *cookie, int lines) if (scr->rs_crow != -1 && scr->rs_visibleoffset == scr->rs_dispoffset) rasops_cursor(ri, 1, scr->rs_crow, scr->rs_ccol); } + +struct rasops_framebuffer { + SLIST_ENTRY(rasops_framebuffer) rf_list; + paddr_t rf_base; + psize_t rf_size; + struct device *rf_dev; +}; + +SLIST_HEAD(, rasops_framebuffer) rasops_framebuffers = + SLIST_HEAD_INITIALIZER(&rasops_framebuffers); + +void +rasops_claim_framebuffer(paddr_t base, psize_t size, struct device *dev) +{ + struct rasops_framebuffer *rf; + + rf = malloc(sizeof(*rf), M_DEVBUF, M_WAITOK); + rf->rf_base = base; + rf->rf_size = size; + rf->rf_dev = dev; + + SLIST_INSERT_HEAD(&rasops_framebuffers, rf, rf_list); +} + +int +rasops_check_framebuffer(paddr_t base) +{ + struct rasops_framebuffer *rf; + + SLIST_FOREACH(rf, &rasops_framebuffers, rf_list) { + if (base >= rf->rf_base && base < rf->rf_base + rf->rf_size) + return 1; + } + + return 0; +} diff --git a/sys/dev/rasops/rasops.h b/sys/dev/rasops/rasops.h index bab120e5309..89de261be89 100644 --- a/sys/dev/rasops/rasops.h +++ b/sys/dev/rasops/rasops.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rasops.h,v 1.22 2018/04/27 21:36:12 jcs Exp $ */ +/* $OpenBSD: rasops.h,v 1.23 2018/08/27 09:30:07 kettenis Exp $ */ /* $NetBSD: rasops.h,v 1.13 2000/06/13 13:36:54 ad Exp $ */ /*- @@ -179,6 +179,8 @@ int rasops_load_font(void *, void *, struct wsdisplay_font *); int rasops_list_font(void *, struct wsdisplay_font *); int rasops_getchar(void *, int, int, struct wsdisplay_charcell *); void rasops_scrollback(void *, void *, int); +void rasops_claim_framebuffer(paddr_t, psize_t, struct device *); +int rasops_check_framebuffer(paddr_t); extern const u_char rasops_isgray[16]; extern const u_char rasops_cmap[256*3]; -- 2.20.1