Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752558Ab1DRUFh (ORCPT ); Mon, 18 Apr 2011 16:05:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47490 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751556Ab1DRUFf (ORCPT ); Mon, 18 Apr 2011 16:05:35 -0400 From: Matthew Garrett To: linux-kernel@vger.kernel.org Cc: dri-devel@lists.freedesktop.org, airlied@linux.ie, Matthew Garrett , Matt Turner Subject: [PATCH] drm: Add a driver for kvm emulated Cirrus Date: Mon, 18 Apr 2011 16:04:54 -0400 Message-Id: <1303157094-11425-1-git-send-email-mjg@redhat.com> X-SA-Do-Not-Run: Yes X-SA-Exim-Connect-IP: 66.187.233.202 X-SA-Exim-Mail-From: mjg@redhat.com X-SA-Exim-Scanned: No (on cavan.codon.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 41028 Lines: 1506 qemu-kvm emulates a Cirrus GPU, including its acceleration engine. We typically then run a Cirrus-specific X driver on top of this, which turns requests into commands and sends them to the emulated accelerator. This all seems to be unnecessary overhead given that we're just going to end up writing to memory from the host instead, and performance is almost certainly going to be better using an unaccelerated framebuffer and a guest-side shadow. This patch provides a simple modesetting-only KMS driver for the hardware emulated in qemu-kvm. It's stripped down to the point where it's able to program the emulation, but would almost certainly fail miserably if asked to run on real hardware. It's intended to reduce virt overhead slightly, but also to serve as a template to writing a basic KMS driver. The code and structure are heavily derived from Matt Turner's glint driver, with the modesetting code cribbed from cirrusfb (hence the license). Signed-off-by: Matthew Garrett Cc: Matt Turner --- drivers/gpu/drm/Kconfig | 8 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/cirrus/Makefile | 6 + drivers/gpu/drm/cirrus/cirrus.h | 40 ++++ drivers/gpu/drm/cirrus/cirrus_crtc.c | 277 +++++++++++++++++++++++++++ drivers/gpu/drm/cirrus/cirrus_device.c | 111 +++++++++++ drivers/gpu/drm/cirrus/cirrus_display.c | 70 +++++++ drivers/gpu/drm/cirrus/cirrus_drv.c | 91 +++++++++ drivers/gpu/drm/cirrus/cirrus_drv.h | 127 ++++++++++++ drivers/gpu/drm/cirrus/cirrus_encoder.c | 139 ++++++++++++++ drivers/gpu/drm/cirrus/cirrus_fbdev.c | 214 +++++++++++++++++++++ drivers/gpu/drm/cirrus/cirrus_framebuffer.c | 48 +++++ drivers/gpu/drm/cirrus/cirrus_kms.c | 59 ++++++ drivers/gpu/drm/cirrus/cirrus_mode.h | 54 +++++ drivers/gpu/drm/cirrus/cirrus_vga.c | 102 ++++++++++ 15 files changed, 1347 insertions(+), 0 deletions(-) create mode 100644 drivers/gpu/drm/cirrus/Makefile create mode 100644 drivers/gpu/drm/cirrus/cirrus.h create mode 100644 drivers/gpu/drm/cirrus/cirrus_crtc.c create mode 100644 drivers/gpu/drm/cirrus/cirrus_device.c create mode 100644 drivers/gpu/drm/cirrus/cirrus_display.c create mode 100644 drivers/gpu/drm/cirrus/cirrus_drv.c create mode 100644 drivers/gpu/drm/cirrus/cirrus_drv.h create mode 100644 drivers/gpu/drm/cirrus/cirrus_encoder.c create mode 100644 drivers/gpu/drm/cirrus/cirrus_fbdev.c create mode 100644 drivers/gpu/drm/cirrus/cirrus_framebuffer.c create mode 100644 drivers/gpu/drm/cirrus/cirrus_kms.c create mode 100644 drivers/gpu/drm/cirrus/cirrus_mode.h create mode 100644 drivers/gpu/drm/cirrus/cirrus_vga.c diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index c58f691..2f54d2f 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -126,6 +126,14 @@ config DRM_I915_KMS the driver to bind to PCI devices, which precludes loading things like intelfb. +config DRM_KVM_CIRRUS + tristate "Kernel modesetting driver for qemu-kvm Cirrus emulation" + depends on DRM && PCI + select FB_CFB_FILLRECT + select FB_CFB_COPYAREA + select FB_CFB_IMAGEBLIT + select DRM_KMS_HELPER + config DRM_MGA tristate "Matrox g200/g400" depends on DRM && PCI diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 89cf05a..11e486f 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -30,6 +30,7 @@ obj-$(CONFIG_DRM_RADEON)+= radeon/ obj-$(CONFIG_DRM_MGA) += mga/ obj-$(CONFIG_DRM_I810) += i810/ obj-$(CONFIG_DRM_I915) += i915/ +obj-$(CONFIG_DRM_KVM_CIRRUS) += cirrus/ obj-$(CONFIG_DRM_SIS) += sis/ obj-$(CONFIG_DRM_SAVAGE)+= savage/ obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/ diff --git a/drivers/gpu/drm/cirrus/Makefile b/drivers/gpu/drm/cirrus/Makefile new file mode 100644 index 0000000..126dd50 --- /dev/null +++ b/drivers/gpu/drm/cirrus/Makefile @@ -0,0 +1,6 @@ +ccflags-y := -Iinclude/drm +cirrus-y := cirrus_crtc.o cirrus_encoder.o cirrus_device.o cirrus_display.o \ + cirrus_drv.o cirrus_fbdev.o cirrus_framebuffer.o \ + cirrus_kms.o cirrus_vga.o + +obj-$(CONFIG_DRM_KVM_CIRRUS) += cirrus.o diff --git a/drivers/gpu/drm/cirrus/cirrus.h b/drivers/gpu/drm/cirrus/cirrus.h new file mode 100644 index 0000000..44ad60a --- /dev/null +++ b/drivers/gpu/drm/cirrus/cirrus.h @@ -0,0 +1,40 @@ +/* + * Copyright 2010 Matt Turner. + * Copyright 2011 Red Hat + * + * This file is subject to the terms and conditions of the GNU General + * Public License version 2. See the file COPYING in the main + * directory of this archive for more details. + * + * Authors: Matthew Garrett + * Matt Turner + */ +#ifndef __CIRRUS_H__ +#define __CIRRUS_H__ + +#include "cirrus_mode.h" + +struct cirrus_mc { + resource_size_t vram_size; + resource_size_t vram_base; +}; + +struct cirrus_device { + struct device *dev; + struct drm_device *ddev; + struct pci_dev *pdev; + unsigned long flags; + + resource_size_t rmmio_base; + resource_size_t rmmio_size; + void __iomem *rmmio; + + drm_local_map_t *framebuffer; + + struct cirrus_mc mc; + struct cirrus_mode_info mode_info; + + int num_crtc; +}; + +#endif /* __CIRRUS_H__ */ diff --git a/drivers/gpu/drm/cirrus/cirrus_crtc.c b/drivers/gpu/drm/cirrus/cirrus_crtc.c new file mode 100644 index 0000000..afce8f2 --- /dev/null +++ b/drivers/gpu/drm/cirrus/cirrus_crtc.c @@ -0,0 +1,277 @@ +/* + * Copyright 2000,2001 Sven Luther. + * Copyright 2010 Matt Turner. + * Copyright 2011 Red Hat + * + * This file is subject to the terms and conditions of the GNU General + * Public License version 2. See the file COPYING in the main + * directory of this archive for more details. + * + * Authors: Matthew Garrett + * Matt Turner + * Sven Luther + * Thomas Witzel + * Alan Hourihane + * + * Portions of this code derived from cirrusfb.c: + * drivers/video/cirrusfb.c - driver for Cirrus Logic chipsets + * + * Copyright 1999-2001 Jeff Garzik + */ +#include "drmP.h" +#include "drm.h" +#include "drm_crtc_helper.h" + +#include