From nobody Mon Jan 10 19:50:51 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7062E1954969; Mon, 10 Jan 2022 19:50:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JXkvy0hLgz3Nn5; Mon, 10 Jan 2022 19:50:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B41F53303; Mon, 10 Jan 2022 19:50:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20AJopLQ009305; Mon, 10 Jan 2022 19:50:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20AJopwM009304; Mon, 10 Jan 2022 19:50:51 GMT (envelope-from git) Date: Mon, 10 Jan 2022 19:50:51 GMT Message-Id: <202201101950.20AJopwM009304@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 98b129783c47 - main - LinuxKPI: Import MTRR support functions from drm-kmod List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 98b129783c478616f59b3b9c9576a303f7ed67de Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641844254; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9gojM9MYm7ucauKMhtcmGkESneJ5uFlwkxy9zJzZOK0=; b=a6Cp3cb0ibd1Mzx7kUzUB6aA1XuxViNgeOsioqndUpVn6OdyrJ1lkGy4Tq0M96/AqN5jym 7BgLaiQXGViMPGdePh9MScbzbRLCQs0lknIldWOm0OYAJSa6J+/LhhgWzTJHJTmugJPf2u mDeXiVLQszuZdWYsCrOoq7cQP8jdN0eQeB/2gLRD8mlGtoLR0tr68fGCaOvEj3XEnFV11e L/wL2O4PbLu3qjNpXkHua5uwOb75yP0wVwgTXO6X7CK2OKQNnNCOPjk0tQrExZcszF/ccz 6ztfpQIEUupo+o2/mKoYXVs/qS9OZvv8oO2E1FkhAvsNuOt/cL6G1xAq6/XVJQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641844254; a=rsa-sha256; cv=none; b=HlcZ9wyAnpfujT7jNG2bZx9PghNngXst7gDK7w0ZMhcCMjlYb/gKmtmYCAKrxrmRLpFZ01 XwDAS2y1r/PObV/0LXgLhoJm2abibQfN9ZIGgnLOw7alDlEYSocSZqMUqr+rmD8xaTeyO2 FC0K2h3jEseSTtJTpt7k9Zin6RHkWU0GshNLzEKuFL2yp146yZ5aoHYpR88qiSRD3dYlJl Me3J7GpO4W+lQ3641qIsrxlhd8b/TojfAO9in2xZsBSqzOOwnNWiAnlvQLPYv5jUAta8zT +06hDvVzQZWhiefDu1sarZIGDW1Yrex6w3EHbgde+dsW1BO3JEg72ySW7bb/AA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=98b129783c478616f59b3b9c9576a303f7ed67de commit 98b129783c478616f59b3b9c9576a303f7ed67de Author: Vladimir Kondratyev AuthorDate: 2021-12-08 21:12:51 +0000 Commit: Vladimir Kondratyev CommitDate: 2022-01-10 19:49:38 +0000 LinuxKPI: Import MTRR support functions from drm-kmod They are superseded by PAT and mostly useless nowadays but still can be used on Pentium III/IV era processors. Unlike drm-kmod version, this one ignores MTRR if PAT is available that fixes confusing "Failed to add WC MTRR for [0xXXXX-0xYYYY]: 22; performance may suffer" message often appearing during drm-kmod initialization process. MFC after: 1 week Reviewed by: hselasky, manu Differential Revision: https://reviews.freebsd.org/D33561 --- sys/compat/linuxkpi/common/include/linux/io.h | 8 +++ sys/compat/linuxkpi/common/src/linux_page.c | 72 +++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/io.h b/sys/compat/linuxkpi/common/include/linux/io.h index e402ebed0665..08e1635b70ac 100644 --- a/sys/compat/linuxkpi/common/include/linux/io.h +++ b/sys/compat/linuxkpi/common/include/linux/io.h @@ -482,4 +482,12 @@ memunmap(void *addr) iounmap(addr); } +#define __MTRR_ID_BASE 1 +int lkpi_arch_phys_wc_add(unsigned long, unsigned long); +void lkpi_arch_phys_wc_del(int); +#define arch_phys_wc_add(...) lkpi_arch_phys_wc_add(__VA_ARGS__) +#define arch_phys_wc_del(...) lkpi_arch_phys_wc_del(__VA_ARGS__) +#define arch_phys_wc_index(x) \ + (((x) < __MTRR_ID_BASE) ? -1 : ((x) - __MTRR_ID_BASE)) + #endif /* _LINUX_IO_H_ */ diff --git a/sys/compat/linuxkpi/common/src/linux_page.c b/sys/compat/linuxkpi/common/src/linux_page.c index 3c8bc2bd3c5b..df4a124cf3e2 100644 --- a/sys/compat/linuxkpi/common/src/linux_page.c +++ b/sys/compat/linuxkpi/common/src/linux_page.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include @@ -63,6 +64,15 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include +#include + +#ifdef __i386__ +DEFINE_IDR(mtrr_idr); +static MALLOC_DEFINE(M_LKMTRR, "idr", "Linux MTRR compat"); +extern int pat_works; +#endif void si_meminfo(struct sysinfo *si) @@ -357,3 +367,65 @@ retry: vm_object_deallocate(devobj); } } + +int +lkpi_arch_phys_wc_add(unsigned long base, unsigned long size) +{ +#ifdef __i386__ + struct mem_range_desc *mrdesc; + int error, id, act; + + /* If PAT is available, do nothing */ + if (pat_works) + return (0); + + mrdesc = malloc(sizeof(*mrdesc), M_LKMTRR, M_WAITOK); + mrdesc->mr_base = base; + mrdesc->mr_len = size; + mrdesc->mr_flags = MDF_WRITECOMBINE; + strlcpy(mrdesc->mr_owner, "drm", sizeof(mrdesc->mr_owner)); + act = MEMRANGE_SET_UPDATE; + error = mem_range_attr_set(mrdesc, &act); + if (error == 0) { + error = idr_get_new(&mtrr_idr, mrdesc, &id); + MPASS(idr_find(&mtrr_idr, id) == mrdesc); + if (error != 0) { + act = MEMRANGE_SET_REMOVE; + mem_range_attr_set(mrdesc, &act); + } + } + if (error != 0) { + free(mrdesc, M_LKMTRR); + pr_warn( + "Failed to add WC MTRR for [%p-%p]: %d; " + "performance may suffer\n", + (void *)base, (void *)(base + size - 1), error); + } else + pr_warn("Successfully added WC MTRR for [%p-%p]\n", + (void *)base, (void *)(base + size - 1)); + + return (error != 0 ? -error : id + __MTRR_ID_BASE); +#else + return (0); +#endif +} + +void +lkpi_arch_phys_wc_del(int reg) +{ +#ifdef __i386__ + struct mem_range_desc *mrdesc; + int act; + + /* Check if arch_phys_wc_add() failed. */ + if (reg < __MTRR_ID_BASE) + return; + + mrdesc = idr_find(&mtrr_idr, reg - __MTRR_ID_BASE); + MPASS(mrdesc != NULL); + idr_remove(&mtrr_idr, reg - __MTRR_ID_BASE); + act = MEMRANGE_SET_REMOVE; + mem_range_attr_set(mrdesc, &act); + free(mrdesc, M_LKMTRR); +#endif +}