Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934470AbdC3SCD (ORCPT ); Thu, 30 Mar 2017 14:02:03 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:36039 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934007AbdC3SCB (ORCPT ); Thu, 30 Mar 2017 14:02:01 -0400 From: Max Filippov To: linux-xtensa@linux-xtensa.org Cc: Chris Zankel , Marc Gauthier , Boris Brezillon , LKML , Max Filippov , stable@vger.kernel.org Subject: [PATCH] xtensa: make __pa work with uncached KSEG addresses Date: Thu, 30 Mar 2017 11:01:45 -0700 Message-Id: <1490896905-26344-1-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1551 Lines: 46 When __pa is applied to virtual address in uncached KSEG region the result is incorrect. Fix it by checking if the original address is in the uncached KSEG and adjusting the result. It looks better than masking off bits because pfn_valid would correctly work with new __pa results and it may be made working in noMMU case, once we get definition for uncached memory view. This is required for the dma_common_mmap and other functions calling __pa on coherent DMA memory addresses. Cc: stable@vger.kernel.org Tested-by: Boris Brezillon Reviewed-by: Boris Brezillon Signed-off-by: Max Filippov --- arch/xtensa/include/asm/page.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/xtensa/include/asm/page.h b/arch/xtensa/include/asm/page.h index 976b1d7..4ddbfd5 100644 --- a/arch/xtensa/include/asm/page.h +++ b/arch/xtensa/include/asm/page.h @@ -164,8 +164,21 @@ void copy_user_highpage(struct page *to, struct page *from, #define ARCH_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT) +#ifdef CONFIG_MMU +static inline unsigned long ___pa(unsigned long va) +{ + unsigned long off = va - PAGE_OFFSET; + + if (off >= XCHAL_KSEG_SIZE) + off -= XCHAL_KSEG_SIZE; + + return off + PHYS_OFFSET; +} +#define __pa(x) ___pa((unsigned long)(x)) +#else #define __pa(x) \ ((unsigned long) (x) - PAGE_OFFSET + PHYS_OFFSET) +#endif #define __va(x) \ ((void *)((unsigned long) (x) - PHYS_OFFSET + PAGE_OFFSET)) #define pfn_valid(pfn) \ -- 2.1.4