Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/riastradh-drm2]: src/sys Implement drm_cache.c, for x86 only at the moment.
details: https://anonhg.NetBSD.org/src/rev/f09b22d7a0ff
branches: riastradh-drm2
changeset: 788519:f09b22d7a0ff
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sun Sep 08 15:41:07 2013 +0000
description:
Implement drm_cache.c, for x86 only at the moment.
diffstat:
sys/external/bsd/drm2/dist/include/drm/drmP.h | 6 +-
sys/external/bsd/drm2/drm/drm_cache.c | 148 ++++++++++++++++++++++++++
sys/modules/drm2/Makefile | 4 +-
3 files changed, 155 insertions(+), 3 deletions(-)
diffs (186 lines):
diff -r c7d7886c93a3 -r f09b22d7a0ff sys/external/bsd/drm2/dist/include/drm/drmP.h
--- a/sys/external/bsd/drm2/dist/include/drm/drmP.h Sun Sep 08 15:40:17 2013 +0000
+++ b/sys/external/bsd/drm2/dist/include/drm/drmP.h Sun Sep 08 15:41:07 2013 +0000
@@ -1601,7 +1601,11 @@
struct drm_file *file_priv);
extern int drm_remove_magic(struct drm_master *master, drm_magic_t magic);
-#ifndef __NetBSD__ /* XXX temporary measure 20130212 */
+#ifdef __NetBSD__ /* XXX drm clflush */
+void drm_clflush_pglist(struct pglist *);
+void drm_clflush_page(struct page *);
+void drm_clflush_virt_range(const void *, size_t);
+#else
/* Cache management (drm_cache.c) */
void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
void drm_clflush_sg(struct sg_table *st);
diff -r c7d7886c93a3 -r f09b22d7a0ff sys/external/bsd/drm2/drm/drm_cache.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/drm2/drm/drm_cache.c Sun Sep 08 15:41:07 2013 +0000
@@ -0,0 +1,148 @@
+/* $NetBSD: drm_cache.c,v 1.1.2.1 2013/09/08 15:41:07 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: drm_cache.c,v 1.1.2.1 2013/09/08 15:41:07 riastradh Exp $");
+
+#include <sys/types.h>
+#include <sys/xcall.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/cpufunc.h>
+
+#include <linux/mm_types.h>
+
+#include <drm/drmP.h>
+
+static bool drm_md_clflush_finegrained_p(void);
+static void drm_md_clflush_all(void);
+static void drm_md_clflush_page(struct page *);
+static void drm_md_clflush_virt_range(const void *, size_t);
+
+void
+drm_clflush_pglist(struct pglist *list)
+{
+
+ if (drm_md_clflush_finegrained_p()) {
+ struct vm_page *page;
+
+ TAILQ_FOREACH(page, list, pageq.queue)
+ drm_md_clflush_page(container_of(page, struct page,
+ p_vmp));
+ } else {
+ drm_md_clflush_all();
+ }
+}
+
+void
+drm_clflush_page(struct page *page)
+{
+
+ if (drm_md_clflush_finegrained_p())
+ drm_md_clflush_page(page);
+ else
+ drm_md_clflush_all();
+}
+
+void
+drm_clflush_virt_range(const void *vaddr, size_t nbytes)
+{
+
+ if (drm_md_clflush_finegrained_p())
+ drm_md_clflush_virt_range(vaddr, nbytes);
+ else
+ drm_md_clflush_all();
+}
+
+#if defined(__i386__) || defined(__x86_64__)
+
+static bool
+drm_md_clflush_finegrained_p(void)
+{
+ return ISSET(cpu_info_primary.ci_feat_val[0], CPUID_CFLUSH);
+}
+
+static void
+drm_x86_clflush_cpu(void)
+{
+ __asm__ __volatile__ ("wbinvd");
+}
+
+static void
+drm_x86_clflush(const void *vaddr)
+{
+ __asm__ __volatile__ ("clflush %0" : : "=r" (vaddr));
+}
+
+static size_t
+drm_x86_clflush_size(void)
+{
+ KASSERT(drm_md_clflush_finegrained_p());
+ return cpu_info_primary.ci_cflush_lsize;
+}
+
+static void
+drm_x86_clflush_xc(void *arg0 __unused, void *arg1 __unused)
+{
+ drm_x86_clflush_cpu();
+}
+
+static void
+drm_md_clflush_all(void)
+{
+ xc_wait(xc_broadcast(0, &drm_md_clflush_xc, NULL, NULL));
+}
+
+static void
+drm_md_clflush_page(struct page *page)
+{
+ void *const vaddr = kmap_atomic(page);
+
+ drm_md_clflush_virt_range(vaddr, PAGE_SIZE);
+
+ kunmap_atomic(vaddr);
+}
+
+static void
+drm_md_clflush_virt_range(const void *vaddr, size_t nbytes)
+
+{
+ const char *const start = vaddr, *const end = (start + nbytes);
+ const char *p;
+ const unsigned int clflush_size = drm_x86_clflush_size();
+
+ KASSERT(drm_md_clflush_finegrained_p());
+ for (p = start; p < end; p += clflush_size)
+ drm_clflush(p);
+}
+
+#endif /* defined(__i386__) || defined(__x86_64__) */
diff -r c7d7886c93a3 -r f09b22d7a0ff sys/modules/drm2/Makefile
--- a/sys/modules/drm2/Makefile Sun Sep 08 15:40:17 2013 +0000
+++ b/sys/modules/drm2/Makefile Sun Sep 08 15:41:07 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1.2.38 2013/07/24 03:52:37 riastradh Exp $
+# $NetBSD: Makefile,v 1.1.2.39 2013/09/08 15:41:07 riastradh Exp $
.include "../Makefile.inc"
.include "Makefile.inc"
@@ -16,7 +16,7 @@
SRCS+= drm_auth.c
SRCS+= drm_buffer.c
SRCS+= drm_bufs.c
-#SRCS+= drm_cache.c # XXX Rewrite for uvm.
+SRCS+= drm_cache.c
SRCS+= drm_context.c
SRCS+= drm_crtc.c
SRCS+= drm_crtc_helper.c
Home |
Main Index |
Thread Index |
Old Index