From nobody Sat Jan 22 19:36:38 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 D0188196BD36; Sat, 22 Jan 2022 19:36:42 +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 4Jh6203L0qz3h6t; Sat, 22 Jan 2022 19:36:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642880202; 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=KQlhfH5IUgpZS/zuc7l4i/bvBncbd6R3U+8YMBlTW4I=; b=ArWXZYqBItQE2dX8Kxy7akpQQhvdYZhx0P+jhJ9Io3LjwdQBUQtIu56lEIY/KPYMOfc18+ fw7WVbV3Esqt2Eaotg8myjN3JiXUylFRZlrqH0ZtVcu+LG+wDjwOGXD1NqfP70JnAu3W0q rmpSk3joH1gcWuIaNTjepvsIJ3D7pW3FOygMcSZdR/YHVT/piObKxs+SvQCEP32zeVVLaD 8UAJne0Qv/COKd5rXolppbLdOvHA4c/sYryJtSKcsE4ylgNYaOJBO9JobZlv309n2Z6Pp0 f3By1es7YfjlpsN4QZPj/eABsVQLW/kCJYjMlq1xwwU3PRqsoitEmivUrLS3WA== 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 BC44714B65; Sat, 22 Jan 2022 19:36:38 +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 20MJacvU000393; Sat, 22 Jan 2022 19:36:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20MJacFg000392; Sat, 22 Jan 2022 19:36:38 GMT (envelope-from git) Date: Sat, 22 Jan 2022 19:36:38 GMT Message-Id: <202201221936.20MJacFg000392@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: 2d90567415d5 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 2d90567415d5b67c86df09eaeda30c40fa3483cc Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642880202; 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=KQlhfH5IUgpZS/zuc7l4i/bvBncbd6R3U+8YMBlTW4I=; b=up0gYzozwngDDuVtvk9SpoKiTwYlRzUf0piBjVCr+9i166FX4J36SVbhNG9nBoNAIRDVP+ LCPdYImdhMQDOBozHvBpcaBsGblSeyOlDDokvcdIY7+WkZSN4x8VIoR2SuR+w6lFmrq36K iYTBR64c1u8aouMiHH4fgf8BH1pVB0u7gvENkDoc5csxqopKePHXU3xpMJ6bjQT39+w+mW sbcy/qdbUu1yFuG9ujqu+4iirzIa5dBb+aKX96Gx8RujJZZikB8BwHjVCGadXrlJX4Sl8F WqHEsIOwDzE+Crvpq1OFFVNussoUHHga+zgF7/NCpG7O2/6RPycHLH72Dez9SA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642880202; a=rsa-sha256; cv=none; b=a1W/ji2B4gc557qfzK4wzStnK46UB8OT3USzZ6mpU98ZDJnSVAzWznb4DTKZ+Fh88/YPbH kPe1skI+UqbKLmtUj2CC/x/246rcnNzuOJYxVrknZNq+pXSUgF6g2DxvWmRDEEmToq9vme sSqfY5UtSJ+qnnxRN2yUEoWYvm50+xNuPxz1RH5mPt/jD7i7H9qR8FkQiXOcONUauFuR7s loPteV/j17cFtsj8T8QurYMjZA1hQErGsQmhyJqA0RXDwJZ90i3enDMXzQ2UtyQDh7jPta kBg64MEKlfNjjutUnWbaFPA3E4prZI7viE+pEG2ChvHkhU0aaXUY8+SkQqgdjA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=2d90567415d5b67c86df09eaeda30c40fa3483cc commit 2d90567415d5b67c86df09eaeda30c40fa3483cc Author: Vladimir Kondratyev AuthorDate: 2021-12-08 21:12:51 +0000 Commit: Vladimir Kondratyev CommitDate: 2022-01-22 19:34:37 +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 (cherry picked from commit 98b129783c478616f59b3b9c9576a303f7ed67de) --- 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 +}