Module Name: src Committed By: riastradh Date: Sun Sep 8 15:41:07 UTC 2013
Modified Files: src/sys/external/bsd/drm2/dist/include/drm [riastradh-drm2]: drmP.h src/sys/modules/drm2 [riastradh-drm2]: Makefile Added Files: src/sys/external/bsd/drm2/drm [riastradh-drm2]: drm_cache.c Log Message: Implement drm_cache.c, for x86 only at the moment. To generate a diff of this commit: cvs rdiff -u -r1.1.1.1.2.50 -r1.1.1.1.2.51 \ src/sys/external/bsd/drm2/dist/include/drm/drmP.h cvs rdiff -u -r0 -r1.1.2.1 src/sys/external/bsd/drm2/drm/drm_cache.c cvs rdiff -u -r1.1.2.38 -r1.1.2.39 src/sys/modules/drm2/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/external/bsd/drm2/dist/include/drm/drmP.h diff -u src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.1.1.1.2.50 src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.1.1.1.2.51 --- src/sys/external/bsd/drm2/dist/include/drm/drmP.h:1.1.1.1.2.50 Wed Jul 24 03:53:46 2013 +++ src/sys/external/bsd/drm2/dist/include/drm/drmP.h Sun Sep 8 15:41:07 2013 @@ -1601,7 +1601,11 @@ extern int drm_authmagic(struct drm_devi 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); Index: src/sys/modules/drm2/Makefile diff -u src/sys/modules/drm2/Makefile:1.1.2.38 src/sys/modules/drm2/Makefile:1.1.2.39 --- src/sys/modules/drm2/Makefile:1.1.2.38 Wed Jul 24 03:52:37 2013 +++ src/sys/modules/drm2/Makefile Sun Sep 8 15:41:07 2013 @@ -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_agpsupport.c # XXX Move to dr 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 Added files: Index: src/sys/external/bsd/drm2/drm/drm_cache.c diff -u /dev/null src/sys/external/bsd/drm2/drm/drm_cache.c:1.1.2.1 --- /dev/null Sun Sep 8 15:41:07 2013 +++ src/sys/external/bsd/drm2/drm/drm_cache.c Sun Sep 8 15:41:07 2013 @@ -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__) */