All of lore.kernel.org
 help / color / mirror / Atom feed
From: girish <girishvg@gmail.com>
To: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: "linux-mips@linux-mips.org" <linux-mips@linux-mips.org>,
	girish <girishvg@gmail.com>
Subject: Re: [PATCH] cleanup hardcoding __pa/__va macros etc. (take-2)
Date: Wed, 27 Sep 2006 07:06:10 +0900	[thread overview]
Message-ID: <C13FD364.7334%girishvg@gmail.com> (raw)
In-Reply-To: <20060927.013553.48803581.anemo@mba.ocn.ne.jp>

[-- Attachment #1: Type: text/plain, Size: 1590 bytes --]


>> But, then again treating all addresses as above PAGE_OFFSET is also wrong :)
> 
> It would be a design not a bug :-)
> 
>> I looked at it just as a work around. These macros are called from so many
>> other places that if an access is made at say 4000_0000 the kernel will oops
>> telling it was C000_0000 access error. Now that confused me a lot! With this
>> change now kernel oops on 4000_0000 :)
> 
> Yes, 4000_0000, which is wrong too.  And it _hides_ wrong usage of
> vaddr/paddr.  Bad side effect :)
> 
>> Anyway, you may ignore __pa/__va macros.
>> 
>> Could you please look into other changes I proposed?
> 
> __pa() returns "unsigned long" and __va() returns "void *" so some
> casts are also redundant.

After removing some of the redundant casts, re-submitting the patch.
Attached the patch in a text file.
 
In the meantime, I couldn't find the changes suggested for SPARSEMEM support
in the main source tree. Especially the ones reviewed during month of August
([PATCH] do not count pages in holes with sparsemem ...). Could you please
resend the consolidated patch to the list? Thanks.

BTW, I have couple of more changes in mind.
.1a Currently only one PCI DMA window is supported. We need to extend that,
if the PCI controller has multiple windows. Example implementation is in
arch/powerpc.
.1b During HIGHMEM support the PCI windows are not honored correctly. A
kmap() based mapping could be provided during PCI sync. Example
implementation, again arch/powerpc. Has anybody looked into this?
.2 Has anybody tested /dev/mem and/or /dev/kmem devices on MIPS platform?


[-- Attachment #2: patch-basicfix-20060927 --]
[-- Type: application/octet-stream, Size: 4609 bytes --]

diff -uprN -X linux-vanilla/Documentation/dontdiff linux-vanilla/arch/mips/mm/dma-noncoherent.c linux/arch/mips/mm/dma-noncoherent.c
--- linux-vanilla/arch/mips/mm/dma-noncoherent.c	2006-09-24 12:22:46.000000000 +0900
+++ linux/arch/mips/mm/dma-noncoherent.c	2006-09-25 22:38:38.000000000 +0900
@@ -334,7 +334,7 @@ EXPORT_SYMBOL(pci_dac_page_to_dma);
 struct page *pci_dac_dma_to_page(struct pci_dev *pdev,
 	dma64_addr_t dma_addr)
 {
-	return mem_map + (dma_addr >> PAGE_SHIFT);
+	return pfn_to_page (dma_addr >> PAGE_SHIFT);
 }
 
 EXPORT_SYMBOL(pci_dac_dma_to_page);
diff -uprN -X linux-vanilla/Documentation/dontdiff linux-vanilla/arch/mips/mm/init.c linux/arch/mips/mm/init.c
--- linux-vanilla/arch/mips/mm/init.c	2006-09-24 12:22:46.000000000 +0900
+++ linux/arch/mips/mm/init.c	2006-09-25 22:58:15.000000000 +0900
@@ -155,24 +155,22 @@ void __init paging_init(void)
 	low = max_low_pfn;
 	high = highend_pfn;
 
-#ifdef CONFIG_ISA
-	if (low < max_dma)
+	if (low < max_dma) {
 		zones_size[ZONE_DMA] = low;
-	else {
+	} else {
 		zones_size[ZONE_DMA] = max_dma;
 		zones_size[ZONE_NORMAL] = low - max_dma;
 	}
-#else
-	zones_size[ZONE_DMA] = low;
-#endif
+
 #ifdef CONFIG_HIGHMEM
 	if (cpu_has_dc_aliases) {
 		printk(KERN_WARNING "This processor doesn't support highmem.");
 		if (high - low)
 			printk(" %ldk highmem ignored", high - low);
 		printk("\n");
-	} else
-		zones_size[ZONE_HIGHMEM] = high - low;
+	} else {
+		zones_size[ZONE_HIGHMEM] = high - highstart_pfn;
+	}
 #endif
 
 	free_area_init(zones_size);
@@ -233,7 +231,7 @@ void __init mem_init(void)
 
 #ifdef CONFIG_HIGHMEM
 	for (tmp = highstart_pfn; tmp < highend_pfn; tmp++) {
-		struct page *page = mem_map + tmp;
+		struct page *page = pfn_to_page(tmp);
 
 		if (!page_is_ram(tmp)) {
 			SetPageReserved(page);
diff -uprN -X linux-vanilla/Documentation/dontdiff linux-vanilla/include/asm-mips/dma.h linux/include/asm-mips/dma.h
--- linux-vanilla/include/asm-mips/dma.h	2006-09-24 12:23:34.000000000 +0900
+++ linux/include/asm-mips/dma.h	2006-09-25 22:45:28.000000000 +0900
@@ -87,8 +87,13 @@
 /* Horrible hack to have a correct DMA window on IP22 */
 #include <asm/sgi/mc.h>
 #define MAX_DMA_ADDRESS		(PAGE_OFFSET + SGIMC_SEG0_BADDR + 0x01000000)
-#else
+#elif defined(CONFIG_ISA)
 #define MAX_DMA_ADDRESS		(PAGE_OFFSET + 0x01000000)
+#else
+#ifndef PLAT_MAX_DMA_SIZE
+#define PLAT_MAX_DMA_SIZE	0x10000000	/* 256MB: true for most of the MIPS32 systems */
+#endif
+#define MAX_DMA_ADDRESS		(PAGE_OFFSET + PLAT_MAX_DMA_SIZE)
 #endif
 
 /* 8237 DMA controllers */
diff -uprN -X linux-vanilla/Documentation/dontdiff linux-vanilla/include/asm-mips/io.h linux/include/asm-mips/io.h
--- linux-vanilla/include/asm-mips/io.h	2006-09-24 12:23:34.000000000 +0900
+++ linux/include/asm-mips/io.h	2006-09-27 06:45:15.000000000 +0900
@@ -116,7 +116,7 @@ static inline void set_io_port_base(unsi
  */
 static inline unsigned long virt_to_phys(volatile void * address)
 {
-	return (unsigned long)address - PAGE_OFFSET;
+	return __pa(address);
 }
 
 /*
@@ -133,7 +133,7 @@ static inline unsigned long virt_to_phys
  */
 static inline void * phys_to_virt(unsigned long address)
 {
-	return (void *)(address + PAGE_OFFSET);
+	return __va(address);
 }
 
 /*
@@ -141,12 +141,12 @@ static inline void * phys_to_virt(unsign
  */
 static inline unsigned long isa_virt_to_bus(volatile void * address)
 {
-	return (unsigned long)address - PAGE_OFFSET;
+	return __pa(address);
 }
 
 static inline void * isa_bus_to_virt(unsigned long address)
 {
-	return (void *)(address + PAGE_OFFSET);
+	return __va(address);
 }
 
 #define isa_page_to_bus page_to_phys
diff -uprN -X linux-vanilla/Documentation/dontdiff linux-vanilla/include/asm-mips/page.h linux/include/asm-mips/page.h
--- linux-vanilla/include/asm-mips/page.h	2006-09-24 12:23:34.000000000 +0900
+++ linux/include/asm-mips/page.h	2006-09-27 06:46:24.000000000 +0900
@@ -134,8 +134,17 @@ typedef struct { unsigned long pgprot; }
 /* to align the pointer to the (next) page boundary */
 #define PAGE_ALIGN(addr)	(((addr) + PAGE_SIZE - 1) & PAGE_MASK)
 
-#define __pa(x)			((unsigned long) (x) - PAGE_OFFSET)
-#define __va(x)			((void *)((unsigned long) (x) + PAGE_OFFSET))
+#ifdef CONFIG_32BIT
+#define ISMAPPED(x)	(KSEGX((x)) >= HIGHMEM_START && KSEGX((x)) < KSEG0)
+#else
+#define ISMAPPED(x)	(0)
+#endif
+
+#define ___pa(x)	((unsigned long) (x) - PAGE_OFFSET)
+#define __pa(x)		(ISMAPPED(x) ? (unsigned long)(x) : ___pa(x))
+
+#define ___va(x)	((void *)((unsigned long) (x) + PAGE_OFFSET))
+#define __va(x)		(ISMAPPED(x) ? (void*)(x) : ___va(x))
 
 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
 

  reply	other threads:[~2006-09-26 22:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-24  5:39 [PATCH] cleanup hardcoding __pa/__va macros etc girish
2006-09-24  7:15 ` [PATCH] cleanup hardcoding __pa/__va macros etc. (FWD) girish
2006-09-24 15:26 ` [PATCH] cleanup hardcoding __pa/__va macros etc Atsushi Nemoto
2006-09-25 14:51   ` [PATCH] cleanup hardcoding __pa/__va macros etc. (take-2) girish
2006-09-25 15:43     ` Atsushi Nemoto
     [not found]       ` <C13EBDF2.724C%girishvg@gmail.com>
2006-09-26  2:24         ` FW: " girish
2006-09-26  9:02         ` Atsushi Nemoto
2006-09-26 15:20           ` girish
2006-09-26 16:35             ` Atsushi Nemoto
2006-09-26 22:06               ` girish [this message]
2006-09-27 15:35                 ` Atsushi Nemoto
2006-09-27 16:58                   ` PATCH] cleanup hardcoding __pa/__va macros etc. (take-4) girish
2006-09-28 23:29                     ` Ralf Baechle
2006-09-29 14:45                       ` PATCH] cleanup hardcoding __pa/__va macros etc. (take-5) girish
2006-09-29 17:59                         ` Atsushi Nemoto
2006-09-29 18:33                           ` girish
2006-10-01 14:52                             ` Atsushi Nemoto
2006-10-01 14:57                               ` girish
2006-10-01 15:09                                 ` Atsushi Nemoto
2006-09-28 15:01           ` [PATCH] cleanup hardcoding __pa/__va macros etc. (take-2) Ralf Baechle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=C13FD364.7334%girishvg@gmail.com \
    --to=girishvg@gmail.com \
    --cc=anemo@mba.ocn.ne.jp \
    --cc=linux-mips@linux-mips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.