Skip to contentSkip to conversation

mb862xxfb: use CONFIG_OF instead of CONFIG_PPC_OF

PATCH In review Arnd Bergmann 15 participants 76 messages May 11, 2009 – May 27, 2009 1 message not in the archive

Subsystems (36)
Arm (32-bit) x86 SCSI Sound +32 more subsystems
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Arnd Bergmann

author maintainer
#1 lore raw

PATCH 1/1 mb862xxfb: use CONFIG_OF instead of CONFIG_PPC_OF

With this change, the driver builds fine on Microblaze, which helps allyesconfig compile tests.

I did not test sparc, but the change should have the same effect there.

---
 drivers/video/mb862xx/mb862xxfb.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/video/mb862xx/mb862xxfb.c
index fb64234..a28e3cf 100644

drivers/video/mb862xx/mb862xxfb.c +1 -1
@@ -19,7 +19,7 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/pci.h>
-#if defined(CONFIG_PPC_OF)
+#if defined(CONFIG_OF)
 #include <linux/of_platform.h>
 #endif
 #include "mb862xxfb.h"
Acked-by on v1 1/1
#2 lore raw
Quoted 2 lines · Arnd Bergmann

With this change, the driver builds fine on Microblaze, which helps allyesconfig compile tests.

This patch is okay, just tested it. So

Quoted 1 line

I did not test sparc, but the change should have the same effect there.

unfortunately, OF platform part of this driver doesn't build on sparc as there is no of_address_to_resource() and no NO_IRQ in sparc code. There was an attempt to fix it by restricting the build of this part to PPC, see http://lkml.org/lkml/2009/1/11/376

I will rebase the above mentioned patch by Julian Calaby and resubmit soon. Thanks.

Quoted 19 lines
---
 drivers/video/mb862xx/mb862xxfb.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/video/mb862xx/mb862xxfb.c +1 -1
index fb64234..a28e3cf 100644
@@ -19,7 +19,7 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/pci.h>
-#if defined(CONFIG_PPC_OF)
+#if defined(CONFIG_OF)
 #include <linux/of_platform.h>
 #endif
 #include "mb862xxfb.h"
author maintainer
#3 lore raw

PATCH 1/1 ata: libata depends on HAS_DMA

In reply to a message not in the archive

libata uses the DMA mapping API, so it cannot be built on architectures that don't have DMA support.

---
 drivers/ata/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/Kconfig +1 -1
index 9120717..f076268 100644
@@ -4,7 +4,7 @@
 
 menuconfig ATA
 	tristate "Serial ATA (prod) and Parallel ATA (experimental) drivers"
-	depends on HAS_IOMEM
+	depends on HAS_IOMEM && HAS_DMA
 	depends on BLOCK
 	depends on !(M32R || M68K) || BROKEN
 	select SCSI
Signature · 3 lines
1.6.0.4

-- 
#4 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 13 lines · Arnd Bergmann

libata uses the DMA mapping API, so it cannot be built on architectures that don't have DMA support.

---
 drivers/ata/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/Kconfig +0 -0
index 9120717..f076268 100644

drivers/ata/Kconfig line 9

Quoted 7 lines
drivers/ata/Kconfig +1 -1
@@ -4,7 +4,7 @@
 
 menuconfig ATA
 	tristate "Serial ATA (prod) and Parallel ATA (experimental) drivers"
-	depends on HAS_IOMEM
+	depends on HAS_IOMEM && HAS_DMA
 	depends on BLOCK
 	depends on !(M32R || M68K) || BROKEN

What specifically is breaking?

Ideally we should be able to work with PIO-only...

JEff

author maintainer
#5 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 13 lines · Jeff Garzik
Quoted 10 lines
drivers/ata/Kconfig +0 -0
@@ -4,7 +4,7 @@


 menuconfig ATA
      tristate "Serial ATA (prod) and Parallel ATA (experimental) drivers" -     depends on HAS_IOMEM
+     depends on HAS_IOMEM && HAS_DMA
      depends on BLOCK
      depends on !(M32R || M68K) || BROKEN

What specifically is breaking?

Quoted 1 line

Ideally we should be able to work with PIO-only...

CONFIG_HAS_DMA is not set on architectures that are missing asm/dma-mapping.h or fall back to asm-generic/dma-mapping-broken.h.

In the latter case, you get a link error:
drivers/built-in.o: In function `sas_issue_ata_cmd':
/home/arnd/linux/linux-2.6/drivers/scsi/libsas/sas_ata.c(.text+0x33c50): undefined reference to dma_map_sg' /home/arnd/linux/linux-2.6/drivers/scsi/libsas/sas_ata.c(.text+0x33ef0): undefined reference to dma_unmap_sg' drivers/built-in.o: In function `ata_sg_clean':
/home/arnd/linux/linux-2.6/drivers/ata/libata-core.c(.text+0x37d18): undefined reference to dma_unmap_sg' drivers/built-in.o: In function ata_qc_issue':
/home/arnd/linux/linux-2.6/drivers/ata/libata-core.c(.text+0x38774): undefined reference to dma_map_sg' drivers/built-in.o: In function ata_port_start':
/home/arnd/linux/linux-2.6/drivers/ata/libata-core.c(.text+0x3bf0c): undefined reference to `dmam_alloc_coherent'

A slightly less naive (but still suboptimal) fix would be the patch below. I could not find an easy way to force all devices to use PIO, this patch would simply fail if someone tried to set a DMA mode.

	Arnd <><
drivers/ata/libata-core.c +11 -0
@@ -4629,6 +4629,7 @@ static unsigned int ata_dev_init_params(struct ata_device *dev,
  */
 void ata_sg_clean(struct ata_queued_cmd *qc)
 {
+#ifdef CONFIG_HAS_DMA
 	struct ata_port *ap = qc->ap;
 	struct scatterlist *sg = qc->sg;
 	int dir = qc->dma_dir;
@@ -4642,6 +4643,7 @@ void ata_sg_clean(struct ata_queued_cmd *qc)
 
 	qc->flags &= ~ATA_QCFLAG_DMAMAP;
 	qc->sg = NULL;
+#endif /* CONFIG_HAS_DMA */
 }
 
 /**
@@ -4743,6 +4745,7 @@ void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
  */
 static int ata_sg_setup(struct ata_queued_cmd *qc)
 {
+#ifdef CONFIG_HAS_DMA
 	struct ata_port *ap = qc->ap;
 	unsigned int n_elem;
 
@@ -4758,6 +4761,10 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
 	qc->flags |= ATA_QCFLAG_DMAMAP;
 
 	return 0;
+#else
+	DPRINTK("attempted to use DMA on incompatible architecture\n");
+	return -EINVAL;
+#endif /* CONFIG_HAS_DMA */
 }
 
 /**
@@ -5450,8 +5457,12 @@ int ata_port_start(struct ata_port *ap)
 {
 	struct device *dev = ap->dev;
 
+#ifdef CONFIG_HAS_DMA
 	ap->prd = dmam_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma,
 				      GFP_KERNEL);
+#else
+	ap->prd = devres_alloc(dev, ATA_PRD_TBL_SZ, GFP_KERNEL);
+#endif /* CONFIG_HAS_DMA */
 	if (!ap->prd)
 		return -ENOMEM;
 
drivers/scsi/libsas/Kconfig +1 -0
index 59e00fa..e00271f 100644
@@ -34,6 +34,7 @@ config SCSI_SAS_ATA
 	bool "ATA support for libsas (requires libata)"
 	depends on SCSI_SAS_LIBSAS
 	depends on ATA = y || ATA = SCSI_SAS_LIBSAS
+	depends on HAS_DMA
 	help
 		Builds in ATA support into libsas.  Will necessitate
 		the loading of libata along with libsas.
author maintainer
#6 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 8 lines · Arnd Bergmann

+#ifdef CONFIG_HAS_DMA
        ap->prd = dmam_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma, GFP_KERNEL);

drivers/ata/libata-core.c +3 -0
+#else
+       ap->prd = devres_alloc(dev, ATA_PRD_TBL_SZ, GFP_KERNEL);
+#endif /* CONFIG_HAS_DMA */

        if (!ap->prd)
                return -ENOMEM;

this should have been devm_kzalloc, not devres_alloc.

	Arnd <><
#7 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

In reply to Arnd Bergmann
Quoted 4 lines · On Mon, 11 May 2009 22:38:55 +0000 Arnd Bergmann <[email protected]> wrote:

libata uses the DMA mapping API, so it cannot be built on architectures that don't have DMA support.

Almost every PATA adapter can fall back to PIO, many are PIO only. We need a rather cleaner way to sort this.

author maintainer
#8 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 4 lines · Alan Cox

Almost every PATA adapter can fall back to PIO, many are PIO only. We need a rather cleaner way to sort this.

Currently, the only architectures that don't set HAS_DMA are h8300, m32r m68k (except SUN3 and Coldfire), microblaze and s390.
s390 will never get it, microblaze is currently implementing dma-mapping.h.

The other three are still using drivers/ide instead of drivers/ata.

One way to fix this would be to implement dma-mapping.h in h8300, m32r and m68k and leave !HAS_DMA as the obscure s390 case (this one already can't use ATA because of !HAS_MMIO).

The other way would be to add some #ifdef CONFIG_HAS_DMA in libata-core.c and sas_ata.c.

	Arnd <><

	Arnd <><
#9 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 9 lines · Arnd Bergmann

Currently, the only architectures that don't set HAS_DMA are h8300, m32r m68k (except SUN3 and Coldfire), microblaze and s390.
s390 will never get it, microblaze is currently implementing dma-mapping.h.

The other three are still using drivers/ide instead of drivers/ata.

One way to fix this would be to implement dma-mapping.h in h8300, m32r and m68k and leave !HAS_DMA as the obscure s390 case (this one already can't use ATA because of !HAS_MMIO).

If I'm reading the m68k code correctly, SUN3 is the one that doesn't have DMA. It is implemented on any m68k with a standard Motorola MMU. It might be possible to get the DMA code working on a sun3, but I doubt they ever have IDE hardware.

Brad Boyer
[email protected]

#10 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Hi,

Quoted 6 lines
Quoted 6 lines

Currently, the only architectures that don't set HAS_DMA are h8300, m32r m68k (except SUN3 and Coldfire), microblaze and s390.
s390 will never get it, microblaze is currently implementing dma-mapping.h.

The other three are still using drivers/ide instead of drivers/ata.

Quoted 8 lines
Quoted 3 lines

One way to fix this would be to implement dma-mapping.h in h8300, m32r and m68k and leave !HAS_DMA as the obscure s390 case (this one already can't use ATA because of !HAS_MMIO).

If I'm reading the m68k code correctly, SUN3 is the one that doesn't have DMA. It is implemented on any m68k with a standard Motorola MMU. It might be possible to get the DMA code working on a sun3, but I doubt they ever have IDE hardware.

The Atari IDE interface does not use DMA. I don't see what addition of DMA mapping for IDE would achieve.

If it doesn't interfere with plain PIO mode, fine.

Michael

#11 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

In reply to Brad Boyer

Hi,

Quoted 6 lines
Quoted 6 lines

Currently, the only architectures that don't set HAS_DMA are h8300, m32r m68k (except SUN3 and Coldfire), microblaze and s390.
s390 will never get it, microblaze is currently implementing dma-mapping.h.

The other three are still using drivers/ide instead of drivers/ata.

Quoted 8 lines
Quoted 3 lines

One way to fix this would be to implement dma-mapping.h in h8300, m32r and m68k and leave !HAS_DMA as the obscure s390 case (this one already can't use ATA because of !HAS_MMIO).

If I'm reading the m68k code correctly, SUN3 is the one that doesn't have DMA. It is implemented on any m68k with a standard Motorola MMU. It might be possible to get the DMA code working on a sun3, but I doubt they ever have IDE hardware.

The Atari IDE interface does not use DMA. I don't see what addition of DMA mapping for IDE would achieve.

If it doesn't interfere with plain PIO mode, fine.

Michael

#12 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 2 lines · Michael Schmitz

The Atari IDE interface does not use DMA. I don't see what addition of DMA mapping for IDE would achieve.

The macide driver doesn't support anything with DMA hardware either. In fact, no m68k Macintosh has both DMA capability and an IDE controller. However, we do support the basic DMA routines on the main m68k platforms. It's just not used for IDE. I think the proposed change was to require that the DMA routines be present, not that the IDE ports actually have to have a DMA capability.

Quoted 1 line

If it doesn't interfere with plain PIO mode, fine.

I agree. There definitely needs to still be support for IDE ports that don't have DMA capability.

Brad Boyer
[email protected]

#13 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 4 lines
Quoted 1 line

If it doesn't interfere with plain PIO mode, fine.

I agree. There definitely needs to still be support for IDE ports that don't have DMA capability.

There is - it's just if the platform doesn't implement the dma_* APIs you get a problem.

Alan

#14 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 7 lines · Alan Cox
Quoted 4 lines
Quoted 1 line

If it doesn't interfere with plain PIO mode, fine.

I agree. There definitely needs to still be support for IDE ports that don't have DMA capability.

There is - it's just if the platform doesn't implement the dma_* APIs you get a problem.

Note that there are other things missing on m68k and m32r, that's why Al added the

| depends on !(M32R || M68K) || BROKEN

commit 9317fd4c60962d3a9423b5f9bb5d1b10cf8a0699

Author: Al Viro <[email protected]>
Date:   Sun Sep 24 23:40:00 2006 +0100

[PATCH] libata won't build on m68k and m32r

no ioread*(), for one thing

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#15 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

In reply to Alan Cox
Quoted 6 lines · Alan Cox
Quoted 3 lines
Quoted 1 line

If it doesn't interfere with plain PIO mode, fine.

I agree. There definitely needs to still be support for IDE ports that don't have DMA capability.

There is - it's just if the platform doesn't implement the dma_* APIs you get a problem.

Wouldn't the easiest solution be to just dummy out the DMA API calls on this platform to always fail? That would fix these compile problems..

#16 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 10 lines · On Wed, 13 May 2009 17:57:14 -0600 Robert Hancock <[email protected]> wrote:
Quoted 6 lines · Alan Cox
Quoted 3 lines
Quoted 1 line

If it doesn't interfere with plain PIO mode, fine.

I agree. There definitely needs to still be support for IDE ports that don't have DMA capability.

There is - it's just if the platform doesn't implement the dma_* APIs you get a problem.

Wouldn't the easiest solution be to just dummy out the DMA API calls on this platform to always fail? That would fix these compile problems..

Can libata call dma_supported() per device to decide DMA or PIO mode? Then, we can solve this problem by add dummy DMA API (just calls BUG) on such architectures, without Kconfig magic or adding ifdef (like the old ide stack does), I think.

#17 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 9 lines · FUJITA Tomonori
Quoted 6 lines · On Wed, 13 May 2009 17:57:14 -0600 Robert Hancock <[email protected]> wrote:
Quoted 5 lines · Alan Cox
Quoted 3 lines
Quoted 1 line

If it doesn't interfere with plain PIO mode, fine.

I agree. There definitely needs to still be support for IDE ports that don't have DMA capability.

There is - it's just if the platform doesn't implement the dma_* APIs you get a problem.

Quoted 7 lines
Quoted 2 lines

Wouldn't the easiest solution be to just dummy out the DMA API calls on this platform to always fail? That would fix these compile problems..

Can libata call dma_supported() per device to decide DMA or PIO mode? Then, we can solve this problem by add dummy DMA API (just calls BUG) on such architectures, without Kconfig magic or adding ifdef (like the old ide stack does), I think.

Sure it can. Which specific drivers are we talking about?

Thanks.

Signature · 1 line
tejun
author maintainer
#18 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 5 lines · Tejun Heo
Quoted 4 lines · FUJITA Tomonori

Can libata call dma_supported() per device to decide DMA or PIO mode? Then, we can solve this problem by add dummy DMA API (just calls BUG) on such architectures, without Kconfig magic or adding ifdef (like the old ide stack does), I think.

That would be the !CONFIG_PCI half of the old include/asm-generic/dma-mapping.h file that you just removed, right?

In general, I'd prefer keeping the asm-generic/dma-mapping-broken.h implementation that gives us a compile-time error, but maybe there is an even better option based on the mn10300 implementation which basically pretends everything works with just page_to_phys() mappings.

Quoted 1 line

Sure it can.  Which specific drivers are we talking about?

The main problem is libata-core.c, which references DMA mapping API calls that are only implemented on architectures setting CONFIG_HAS_DMA.

	Arnd <><

--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#19 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Hello,

Quoted 7 lines · Arnd Bergmann
Quoted 5 lines · Tejun Heo
Quoted 4 lines · FUJITA Tomonori

Can libata call dma_supported() per device to decide DMA or PIO mode? Then, we can solve this problem by add dummy DMA API (just calls BUG) on such architectures, without Kconfig magic or adding ifdef (like the old ide stack does), I think.

Quoted 8 lines

That would be the !CONFIG_PCI half of the old include/asm-generic/dma-mapping.h file that you just removed, right?

In general, I'd prefer keeping the asm-generic/dma-mapping-broken.h implementation that gives us a compile-time error, but maybe there is an even better option based on the mn10300 implementation which basically pretends everything works with just page_to_phys() mappings.

Don't know much history here but I don't wanna sprinkle ifdefs around in libata so I would much prefer dummy implementation which doesn't fail compile.

Quoted 5 lines
Quoted 1 line

Sure it can. Which specific drivers are we talking about?

The main problem is libata-core.c, which references DMA mapping API calls that are only implemented on architectures setting CONFIG_HAS_DMA.

Yeah, sure, libata-core is used by every driver but I was wondering whether only SFF drivers are of interest or there are others.

Thanks.

Signature · 1 line
tejun
author maintainer
#20 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 3 lines · Tejun Heo

Don't know much history here but I don't wanna sprinkle ifdefs around in libata so I would much prefer dummy implementation which doesn't fail compile.

My original patch did that by adding 'depends on HAS_DMA'.

The only architectures that don't have that are m68k, m32r, h8300, s390 and microblaze. More research has shown that they all found a different way to disable the ATA drivers already, except microblaze.

Alan, you objected the patch initially (and loudly), but maybe you can reconsider this. The only actual effect that my patch has is to allow an allyesconfig build on microblaze and that will implement dma-mapping.h in the next version.

All existing architectures do not care at all about this change, unless I'm missing something.

Besides, all the other users of the DMA mapping API also depend on CONFIG_HAS_DMA.

	Arnd <><
#21 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 18 lines · Arnd Bergmann
Quoted 3 lines · Tejun Heo

Don't know much history here but I don't wanna sprinkle ifdefs around in libata so I would much prefer dummy implementation which doesn't fail compile.

My original patch did that by adding 'depends on HAS_DMA'.

The only architectures that don't have that are m68k, m32r, h8300, s390 and microblaze. More research has shown that they all found a different way to disable the ATA drivers already, except microblaze.

Alan, you objected the patch initially (and loudly), but maybe you can reconsider this. The only actual effect that my patch has is to allow an allyesconfig build on microblaze and that will implement dma-mapping.h in the next version.

Quoted 5 lines

All existing architectures do not care at all about this change, unless I'm missing something.

Besides, all the other users of the DMA mapping API also depend on CONFIG_HAS_DMA.

Yes, it fixes the compile problem by preventing libata from being compiled at all. But the point is that libata should be able to work without DMA support.

author maintainer
#22 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 22 lines · Robert Hancock
Quoted 21 lines · Arnd Bergmann
Quoted 3 lines · Tejun Heo

Don't know much history here but I don't wanna sprinkle ifdefs around in libata so I would much prefer dummy implementation which doesn't fail compile.

My original patch did that by adding 'depends on HAS_DMA'.

The only architectures that don't have that are m68k, m32r, h8300, s390 and microblaze. More research has shown that they all found a different way to disable the ATA drivers already, except microblaze.

Alan, you objected the patch initially (and loudly), but maybe you can reconsider this. The only actual effect that my patch has is to allow an allyesconfig build on microblaze and that will implement dma-mapping.h in the next version.

All existing architectures do not care at all about this change, unless I'm missing something.

Quoted 6 lines
Quoted 2 lines

Besides, all the other users of the DMA mapping API also depend on CONFIG_HAS_DMA.

Yes, it fixes the compile problem by preventing libata from being compiled at all. But the point is that libata should be able to work without DMA support.

Please reread my explanations above and your own reply from last thursday. The case is entirely theoretical, as all platforms (except microblaze, which is getting fixed) either set HAS_DMA or don't allow building ATA drivers anyway. Platforms that don't support DMA can just define CONFIG_HAS_DMA and do what you suggested:

Quoted 2 lines · Robert Hancock

Wouldn't the easiest solution be to just dummy out the DMA API calls on this platform to always fail? That would fix these compile problems..

	Arnd <><
#23 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

Quoted 8 lines · Arnd Bergmann

On Sunday 17 May 2009, Robert Hancock wrote:
Please reread my explanations above and your own reply from last thursday. The case is entirely theoretical, as all platforms (except microblaze, which is getting fixed) either set HAS_DMA or
don't allow building ATA drivers anyway. Platforms that don't support
DMA can just define CONFIG_HAS_DMA and do what you suggested:

Quoted 1 line · Robert Hancock

Wouldn't the easiest solution be to just dummy out the DMA API calls on this platform to always fail? That would fix these compile problems..

That's what needs to happen. We provide no-op functions for e.g. PCI and x86 DMI, for platforms where this support does not exist.

Pretty much all architectures support some form of ATA. m68k, m32r, h8300 and microblaze all have IDE interface, which means that libata needs to work on that platform.

The only !ATA arch in the entire kernel is s390, AFAICT.

Jeff

author maintainer
#24 lore raw

PATCH 1/1 asm-generic: add a dma-mapping.h file

h8300 and m32r currently do not provide a DMA mapping API and therefore cannot use the ATA drivers. This adds a generic version of dma-mapping.h for architectures that have none or very minimal actual support for DMA in hardware and makes the two architectures use it.

---

Quoted 8 lines · On Sunday 17 May 2009 20:05:54 Jeff Garzik wrote:

That's what needs to happen. We provide no-op functions for e.g. PCI and x86 DMI, for platforms where this support does not exist.

Pretty much all architectures support some form of ATA. m68k, m32r, h8300 and microblaze all have IDE interface, which means that libata needs to work on that platform.

The only !ATA arch in the entire kernel is s390, AFAICT.

m68k only defines NO_DMA for Sun3 and Dragonball. Sun3 does not have ATA, Dragonball could probably just enable HAS_DMA.

---
 arch/h8300/Kconfig                   |    2 +-
 arch/h8300/include/asm/dma-mapping.h |    1 +
 arch/m32r/Kconfig                    |    2 +-
 arch/m32r/include/asm/dma-mapping.h  |    1 +
 include/asm-generic/dma-mapping.h    |  399 ++++++++++++++++++++++++++++++++++
 5 files changed, 403 insertions(+), 2 deletions(-)
 create mode 100644 arch/h8300/include/asm/dma-mapping.h
 create mode 100644 arch/m32r/include/asm/dma-mapping.h
 create mode 100644 include/asm-generic/dma-mapping.h
arch/h8300/Kconfig +1 -1
index 9420648..36a037d 100644
@@ -74,7 +74,7 @@ config NO_IOPORT
 	def_bool y
 
 config NO_DMA
-	def_bool y
+	def_bool n
 
 config ISA
 	bool
arch/h8300/include/asm/dma-mapping.h new file +1 -0
new file mode 100644
index 0000000..e7e1690
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
arch/m32r/Kconfig +1 -1
index cabba33..57ad603 100644
@@ -35,7 +35,7 @@ config NO_IOPORT
 	def_bool y
 
 config NO_DMA
-	def_bool y
+	def_bool n
 
 config HZ
 	int
arch/m32r/include/asm/dma-mapping.h new file +1 -0
new file mode 100644
index 0000000..e7e1690
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
include/asm-generic/dma-mapping.h new file +399 -0

399 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#25 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 44 lines · Arnd Bergmann
include/asm-generic/dma-mapping.h new file +41 -0
@@ -0,0 +1,399 @@
+#ifndef _ASM_GENERIC_DMA_MAPPING_H
+#define _ASM_GENERIC_DMA_MAPPING_H
+/*
+ * This provides a no-op variant of the DMA mapping API,
+ * for use by architectures that do not actually support
+ * DMA, or that are fully consistent and linear-mapped
+ * in their DMA implementation.
+ */
+
+#include <asm/scatterlist.h>
+
+/*
+ * If any driver asks for DMA, it's not supported.
+ */
+#ifndef dma_supported
+static inline int
+dma_supported(struct device *dev, u64 mask)
+{
+       return 0;
+}
+#endif
+
+#ifndef dma_set_mask
+static inline int
+dma_set_mask(struct device *dev, u64 dma_mask)
+{
+       if (!dev->dma_mask || !dma_supported(dev, dma_mask))
+               return -EIO;
+
+       *dev->dma_mask = dma_mask;
+       return 0;
+}
+#endif
+
+/**
+ * dma_alloc_coherent - allocate consistent memory for DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @size: required memory size
+ * @handle: bus-specific DMA address
+ *
+ * Allocate some uncached, unbuffered memory for a device for

include/asm-generic/dma-mapping.h line 51

Quoted 10 lines
include/asm-generic/dma-mapping.h new file +10 -0
+ * performing DMA.  This function allocates pages, and will
+ * return the CPU-viewed address, and sets @handle to be the
+ * device-viewed address.
+ */
+#ifndef dma_alloc_coherent
+static inline void *
+dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
+                  gfp_t flag)
+{
+       void *virt = kmalloc(size, flag);

kmalloc() may fail.

include/asm-generic/dma-mapping.h line 52

Quoted 1 line
include/asm-generic/dma-mapping.h new file +1 -0
+       *dma_handle = virt_to_phys(virt);

Not all variants of virt_to_phys() may handle the NULL case very well. I took a statistically invalid sample: some just cast to unsigned long, other subtract PAGE_OFFSET.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#26 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 9 lines · Geert Uytterhoeven

include/asm-generic/dma-mapping.h line 51

Quoted 6 lines
include/asm-generic/dma-mapping.h new file +6 -0
+#ifndef dma_alloc_coherent
+static inline void *
+dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
+                  gfp_t flag)
+{
+       void *virt = kmalloc(size, flag);

kmalloc() may fail.

Quoted 5 lines
Quoted 1 line

+       *dma_handle = virt_to_phys(virt);

Not all variants of virt_to_phys() may handle the NULL case very well. I took a statistically invalid sample: some just cast to unsigned long, other subtract PAGE_OFFSET.

Right. It should not really hurt, because all users need to check virt before using dma_handle, but I can fix it just to be sure.

I'll wait for comments from Fujita Tomonori and others before I repost.

	Arnd <><
#27 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

In reply to Arnd Bergmann
Quoted 90 lines · On Sun, 17 May 2009 22:45:21 +0000 Arnd Bergmann <[email protected]> wrote:

h8300 and m32r currently do not provide a DMA mapping API and therefore cannot use the ATA drivers. This adds a generic version of dma-mapping.h for architectures that have none or very minimal actual support for DMA in hardware and makes the two architectures use it.

---

Quoted 8 lines · On Sunday 17 May 2009 20:05:54 Jeff Garzik wrote:

That's what needs to happen. We provide no-op functions for e.g. PCI and x86 DMI, for platforms where this support does not exist.

Pretty much all architectures support some form of ATA. m68k, m32r, h8300 and microblaze all have IDE interface, which means that libata needs to work on that platform.

The only !ATA arch in the entire kernel is s390, AFAICT.

m68k only defines NO_DMA for Sun3 and Dragonball. Sun3 does not have ATA, Dragonball could probably just enable HAS_DMA.

---
 arch/h8300/Kconfig                   |    2 +-
 arch/h8300/include/asm/dma-mapping.h |    1 +
 arch/m32r/Kconfig                    |    2 +-
 arch/m32r/include/asm/dma-mapping.h  |    1 +
 include/asm-generic/dma-mapping.h    |  399 ++++++++++++++++++++++++++++++++++
 5 files changed, 403 insertions(+), 2 deletions(-)
 create mode 100644 arch/h8300/include/asm/dma-mapping.h
 create mode 100644 arch/m32r/include/asm/dma-mapping.h
 create mode 100644 include/asm-generic/dma-mapping.h
arch/h8300/Kconfig +1 -1
index 9420648..36a037d 100644
@@ -74,7 +74,7 @@ config NO_IOPORT
 	def_bool y
 
 config NO_DMA
-	def_bool y
+	def_bool n
 
 config ISA
 	bool
arch/h8300/include/asm/dma-mapping.h new file +1 -0
new file mode 100644
index 0000000..e7e1690
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
arch/m32r/Kconfig +1 -1
index cabba33..57ad603 100644
@@ -35,7 +35,7 @@ config NO_IOPORT
 	def_bool y
 
 config NO_DMA
-	def_bool y
+	def_bool n
 
 config HZ
 	int
arch/m32r/include/asm/dma-mapping.h new file +1 -0
new file mode 100644
index 0000000..e7e1690
@@ -0,0 +1 @@
+#include <asm-generic/dma-mapping.h>
include/asm-generic/dma-mapping.h new file +11 -0
new file mode 100644
index 0000000..5a14fed
@@ -0,0 +1,399 @@
+#ifndef _ASM_GENERIC_DMA_MAPPING_H
+#define _ASM_GENERIC_DMA_MAPPING_H
+/*
+ * This provides a no-op variant of the DMA mapping API,
+ * for use by architectures that do not actually support
+ * DMA, or that are fully consistent and linear-mapped
+ * in their DMA implementation.
+ */
+
+#include <asm/scatterlist.h>
+

include/asm-generic/dma-mapping.h line 21

Quoted 10 lines
include/asm-generic/dma-mapping.h new file +10 -0
+/*
+ * If any driver asks for DMA, it's not supported.
+ */
+#ifndef dma_supported
+static inline int
+dma_supported(struct device *dev, u64 mask)
+{
+	return 0;
+}
+#endif

NACK'ed, sorry.

- these idndef tricks are really ugly and wrong.

- these functions are not generic at all.

- it's confusing to have two ways to handle this issue; dma-mapping-broken.h and dma-mapping.h.

author maintainer
#28 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 2 lines · FUJITA Tomonori

NACK'ed, sorry.

I had no idea how hard it would get to fix a simple allyesconfig build error. This is the third time that a new approach to getting ATA to build on all platforms is gets a NAK...

Quoted 2 lines

- these idndef tricks are really ugly and wrong.
- these functions are not generic at all.

I was trying to do two things at once:

- provide a default implementation for each function that an architecture can override, therefore the #ifdef magic.
- Have a minimal working implementation of the API that at least makes sense for architectures that do not support DMA, but want to share some of the code.

Ten of the existing architectures simply try do a linear mapping, and that should easily be possible in a generic way not too different from what I posted. Would you agree to a patch that works with the same code on e.g. arm, microblaze, mn10300 and sh and uses only a few #ifdefs?

Quoted 2 lines

- it's confusing to have two ways to handle this issue; dma-mapping-broken.h and dma-mapping.h.

We actually already have three ways to handle this right now:

- dma-mapping-broken.h:
only used on Sun3 m68k, i.e. not interesting any more, plus it does not solve the question of how to build ATA drivers on architectures without DMA.
- selecting NO_DMA:
This works fine for everything except ATA. All other drivers using dma-mapping.h either depend on HAS_DMA or sprinkle their files with #ifdef.
- adding a bogus dma-mapping.h: cris, um and microblaze currently set HAS_DMA but add a dma-mapping.h that allows stuff to compile but cannot actually work.

I think that dma-mapping-broken.h has served its purpose and we should now have two implementations in asm-generic, the one you posted recently for ia64, x86, parisc, powerpc and sparc64 and one for all architectures that only have linear mappings. The version I posted is certainly not generic enough for those, but I can keep improving it.

	Arnd <><
#29 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 9 lines · On Mon, 18 May 2009 16:45:24 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 2 lines · FUJITA Tomonori

NACK'ed, sorry.

I had no idea how hard it would get to fix a simple allyesconfig build error. This is the third time that a new approach to getting ATA to build on all platforms is gets a NAK...

Quoted 8 lines
Quoted 2 lines

- these idndef tricks are really ugly and wrong.
- these functions are not generic at all.

I was trying to do two things at once:

- provide a default implementation for each function that an architecture can override, therefore the #ifdef magic.

I know what you tried with #ifdef but having something like '#define dma_map_sg' in arch's dma-mapping.h is unacceptable.

Quoted 4 lines

- Have a minimal working implementation of the API that at least makes sense for architectures that do not support DMA, but want to share some of the code.

Well, it might make sense but we don't call architectures that don't support DMA 'generic'.

Quoted 3 lines

Ten of the existing architectures simply try do a linear mapping, and that should easily be possible in a generic way not too different from what I posted.

Your proposal doesn't work with arch/x86/kernel/pci-nommu.c, which is trying a linear mapping, what you are talking about.

Quoted 3 lines

Would you agree to a patch that works with the same code on e.g. arm, microblaze, mn10300 and sh and uses only a few #ifdefs?

Having such helper for a linear mapping might be helpful but your approach is wrong.

author maintainer
#30 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 6 lines · FUJITA Tomonori
Quoted 3 lines

Would you agree to a patch that works with the same code on e.g. arm, microblaze, mn10300 and sh and uses only a few #ifdefs?

Having such helper for a linear mapping might be helpful but your approach is wrong.

Do you like this approach better? I've merged a few architectures that were relatively simple. This file should be usable by all architectures that have a linear mapping and are either fully coherent (like cris) or just require flushing the dcache when passing a buffer to the device.

It's become pretty obvious where some of my bugs were in the previous code, I hopefully did better this time and maybe you find the rest. I've also added the dma debugging stuff in here and fixed a number of bugs in all the different architectures on the way, but I can send separate patches for those before doing the merge.

I've also tried merging frv and m68k, but they have some peculiarities that made it slightly harder.

 include/asm-generic/dma-mapping-linear.h |  391 +++++++++++++++++++++++++++++
 arch/avr32/include/asm/dma-mapping.h     |  408 ++++---------------------------
 arch/blackfin/include/asm/dma-mapping.h  |  118 +-------
 arch/cris/include/asm/dma-mapping.h      |  194 +-------------
 arch/mn10300/include/asm/dma-mapping.h   |  266 ++------------------
 arch/sh/include/asm/dma-mapping.h        |  258 ++-----------------
 arch/xtensa/include/asm/dma-mapping.h    |  220 +++-------------
 7 files changed, 606 insertions(+), 1249 deletions(-)
include/asm-generic/dma-mapping-linear.h new file +391 -0
new file mode 100644
index 0000000..13f37db
@@ -0,0 +1,391 @@
+#ifndef __ASM_GENERIC_DMA_MAPPING_H
+#define __ASM_GENERIC_DMA_MAPPING_H
+
+#include <linux/mm.h>
+#include <linux/device.h>
+#include <linux/dma-debug.h>
+#include <linux/scatterlist.h>
+#include <asm/cacheflush.h>
+#include <asm/io.h>
+
+#ifdef CONFIG_DMA_COHERENT
+/*
+ * An architecture should override these if it needs to
+ * perform cache flushes before passing bus addresses
+ * to a device.
+ * It can either do a full flush in dma_coherent_dev
+ * and return 1 from there, or implement more specific
+ * synchronization in dma_cache_sync, which will be
+ * applied separately to each sg element.
+ */
+static inline int
+dma_coherent_dev(struct device *dev)
+{
+	return 1;
+}
+
+static inline void
+dma_cache_sync(struct device *dev, void *cpu_addr, size_t size,
+	       enum dma_data_direction direction)
+{
+}
+
+/**
+ * dma_alloc_coherent - allocate consistent memory for DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @size: required memory size
+ * @handle: bus-specific DMA address
+ *
+ * Allocate some uncached, unbuffered memory for a device for
+ * performing DMA.  This function allocates pages, and will
+ * return the CPU-viewed address, and sets @handle to be the
+ * device-viewed address.
+ */
+void *dma_alloc_coherent(struct device *dev, size_t size,
+				dma_addr_t *dma_handle, gfp_t flag)
+{
+	void *ret;
+	struct page *page;
+	int node = dev_to_node(dev);
+
+	/* ignore region specifiers */
+	flag  &= ~(__GFP_HIGHMEM);
+
+	page = alloc_pages_node(node, flag, get_order(size));
+	if (page == NULL)
+		return NULL;
+	ret = page_address(page);
+	memset(ret, 0, size);
+	*dma_handle = virt_to_abs(ret) + get_dma_direct_offset(dev);
+
+	return ret;
+}
+
+/**
+ * dma_free_coherent - free memory allocated by dma_alloc_coherent
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @size: size of memory originally requested in dma_alloc_coherent
+ * @cpu_addr: CPU-view address returned from dma_alloc_coherent
+ * @handle: device-view address returned from dma_alloc_coherent
+ *
+ * Free (and unmap) a DMA buffer previously allocated by
+ * dma_alloc_coherent().
+ *
+ * References to memory and mappings associated with cpu_addr/handle
+ * during and after this call executing are illegal.
+ */
+void dma_free_coherent(struct device *dev, size_t size,
+			      void *vaddr, dma_addr_t dma_handle)
+{
+	free_pages((unsigned long)vaddr, get_order(size));
+}
+#else
+extern void *
+dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
+		   gfp_t flag);
+
+extern void
+dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
+		  dma_addr_t dma_handle);
+#endif
+
+#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+
+/**
+ * dma_map_single - map a single buffer for streaming DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @cpu_addr: CPU direct mapped address of buffer
+ * @size: size of buffer to map
+ * @dir: DMA transfer direction
+ *
+ * Ensure that any data held in the cache is appropriately discarded
+ * or written back.
+ *
+ * The device owns this memory once this call has completed.  The CPU
+ * can regain ownership by calling dma_unmap_single() or dma_sync_single().
+ */
+static inline dma_addr_t
+dma_map_single(struct device *dev, void *ptr, size_t size,
+	       enum dma_data_direction direction)
+{
+	dma_addr_t dma_addr = virt_to_bus(ptr);
+	BUG_ON(!valid_dma_direction(direction));
+
+	if (!dma_coherent_dev(dev))
+		dma_cache_sync(dev, ptr, size, direction);
+
+	debug_dma_map_page(dev, virt_to_page(ptr),
+			   (unsigned long)ptr & ~PAGE_MASK, size,
+			   direction, dma_addr, true);
+
+	return dma_addr;
+}
+
+/**
+ * dma_unmap_single - unmap a single buffer previously mapped
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @handle: DMA address of buffer
+ * @size: size of buffer to map
+ * @dir: DMA transfer direction
+ *
+ * Unmap a single streaming mode DMA translation.  The handle and size
+ * must match what was provided in the previous dma_map_single() call.
+ * All other usages are undefined.
+ *
+ * After this call, reads by the CPU to the buffer are guaranteed to see
+ * whatever the device wrote there.
+ */
+static inline void
+dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
+		 enum dma_data_direction direction)
+{
+	debug_dma_unmap_page(dev, dma_addr, size, direction, true);
+}
+
+/**
+ * dma_map_sg - map a set of SG buffers for streaming mode DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @sg: list of buffers
+ * @nents: number of buffers to map
+ * @dir: DMA transfer direction
+ *
+ * Map a set of buffers described by scatterlist in streaming
+ * mode for DMA.  This is the scatter-gather version of the
+ * above pci_map_single interface.  Here the scatter gather list
+ * elements are each tagged with the appropriate dma address
+ * and length.  They are obtained via sg_dma_{address,length}(SG).
+ *
+ * NOTE: An implementation may be able to use a smaller number of
+ *       DMA address/length pairs than there are SG table elements.
+ *       (for example via virtual mapping capabilities)
+ *       The routine returns the number of addr/length pairs actually
+ *       used, at most nents.
+ *
+ * Device ownership issues as mentioned above for pci_map_single are
+ * the same here.
+ */
+static inline int
+dma_map_sg(struct device *dev, struct scatterlist *sglist, int nents,
+	   enum dma_data_direction direction)
+{
+	struct scatterlist *sg;
+	int i, sync;
+
+	BUG_ON(!valid_dma_direction(direction));
+	WARN_ON(nents == 0 || sglist[0].length == 0);
+
+	sync = !dma_coherent_dev(dev);
+
+	for_each_sg(sglist, sg, nents, i) {
+		BUG_ON(!sg_page(sg));
+
+		sg->dma_address = page_to_bus(sg_page(sg)) + sg->offset;
+		sg_dma_len(sg) = sg->length;
+		if (sync)
+			dma_cache_sync(dev, sg_virt(sg), sg->length, direction);
+	}
+
+	debug_dma_map_sg(dev, sg, nents, i, direction);
+
+	return nents;
+}
+
+/**
+ * dma_unmap_sg - unmap a set of SG buffers mapped by dma_map_sg
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @sg: list of buffers
+ * @nents: number of buffers to map
+ * @dir: DMA transfer direction
+ *
+ * Unmap a set of streaming mode DMA translations.
+ * Again, CPU read rules concerning calls here are the same as for
+ * pci_unmap_single() above.
+ */
+static inline void
+dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
+	     enum dma_data_direction direction)
+{
+	debug_dma_unmap_sg(dev, sg, nhwentries, direction);
+}
+
+/**
+ * dma_map_page - map a portion of a page for streaming DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @page: page that buffer resides in
+ * @offset: offset into page for start of buffer
+ * @size: size of buffer to map
+ * @dir: DMA transfer direction
+ *
+ * Ensure that any data held in the cache is appropriately discarded
+ * or written back.
+ *
+ * The device owns this memory once this call has completed.  The CPU
+ * can regain ownership by calling dma_unmap_page() or dma_sync_single().
+ */
+static inline dma_addr_t
+dma_map_page(struct device *dev, struct page *page, unsigned long offset,
+	     size_t size, enum dma_data_direction direction)
+{
+	return dma_map_single(dev, page_address(page) + offset,
+			      size, direction);
+}
+
+/**
+ * dma_unmap_page - unmap a buffer previously mapped through dma_map_page()
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @handle: DMA address of buffer
+ * @size: size of buffer to map
+ * @dir: DMA transfer direction
+ *
+ * Unmap a single streaming mode DMA translation.  The handle and size
+ * must match what was provided in the previous dma_map_single() call.
+ * All other usages are undefined.
+ *
+ * After this call, reads by the CPU to the buffer are guaranteed to see
+ * whatever the device wrote there.
+ */
+static inline void
+dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
+	       enum dma_data_direction direction)
+{
+	dma_unmap_single(dev, dma_address, size, direction);
+}
+
+/**
+ * dma_sync_single_for_cpu
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @handle: DMA address of buffer
+ * @size: size of buffer to map
+ * @dir: DMA transfer direction
+ *
+ * Make physical memory consistent for a single streaming mode DMA
+ * translation after a transfer.
+ *
+ * If you perform a dma_map_single() but wish to interrogate the
+ * buffer using the cpu, yet do not wish to teardown the DMA mapping,
+ * you must call this function before doing so.  At the next point you
+ * give the DMA address back to the card, you must first perform a
+ * dma_sync_single_for_device, and then the device again owns the
+ * buffer.
+ */
+static inline void
+dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
+			enum dma_data_direction direction)
+{
+	debug_dma_sync_single_for_cpu(dev, dma_handle, size, direction);
+}
+
+static inline void
+dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
+			      unsigned long offset, size_t size,
+			      enum dma_data_direction direction)
+{
+	debug_dma_sync_single_range_for_cpu(dev, dma_handle,
+					    offset, size, direction);
+}
+
+/**
+ * dma_sync_sg_for_cpu
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @sg: list of buffers
+ * @nents: number of buffers to map
+ * @dir: DMA transfer direction
+ *
+ * Make physical memory consistent for a set of streaming
+ * mode DMA translations after a transfer.
+ *
+ * The same as dma_sync_single_for_* but for a scatter-gather list,
+ * same rules and usage.
+ */
+static inline void
+dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents,
+		    enum dma_data_direction direction)
+{
+	debug_dma_sync_sg_for_cpu(dev, sg, nents, direction);
+}
+
+static inline void
+dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
+			   size_t size, enum dma_data_direction direction)
+{
+	if (!dma_coherent_dev(dev))
+		dma_cache_sync(dev, bus_to_virt(dma_handle), size, direction);
+	debug_dma_sync_single_for_device(dev, dma_handle, size, direction);
+}
+
+static inline void
+dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
+				 unsigned long offset, size_t size,
+				 enum dma_data_direction direction)
+{
+	if (!dma_coherent_dev(dev))
+		dma_cache_sync(dev, bus_to_virt(dma_handle), size, direction);
+	debug_dma_sync_single_range_for_device(dev, dma_handle,
+					       offset, size, direction);
+}
+
+static inline void
+dma_sync_sg_for_device(struct device *dev, struct scatterlist *sglist,
+		       int nents, enum dma_data_direction direction)
+{
+	struct scatterlist *sg;
+	int i;
+
+	if (!dma_coherent_dev(dev))
+		for_each_sg(sglist, sg, nents, i)
+			dma_cache_sync(dev, sg_virt(sg), sg->length, direction);
+
+	debug_dma_sync_sg_for_device(dev, sg, nents, direction);
+}
+
+static inline int
+dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+	return 0;
+}
+
+/*
+ * Return whether the given device DMA address mask can be supported
+ * properly.  For example, if your device can only drive the low 24-bits
+ * during bus mastering, then you would pass 0x00ffffff as the mask
+ * to this function.
+ */
+static inline int
+dma_supported(struct device *dev, u64 mask)
+{
+	/*
+	 * we fall back to GFP_DMA when the mask isn't all 1s,
+	 * so we can't guarantee allocations that must be
+	 * within a tighter range than GFP_DMA.
+	 */
+	if (mask < 0x00ffffff)
+		return 0;
+
+	return 1;
+}
+
+static inline int
+dma_set_mask(struct device *dev, u64 dma_mask)
+{
+	if (!dev->dma_mask || !dma_supported(dev, dma_mask))
+		return -EIO;
+
+	*dev->dma_mask = dma_mask;
+
+	return 0;
+}
+
+static inline int
+dma_get_cache_alignment(void)
+{
+	return L1_CACHE_BYTES;
+}
+
+static inline int
+dma_is_consistent(struct device *dev, dma_addr_t dma_addr)
+{
+	return dma_coherent_dev(dev);
+}
+
+#endif /* __ASM_GENERIC_DMA_MAPPING_H */
arch/avr32/include/asm/dma-mapping.h +59 -349

408 lines not on this page · raw message

arch/blackfin/include/asm/dma-mapping.h +20 -98

118 lines not on this page · raw message

arch/cris/include/asm/dma-mapping.h +24 -170

194 lines not on this page · raw message

arch/mn10300/include/asm/dma-mapping.h +32 -234

266 lines not on this page · raw message

arch/sh/include/asm/dma-mapping.h +39 -219

258 lines not on this page · raw message

arch/xtensa/include/asm/dma-mapping.h +41 -179

220 lines not on this page · raw message

#31 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · FUJITA Tomonori
Quoted 3 lines

Would you agree to a patch that works with the same code on e.g. arm, microblaze, mn10300 and sh and uses only a few #ifdefs?

Quoted 8 lines
Quoted 2 lines

Having such helper for a linear mapping might be helpful but your approach is wrong.

Do you like this approach better? I've merged a few architectures that were relatively simple. This file should be usable by all architectures that have a linear mapping and are either fully coherent (like cris) or just require flushing the dcache when passing a buffer to the device.

I've reviewed the first bit and it looks fine (so far to me). Two related bugs:
1) dma_alloc_coherent() is not respecting the coherent_dma_mask field in device.h:struct device.
2) dma_map_single() is not respecting dma_mask in struct pci_dev (and pointer from struct device).

...

Quoted 10 lines

+/**
+ * dma_alloc_coherent - allocate consistent memory for DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @size: required memory size
+ * @handle: bus-specific DMA address
+ *
+ * Allocate some uncached, unbuffered memory for a device for
+ * performing DMA.  This function allocates pages, and will
+ * return the CPU-viewed address, and sets @handle to be the
+ * device-viewed address.

Key here is the DMA is coherent, bi-directional, and the DMA address fit in the coherent_dma_mask. "uncached/unbuffered" is one way of doing this and is how we've implemented "DMA coherency" on parisc platforms that don't have an IOMMU (which all have PA1.1 CPUs) - see arch/parisc/kernel/pci-dma.c

And I'll confess pci-dma.c doesn't implement support for coherent_dma_mask . AFAIK, the targeted platforms have < 4GB of RAM and only PCI devices. ISA support is completely missing and is the only case this class of machines need coherent_dma_mask support.

More comments on how DMA works for PARISC in
arch/parisc/include/asm/dma-mapping.h

hth,
grant

author maintainer
#32 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 5 lines · On Tuesday 19 May 2009 17:01:27 Grant Grundler wrote:

On Tue, May 19, 2009 at 9:22 AM, Arnd Bergmann <[email protected]> wrote:
I've reviewed the first bit and it looks fine (so far to me). Two related bugs:
1) dma_alloc_coherent() is not respecting the coherent_dma_mask field in device.h:struct device.

Hmm, I've taken that function unchanged from powerpc. I guess that means that powerpc is broken here as well, right?

Quoted 2 lines

2) dma_map_single() is not respecting dma_mask in struct pci_dev (and pointer from struct device).

What should it do with the mask? All the architectures I've looked at as well as arch/parisc/kernel/pci-dma.c ignore it. Should dma_map_* just fail in case of an address exceeding dma_mask?

Quoted 11 lines
Quoted 10 lines

+/**
+ * dma_alloc_coherent - allocate consistent memory for DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @size: required memory size
+ * @handle: bus-specific DMA address
+ *
+ * Allocate some uncached, unbuffered memory for a device for
+ * performing DMA. This function allocates pages, and will
+ * return the CPU-viewed address, and sets @handle to be the
+ * device-viewed address.

Quoted 4 lines

Key here is the DMA is coherent, bi-directional, and the DMA address fit in the coherent_dma_mask. "uncached/unbuffered" is one way of doing this and is how we've implemented "DMA coherency" on parisc platforms that don't have an IOMMU (which all have PA1.1 CPUs) - see arch/parisc/kernel/pci-dma.c

All the architectures I've looked at come with their own version of _alloc_coherent that works in similar ways to allocate an uncached mapping. Now that you mention this, I realize that there is a bug on cris, which after my patch either has two conflicting implementations of dma_{alloc,free}_coherent, or is missing the dma_coherent_dev() function that is hidden inside of the same #ifdef. The one in arch/cris/arch-v32/drivers/pci/dma.c does seem to be correct though.

	Arnd <><
#33 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 9 lines · Arnd Bergmann
Quoted 5 lines · On Tuesday 19 May 2009 17:01:27 Grant Grundler wrote:

On Tue, May 19, 2009 at 9:22 AM, Arnd Bergmann <[email protected]> wrote:
I've reviewed the first bit and it looks fine (so far to me). Two related bugs:
1) dma_alloc_coherent() is not respecting the coherent_dma_mask field in device.h:struct device.

Hmm, I've taken that function unchanged from powerpc. I guess that means that powerpc is broken  here as well, right?

Not necessarily. It might work fine for the subset of machines that use that code.
But generic code should use the masks - even if they are set to ~0UL.

Quoted 4 lines
Quoted 2 lines

2) dma_map_single() is not respecting dma_mask in struct pci_dev (and pointer from struct device).

What should it do with the mask?

Verify or enforce that the physical memory is allocated from a memory pool suitable for
use by that device. If any bits "stick out" from the address (vs the mask), the device
won't be able to DMA to that address and very likely truncate the address.

By default the PCI dma_mask is 32-bits. Drivers that can support more than 32-bits
(some PCI, most PCI-X and all PCI-E devices) will be calling pci_set_dma_mask() and pci_set_coherent_dma_mask() or the equivalent DMA API call.

Quoted 2 lines

All the architectures I've looked
at as well as arch/parisc/kernel/pci-dma.c ignore it.

pci-dma.c ignores it for the same reason it ignores coherent_dma_mask. None of those parisc machines have host memory at a physical address that is NOT reachable via DMA by *all* known/supported devices.

Maybe it's ok and we just need a comment stating the constraints of the generic code.

And there must be some way (e.g. dma_support()) to verify the highest physical memory location is reachable by the given device. So that would be another way to enforce the mask.

Quoted 1 line

Should dma_map_* just fail in case of an address exceeding dma_mask?

That would probably be correct behavior too. But my gut feeling is we don't want the device driver module to load unless we know the device can DMA to any possible host memory location handed to dma_map_single().
My preference is the initialization path fail first. dma_alloc_coherent() is generally in the initialization path after the drivers call pci_set*mask().

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

+/**
+ * dma_alloc_coherent - allocate consistent memory for DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @size: required memory size
+ * @handle: bus-specific DMA address
+ *
+ * Allocate some uncached, unbuffered memory for a device for
+ * performing DMA.  This function allocates pages, and will
+ * return the CPU-viewed address, and sets @handle to be the
+ * device-viewed address.

Quoted 7 lines
Quoted 4 lines

Key here is the DMA is coherent, bi-directional, and the DMA address fit in the coherent_dma_mask. "uncached/unbuffered" is one way of doing this and is how we've implemented "DMA coherency" on parisc platforms that don't have an IOMMU (which all have PA1.1 CPUs) - see arch/parisc/kernel/pci-dma.c

All the architectures I've looked at come with their own version of _alloc_coherent that works in similar ways to allocate an uncached mapping.

That's what I expected. I'm pretty sure parisc could use a generic implementation
for PA7100LC and PA7300LC CPUs (other parisc CPUs/memory controllers don't support uncached mappings to host memory). So we would need run-time detection and set dma_ops appropriately.

Quoted 6 lines

Now that you
mention this, I realize that there is a bug on cris, which after my patch either has two conflicting implementations of dma_{alloc,free}_coherent, or is missing the dma_coherent_dev() function that is hidden inside of the same #ifdef. The one in arch/cris/arch-v32/drivers/pci/dma.c does seem to be correct though.

Ok - cool!

thanks,
grant
--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#34 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

In reply to Arnd Bergmann
Quoted 92 lines · On Tue, 19 May 2009 18:22:47 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 6 lines · FUJITA Tomonori
Quoted 3 lines

Would you agree to a patch that works with the same code on e.g. arm, microblaze, mn10300 and sh and uses only a few #ifdefs?

Having such helper for a linear mapping might be helpful but your approach is wrong.

Do you like this approach better? I've merged a few architectures that were relatively simple. This file should be usable by all architectures that have a linear mapping and are either fully coherent (like cris) or just require flushing the dcache when passing a buffer to the device.

It's become pretty obvious where some of my bugs were in the previous code, I hopefully did better this time and maybe you find the rest. I've also added the dma debugging stuff in here and fixed a number of bugs in all the different architectures on the way, but I can send separate patches for those before doing the merge.

I've also tried merging frv and m68k, but they have some peculiarities that made it slightly harder.

 include/asm-generic/dma-mapping-linear.h |  391 +++++++++++++++++++++++++++++
 arch/avr32/include/asm/dma-mapping.h     |  408 ++++---------------------------
 arch/blackfin/include/asm/dma-mapping.h  |  118 +-------
 arch/cris/include/asm/dma-mapping.h      |  194 +-------------
 arch/mn10300/include/asm/dma-mapping.h   |  266 ++------------------
 arch/sh/include/asm/dma-mapping.h        |  258 ++-----------------
 arch/xtensa/include/asm/dma-mapping.h    |  220 +++-------------
 7 files changed, 606 insertions(+), 1249 deletions(-)
include/asm-generic/dma-mapping-linear.h new file +52 -0
new file mode 100644
index 0000000..13f37db
@@ -0,0 +1,391 @@
+#ifndef __ASM_GENERIC_DMA_MAPPING_H
+#define __ASM_GENERIC_DMA_MAPPING_H
+
+#include <linux/mm.h>
+#include <linux/device.h>
+#include <linux/dma-debug.h>
+#include <linux/scatterlist.h>
+#include <asm/cacheflush.h>
+#include <asm/io.h>
+
+#ifdef CONFIG_DMA_COHERENT
+/*
+ * An architecture should override these if it needs to
+ * perform cache flushes before passing bus addresses
+ * to a device.
+ * It can either do a full flush in dma_coherent_dev
+ * and return 1 from there, or implement more specific
+ * synchronization in dma_cache_sync, which will be
+ * applied separately to each sg element.
+ */
+static inline int
+dma_coherent_dev(struct device *dev)
+{
+	return 1;
+}
+
+static inline void
+dma_cache_sync(struct device *dev, void *cpu_addr, size_t size,
+	       enum dma_data_direction direction)
+{
+}
+
+/**
+ * dma_alloc_coherent - allocate consistent memory for DMA
+ * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
+ * @size: required memory size
+ * @handle: bus-specific DMA address
+ *
+ * Allocate some uncached, unbuffered memory for a device for
+ * performing DMA.  This function allocates pages, and will
+ * return the CPU-viewed address, and sets @handle to be the
+ * device-viewed address.
+ */
+void *dma_alloc_coherent(struct device *dev, size_t size,
+				dma_addr_t *dma_handle, gfp_t flag)
+{
+	void *ret;
+	struct page *page;
+	int node = dev_to_node(dev);
+
+	/* ignore region specifiers */
+	flag  &= ~(__GFP_HIGHMEM);

include/asm-generic/dma-mapping-linear.h line 62

Quoted 10 lines
include/asm-generic/dma-mapping-linear.h new file +10 -0
+
+	page = alloc_pages_node(node, flag, get_order(size));
+	if (page == NULL)
+		return NULL;
+	ret = page_address(page);
+	memset(ret, 0, size);
+	*dma_handle = virt_to_abs(ret) + get_dma_direct_offset(dev);
+
+	return ret;
+}

I don't think that this works for all architectures because a returned buffer of alloc_pages_node might not be DMA-capable. Needs to use the coherent_dma_mask here. See x86's dma_alloc_coherent and Alpha's pci-noop.c (there might be other examples).

I think that having a generic header for simple mapping functions (dma_map_single, dma_map_page, dma_map_sg, etc) would be useful but I'm not sure if we can't have a generic version of dma_alloc_coherent. There are lots of architectures that do architecture-specific things. For example, you replaced avr32 dma-mapping.h except for dma_alloc_coherent, which seems to be can't be generic.

BTW, it looks odd to add dma_debug to dma_map_single, etc but not dma_alloc_coherent. ;)

author maintainer
#35 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 4 lines · FUJITA Tomonori

I don't think that this works for all architectures because a returned buffer of alloc_pages_node might not be DMA-capable. Needs to use the coherent_dma_mask here. See x86's dma_alloc_coherent and Alpha's pci-noop.c (there might be other examples).

Right, Grant also made the same comment.

Quoted 9 lines

I think that having a generic header for simple mapping functions (dma_map_single, dma_map_page, dma_map_sg, etc) would be useful but I'm not sure if we can't have a generic version of dma_alloc_coherent.

There are lots of architectures that do architecture-specific things. For example, you replaced avr32 dma-mapping.h except for dma_alloc_coherent, which seems to be can't be generic.

I agree that it won't be fully generic, because all architectures with non-coherent DMA will have to do architecture specific setup to get uncached mappings here. I believe that it can be generic enough to support all architectures that have a cache-coherent PCI bus, hence the #ifdef CONFIG_DMA_COHERENT around this function.

E.g. cris could use a one-line redirect to asm-generic/dma-mapping-linear.h if it did not have the special dma_get_cache_alignment function. I still would like to find a better way to handle this one than to redefine the function.

Quoted 2 lines

BTW, it looks odd to add dma_debug to dma_map_single, etc but not dma_alloc_coherent. ;)

hehe, sure. I copied the dma_debug stuff from sh, the comments from avr32 and the dma_alloc_coherent implementation from powerpc, so I missed this one.

Thanks for the review.

	Arnd <><
#36 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 18 lines · On Fri, 22 May 2009 16:07:32 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 4 lines · FUJITA Tomonori

I don't think that this works for all architectures because a returned buffer of alloc_pages_node might not be DMA-capable. Needs to use the coherent_dma_mask here. See x86's dma_alloc_coherent and Alpha's pci-noop.c (there might be other examples).

Right, Grant also made the same comment.

Quoted 9 lines

I think that having a generic header for simple mapping functions (dma_map_single, dma_map_page, dma_map_sg, etc) would be useful but I'm not sure if we can't have a generic version of dma_alloc_coherent.

There are lots of architectures that do architecture-specific things. For example, you replaced avr32 dma-mapping.h except for dma_alloc_coherent, which seems to be can't be generic.

Quoted 5 lines

I agree that it won't be fully generic, because all architectures with non-coherent DMA will have to do architecture specific setup to get uncached mappings here. I believe that it can be generic enough to support all architectures that have a cache-coherent PCI bus, hence the #ifdef CONFIG_DMA_COHERENT around this function.

I'm not sure. And only mips internally uses CONFIG_DMA_COHERENT.

The reason why many architectures need architecture-specific alloc_coherent() is not about coherent or not.

I like a new helper header file having only generic functions without any ifdef.

Quoted 21 lines

E.g. cris could use a one-line redirect to asm-generic/dma-mapping-linear.h if it did not have the special dma_get_cache_alignment function. I still would like to find a better way to handle this one than to redefine the function.

Quoted 2 lines

BTW, it looks odd to add dma_debug to dma_map_single, etc but not dma_alloc_coherent. ;)

hehe, sure. I copied the dma_debug stuff from sh, the comments from avr32 and the dma_alloc_coherent implementation from powerpc, so I missed this one.

Thanks for the review.

	Arnd <><

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

author maintainer
#37 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 7 lines · FUJITA Tomonori

I'm not sure. And only mips internally uses CONFIG_DMA_COHERENT.

The reason why many architectures need architecture-specific alloc_coherent() is not about coherent or not.

I like a new helper header file having only generic functions without any ifdef.

Ok, fair enough. Fixing dma_alloc_coherent to handle coherent_dma_mask and debug_dma correctly would also make it even bigger, and it was already doing more than you'd want from a commonly used inline function. It may be useful to put it into kernel/dma-coherent.c under an #ifdef, but I'll leave this one alone for now.

I'll leave dma_alloc_coherent and dma_free_coherent as extern declarations then, and leave out the simple dma_coherent_dev() and dma_cache_sync() that all architectures would need to override.

dma_get_cache_alignment() is still less generic than the other functions, as this is still architecture specific. Should I leave that out as well then?

One more idea I had was to rename all the functions in this file from dma_* to dma_linear_*. This would mean that all architectures using it would still need to do something like #define dma_map_sg dma_linear_map_sg for each function they want to use but can easily chose to provide their own ones for those they need different.

It might also help architectures that work with dma_ops, which could then define their own
struct dma_ops dma_ops_linear = {
.map_single = dma_linear_map_single, .map_sg = dma_linear_map_sg,
...
};

Would you prefer me to do it this way, or just keep the standard function names as in the current patch?

	Arnd <><
#38 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 9 lines · On Fri, 22 May 2009 17:05:53 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 7 lines · FUJITA Tomonori

I'm not sure. And only mips internally uses CONFIG_DMA_COHERENT.

The reason why many architectures need architecture-specific alloc_coherent() is not about coherent or not.

I like a new helper header file having only generic functions without any ifdef.

Quoted 6 lines

Ok, fair enough. Fixing dma_alloc_coherent to handle coherent_dma_mask and debug_dma correctly would also make it even bigger, and it was already doing more than you'd want from a commonly used inline function. It may be useful to put it into kernel/dma-coherent.c under an #ifdef, but I'll leave this one alone for now.

Adding #ifdef into kernel/dma-coherent.c is ugly.

Quoted 4 lines

I'll leave dma_alloc_coherent and dma_free_coherent as extern declarations then, and leave out the simple dma_coherent_dev() and dma_cache_sync() that all architectures would need to override.

Right, needs to leave the functions that architectures need to override.

Quoted 3 lines

dma_get_cache_alignment() is still less generic than the other functions, as this is still architecture specific. Should I leave that out as well then?

Yes, I think that only adding generic functions is a better approach. Overriding with #ifdef is really ugly.

Quoted 7 lines

One more idea I had was to rename all the functions in this file from dma_* to dma_linear_*. This would mean that all architectures using it would still need to do something like #define dma_map_sg dma_linear_map_sg for each function they want to use but can easily chose to provide their own ones for those they need different.

Quoted 7 lines

It might also help architectures that work with dma_ops, which could then define their own
struct dma_ops dma_ops_linear = {
.map_single = dma_linear_map_single, .map_sg = dma_linear_map_sg,
...
};

To me, looks like this just makes things complicated needlessly. But I'm not in a position to ACK or NACK this. it's better to ask architecture maintainers.

Quoted 2 lines

Would you prefer me to do it this way, or just keep the standard function names as in the current patch?

author maintainer
#39 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 7 lines · FUJITA Tomonori
Quoted 3 lines

dma_get_cache_alignment() is still less generic than the other functions, as this is still architecture specific. Should I leave that out as well then?

Yes, I think that only adding generic functions is a better approach. Overriding with #ifdef is really ugly.

Ok, will do.

[trimming Cc list a bit, as the subject has changed]

Could you be more specific as to why you think the #ifdef in this file is ugly? I agree that we should always avoid #ifdef in a device driver file or around the usage of an API, but we use it everywhere when defining an optional API, e.g.

#ifdef CONFIG_DMA_API_DEBUG
extern void dma_debug_add_bus(struct bus_type *bus); #else
static inline void dma_debug_add_bus(struct bus_type *bus) {
{
#endif

or

#ifndef clear_user_highpage
static inline void clear_user_highpage(struct page *page, unsigned long vaddr)

{
	void *addr = kmap_atomic(page, KM_USER0);
	clear_user_page(addr, vaddr, page);
	kunmap_atomic(addr, KM_USER0);
}

#endif

This has always made a lot of sense to me when you are defining something that you want to become a No-op in certain configurations or that only needs special handling in a few cases. IIRC, Linus has stated that he prefers the second of the two styles above when you have the choice, which is why I started out that way, while for the dma_debug stuff, the CONFIG_ symbol clearly makes sense.

	Arnd <><
#40 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 9 lines · On Tue, 26 May 2009 13:35:41 +0100 Arnd Bergmann <[email protected]> wrote:
Quoted 7 lines · FUJITA Tomonori
Quoted 3 lines

dma_get_cache_alignment() is still less generic than the other functions, as this is still architecture specific. Should I leave that out as well then?

Yes, I think that only adding generic functions is a better approach. Overriding with #ifdef is really ugly.

Quoted 8 lines

Ok, will do.

[trimming Cc list a bit, as the subject has changed]

Could you be more specific as to why you think the #ifdef in this file is ugly? I agree that we should always avoid #ifdef in a device driver file or around the usage of an API, but we use it everywhere when defining an optional

Seems that people think regard #ifdef in *.c bad, I think.

Quoted 9 lines

API, e.g.

#ifdef CONFIG_DMA_API_DEBUG
extern void dma_debug_add_bus(struct bus_type *bus); #else
static inline void dma_debug_add_bus(struct bus_type *bus) {
{
#endif

This example is inappropriate; a different way to use #ifdef.

This just ensures that dma_debug_add_bus() is available even if CONFIG_DMA_API_DEBUG is disabled.

It's completely different from a way how you use #ifdef.

Quoted 8 lines

#ifndef clear_user_highpage
static inline void clear_user_highpage(struct page *page, unsigned long vaddr)

{
	void *addr = kmap_atomic(page, KM_USER0);
	clear_user_page(addr, vaddr, page);
	kunmap_atomic(addr, KM_USER0);
}

#endif

#define clear_user_highpage(page,vaddr) \
__cpu_clear_user_highpage(page, vaddr)

Personally, I don't fancy this style but it's a matter of taste, I guess.

Quoted 13 lines

This has always made a lot of sense to me when you are defining something that you want to become a No-op in certain configurations or that only needs special handling in a few cases. IIRC, Linus has stated that he prefers the second of the two styles above when you have the choice, which is why I started out that way, while for the dma_debug stuff, the CONFIG_ symbol clearly makes sense.

	Arnd <><

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#41 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

In reply to Arnd Bergmann
Quoted 19 lines · Arnd Bergmann

h8300 and m32r currently do not provide a DMA mapping API and therefore cannot use the ATA drivers. This adds a generic version of dma-mapping.h for architectures that have none or very minimal actual support for DMA in hardware and makes the two architectures use it.

---

Quoted 5 lines · On Sunday 17 May 2009 20:05:54 Jeff Garzik wrote:

That's what needs to happen. We provide no-op functions for e.g. PCI and x86 DMI, for platforms where this support does not exist.

Pretty much all architectures support some form of ATA. m68k, m32r, h8300 and microblaze all have IDE interface, which means that libata needs to work on that platform.

The only !ATA arch in the entire kernel is s390, AFAICT.

m68k only defines NO_DMA for Sun3 and Dragonball. Sun3 does not have ATA, Dragonball could probably just enable HAS_DMA.

Quoted 10 lines
---
 arch/h8300/Kconfig                   |    2 +-
 arch/h8300/include/asm/dma-mapping.h |    1 +
 arch/m32r/Kconfig                    |    2 +-
 arch/m32r/include/asm/dma-mapping.h  |    1 +
 include/asm-generic/dma-mapping.h    |  399 ++++++++++++++++++++++++++++++++++
 5 files changed, 403 insertions(+), 2 deletions(-)
 create mode 100644 arch/h8300/include/asm/dma-mapping.h
 create mode 100644 arch/m32r/include/asm/dma-mapping.h
 create mode 100644 include/asm-generic/dma-mapping.h

My main comment is a bit non-specific... I tend to think that all no-dma platforms should provide an API whose implementation always returns errors, e.g. an inlined version of dma-mapping-broken.h.

That sort of setup permits the compiler's dead code elimination to work on these no-dma platforms, while not crapping up the libata code with a bunch of ifdefs.

Jeff

#42 lore raw

Re: [PATCH] asm-generic: add a dma-mapping.h file

Quoted 34 lines · On Mon, 18 May 2009 18:54:49 -0400 Jeff Garzik <[email protected]> wrote:
Quoted 22 lines · Arnd Bergmann

h8300 and m32r currently do not provide a DMA mapping API and therefore cannot use the ATA drivers. This adds a generic version of dma-mapping.h for architectures that have none or very minimal actual support for DMA in hardware and makes the two architectures use it.

---

Quoted 8 lines · On Sunday 17 May 2009 20:05:54 Jeff Garzik wrote:

That's what needs to happen. We provide no-op functions for e.g. PCI and x86 DMI, for platforms where this support does not exist.

Pretty much all architectures support some form of ATA. m68k, m32r, h8300 and microblaze all have IDE interface, which means that libata needs to work on that platform.

The only !ATA arch in the entire kernel is s390, AFAICT.

m68k only defines NO_DMA for Sun3 and Dragonball. Sun3 does not have ATA, Dragonball could probably just enable HAS_DMA.

Quoted 10 lines
---
 arch/h8300/Kconfig                   |    2 +-
 arch/h8300/include/asm/dma-mapping.h |    1 +
 arch/m32r/Kconfig                    |    2 +-
 arch/m32r/include/asm/dma-mapping.h  |    1 +
 include/asm-generic/dma-mapping.h    |  399 ++++++++++++++++++++++++++++++++++
 5 files changed, 403 insertions(+), 2 deletions(-)
 create mode 100644 arch/h8300/include/asm/dma-mapping.h
 create mode 100644 arch/m32r/include/asm/dma-mapping.h
 create mode 100644 include/asm-generic/dma-mapping.h
Quoted 7 lines

My main comment is a bit non-specific... I tend to think that all
no-dma platforms should provide an API whose implementation always returns errors, e.g. an inlined version of dma-mapping-broken.h.

That sort of setup permits the compiler's dead code elimination to work on these no-dma platforms, while not crapping up the libata code with a bunch of ifdefs.

Just adding one ifdef to libata.h works? What libata needs is just wrapping dma_map_sg and dma_unmap_sg like the old ide stack does.

I'm not against the idea of an inlined version of dma-mapping-broken.h but having two ways to handle this issue is a bit confusing; so far what we done to handle this problem is using NO_DMA, like SCSI-ml does, not putting the dma code in non-architecture code and having something like scsi_lib_dma.c.

Is it theoretically correct that the dma mapping API lives in low level drivers instead of libata-core (like how SCSI-ml does)?

#43 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

In reply to Arnd Bergmann
Quoted 10 lines · On Fri, 15 May 2009 13:16:30 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 5 lines · Tejun Heo
Quoted 4 lines · FUJITA Tomonori

Can libata call dma_supported() per device to decide DMA or PIO mode? Then, we can solve this problem by add dummy DMA API (just calls BUG) on such architectures, without Kconfig magic or adding ifdef (like the old ide stack does), I think.

That would be the !CONFIG_PCI half of the old include/asm-generic/dma-mapping.h file that you just removed, right?

No.

The old include/asm-generic/dma-mapping.h is a workaround for lazy architecture maintainers who have not converted pci_* API to dma_* API.

author maintainer
#44 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

In reply to Brad Boyer
Quoted 4 lines · Brad Boyer

If I'm reading the m68k code correctly, SUN3 is the one that doesn't have DMA. It is implemented on any m68k with a standard Motorola MMU. It might be possible to get the DMA code working on a sun3, but I doubt they ever have IDE hardware.

Yes, that's right, I misread the Kconfig logic.

In m68nommu, there are also Dragonball and MC68360 that are supported but don't support the DMA API right now. Is that a real limitation, or could those potentially have ATA ports?

	Arnd <><
author maintainer
#45 lore raw

Re: [PATCH] ata: libata depends on HAS_DMA

In reply to Brad Boyer
Quoted 4 lines · Brad Boyer

If I'm reading the m68k code correctly, SUN3 is the one that doesn't have DMA. It is implemented on any m68k with a standard Motorola MMU. It might be possible to get the DMA code working on a sun3, but I doubt they ever have IDE hardware.

Yes, that's right, I misread the Kconfig logic.

In m68nommu, there are also Dragonball and MC68360 that are supported but don't support the DMA API right now. Is that a real limitation, or could those potentially have ATA ports?

	Arnd <><
author maintainer
#46 lore raw

PATCH 1/1 scsi: libsas depends on HAS_DMA

In reply to a message not in the archive

libsas uses the DMA mapping API, so it cannot be
built on architectures that don't support DMA.

---
 drivers/scsi/libsas/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/scsi/libsas/Kconfig +1 -1
index 18f33cd..59e00fa 100644
@@ -24,7 +24,7 @@
 
 config SCSI_SAS_LIBSAS
 	tristate "SAS Domain Transport Attributes"
-	depends on SCSI
+	depends on SCSI && HAS_DMA
 	select SCSI_SAS_ATTRS
 	help
 	  This provides transport specific helpers for SAS drivers which
Signature · 3 lines
1.6.0.4

-- 
maintainer
#47 lore raw

Re: [PATCH] scsi: libsas depends on HAS_DMA

Quoted 13 lines · Arnd Bergmann

libsas uses the DMA mapping API, so it cannot be
built on architectures that don't support DMA.

---
 drivers/scsi/libsas/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/scsi/libsas/Kconfig +0 -0
index 18f33cd..59e00fa 100644

drivers/scsi/libsas/Kconfig line 27

Quoted 5 lines
drivers/scsi/libsas/Kconfig +1 -1
@@ -24,7 +24,7 @@
 
 config SCSI_SAS_LIBSAS
 	tristate "SAS Domain Transport Attributes"
-	depends on SCSI
+	depends on SCSI && HAS_DMA

Our unfortunate Kconfig system can cause problems if you do this:
SCSI_SAS_LIBSAS is used as a select for drivers that need it, so either they'd need to select this themselves, or you need some other solution.

James

maintainer
#48 lore raw

Re: [PATCH] scsi: libsas depends on HAS_DMA

Quoted 15 lines · James Bottomley
Quoted 14 lines · Arnd Bergmann

libsas uses the DMA mapping API, so it cannot be
built on architectures that don't support DMA.

---
 drivers/scsi/libsas/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/scsi/libsas/Kconfig +0 -0
index 18f33cd..59e00fa 100644
@@ -24,7 +24,7 @@
 
Quoted 8 lines

drivers/scsi/libsas/Kconfig line 27

Quoted 4 lines
drivers/scsi/libsas/Kconfig +1 -1
 config SCSI_SAS_LIBSAS
 	tristate "SAS Domain Transport Attributes"
-	depends on SCSI
+	depends on SCSI && HAS_DMA

Our unfortunate Kconfig system can cause problems if you do this:
SCSI_SAS_LIBSAS is used as a select for drivers that need it, so either they'd need to select this themselves, or you need some other solution.

Actually, looking at this further, the problem is only in the ata compatibility layer because of the way libata does dma mapping on behalf of drivers, so the solution below (just disable SATA support if HAS_DMA isn't defined) will work without requiring select dependency modification.

James

---

drivers/scsi/libsas/Kconfig +1 -0
index 18f33cd..f462a0e 100644
@@ -33,6 +33,7 @@ config SCSI_SAS_LIBSAS
 config SCSI_SAS_ATA
 	bool "ATA support for libsas (requires libata)"
 	depends on SCSI_SAS_LIBSAS
+	depends on HAS_DMA
 	depends on ATA = y || ATA = SCSI_SAS_LIBSAS
 	help
 		Builds in ATA support into libsas.  Will necessitate
author maintainer
#49 lore raw

Re: [PATCH] scsi: libsas depends on HAS_DMA

Quoted 5 lines · On Monday 11 May 2009 22:59:44 James Bottomley wrote:

Actually, looking at this further, the problem is only in the ata compatibility layer because of the way libata does dma mapping on behalf of drivers, so the solution below (just disable SATA support if HAS_DMA isn't defined) will work without requiring select dependency modification.

Ah, in that case, the patch should not be needed at all, because SCSI_SAS_ATA already depends on ATA, and I also submitted a patch to make ATA depend on HAS_DMA.

Thanks for looking at it.

	Arnd <><
author maintainer
#50 lore raw

PATCH 1/1 arm: rename CLOCK_TICK_RATE to ARM_TICK_RATE

In reply to a message not in the archive

Most of the users of CLOCK_TICK_RATE in the kernel outside of ARM assume that it refers to the i8253 base frequency of 1.193182 Mhz, while in ARM it actually is the clock frequency of the timer.

By renaming it to ARM_TICK_RATE for all arm specific device drivers, we can hopefully reduce the amount of confusion slightly.

---
 arch/arm/mach-aaec2000/include/mach/timex.h   |    2 +-
 arch/arm/mach-at91/include/mach/timex.h       |   16 ++++++++--------
 arch/arm/mach-clps711x/include/mach/timex.h   |    2 +-
 arch/arm/mach-clps711x/time.c                 |    2 +-
 arch/arm/mach-davinci/include/mach/timex.h    |    2 +-
 arch/arm/mach-ebsa110/include/mach/timex.h    |    2 +-
 arch/arm/mach-ep93xx/core.c                   |    2 +-
 arch/arm/mach-ep93xx/include/mach/timex.h     |    2 +-
 arch/arm/mach-footbridge/include/mach/timex.h |    4 ++--
 arch/arm/mach-gemini/include/mach/timex.h     |    2 +-
 arch/arm/mach-h720x/include/mach/timex.h      |    2 +-
 arch/arm/mach-imx/include/mach/timex.h        |    2 +-
 arch/arm/mach-integrator/include/mach/timex.h |    2 +-
 arch/arm/mach-iop13xx/include/mach/timex.h    |    2 +-
 arch/arm/mach-iop32x/include/mach/timex.h     |    2 +-
 arch/arm/mach-iop33x/include/mach/timex.h     |    2 +-
 arch/arm/mach-ixp2000/include/mach/timex.h    |    2 +-
 arch/arm/mach-ixp23xx/core.c                  |    2 +-
 arch/arm/mach-ixp23xx/include/mach/timex.h    |    2 +-
 arch/arm/mach-ixp4xx/include/mach/timex.h     |    4 ++--
 arch/arm/mach-kirkwood/include/mach/timex.h   |    2 +-
 arch/arm/mach-ks8695/include/mach/timex.h     |    2 +-
 arch/arm/mach-ks8695/time.c                   |    6 +++---
 arch/arm/mach-l7200/include/mach/timex.h      |    2 +-
 arch/arm/mach-lh7a40x/include/mach/timex.h    |    4 ++--
 arch/arm/mach-loki/include/mach/timex.h       |    2 +-
 arch/arm/mach-mmp/include/mach/timex.h        |    2 +-
 arch/arm/mach-mmp/time.c                      |    6 +++---
 arch/arm/mach-msm/include/mach/timex.h        |    2 +-
 arch/arm/mach-mv78xx0/include/mach/timex.h    |    2 +-
 arch/arm/mach-netx/include/mach/timex.h       |    2 +-
 arch/arm/mach-netx/time.c                     |    4 ++--
 arch/arm/mach-ns9xxx/include/mach/timex.h     |    4 ++--
 arch/arm/mach-orion5x/include/mach/timex.h    |    2 +-
 arch/arm/mach-pnx4008/include/mach/timex.h    |    2 +-
 arch/arm/mach-pxa/include/mach/timex.h        |   10 +++++-----
 arch/arm/mach-realview/include/mach/timex.h   |    2 +-
 arch/arm/mach-rpc/include/mach/timex.h        |    2 +-
 arch/arm/mach-s3c24a0/include/mach/timex.h    |    2 +-
 arch/arm/mach-sa1100/include/mach/timex.h     |    2 +-
 arch/arm/mach-sa1100/time.c                   |    2 +-
 arch/arm/mach-shark/include/mach/timex.h      |    2 +-
 arch/arm/mach-versatile/include/mach/timex.h  |    2 +-
 arch/arm/mach-w90x900/include/mach/timex.h    |    4 ++--
 arch/arm/plat-mxc/include/mach/timex.h        |    6 +++---
 arch/arm/plat-omap/include/mach/timex.h       |    6 +++---
 arch/arm/plat-s3c/include/mach/timex.h        |    4 ++--
 drivers/rtc/rtc-pxa.c                         |    2 +-
 drivers/serial/serial_ks8695.c                |    2 +-
 drivers/watchdog/davinci_wdt.c                |    4 ++--
 drivers/watchdog/ks8695_wdt.c                 |    2 +-
 51 files changed, 78 insertions(+), 78 deletions(-)
arch/arm/mach- renamed from arch/arm/mach-aaec2000/include/mach/timex.h +0 -0

aaec2000/include/mach/timex.h
index 6c8edf4..80d82de 100644

arch/arm/mach-aaec2000/include/mach/timex.h +1 -1
@@ -13,6 +13,6 @@
 #ifndef __ASM_ARCH_TIMEX_H
 #define __ASM_ARCH_TIMEX_H
 
-#define CLOCK_TICK_RATE		508000
+#define ARM_TICK_RATE		508000
 
 #endif /* __ASM_ARCH_TIMEX_H */
arch/arm/mach- renamed from arch/arm/mach-at91/include/mach/timex.h +0 -0

at91/include/mach/timex.h
index d84c994..86215f1 100644

arch/arm/mach-at91/include/mach/timex.h +8 -8
@@ -25,7 +25,7 @@
 
 #if defined(CONFIG_ARCH_AT91RM9200)
 
-#define CLOCK_TICK_RATE		(AT91_SLOW_CLOCK)
+#define ARM_TICK_RATE		(AT91_SLOW_CLOCK)
 
 #elif defined(CONFIG_ARCH_AT91SAM9260)
 
@@ -35,12 +35,12 @@
 #define AT91SAM9_MASTER_CLOCK	99300000
 #endif
 
-#define CLOCK_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91SAM9261)
 
 #define AT91SAM9_MASTER_CLOCK	99300000
-#define CLOCK_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91SAM9263)
 
@@ -50,27 +50,27 @@
 #define AT91SAM9_MASTER_CLOCK	99959500
 #endif
 
-#define CLOCK_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91SAM9RL)
 
 #define AT91SAM9_MASTER_CLOCK	100000000
-#define CLOCK_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91SAM9G20)
 
 #define AT91SAM9_MASTER_CLOCK	132096000
-#define CLOCK_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91CAP9)
 
 #define AT91CAP9_MASTER_CLOCK	100000000
-#define CLOCK_TICK_RATE		(AT91CAP9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91CAP9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91X40)
 
 #define AT91X40_MASTER_CLOCK	40000000
-#define CLOCK_TICK_RATE		(AT91X40_MASTER_CLOCK)
+#define ARM_TICK_RATE		(AT91X40_MASTER_CLOCK)
 
 #endif
 
arch/arm/mach- renamed from arch/arm/mach-clps711x/include/mach/timex.h +0 -0

clps711x/include/mach/timex.h
index ac8823c..0965041 100644

arch/arm/mach-clps711x/include/mach/timex.h +1 -1
@@ -20,4 +20,4 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define CLOCK_TICK_RATE 512000
+#define ARM_TICK_RATE 512000
arch/arm/mach-clps711x/time.c +1 -1
index d581ef0..e5daed0 100644
@@ -34,7 +34,7 @@
 /*
  * gettimeoffset() returns time since last timer tick, in usecs.
  *
- * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.
+ * 'LATCH' is hwclock ticks (see ARM_TICK_RATE in timex.h) per jiffy.
  * 'tick' is usecs per jiffy.
  */
 static unsigned long clps711x_gettimeoffset(void)
arch/arm/mach- renamed from arch/arm/mach-davinci/include/mach/timex.h +0 -0

davinci/include/mach/timex.h
index 5282756..38314d3 100644

arch/arm/mach-davinci/include/mach/timex.h +1 -1
@@ -12,6 +12,6 @@
 #define __ASM_ARCH_TIMEX_H
 
 /* The source frequency for the timers is the 27MHz clock */
-#define CLOCK_TICK_RATE 27000000
+#define ARM_TICK_RATE 27000000
 
 #endif /* __ASM_ARCH_TIMEX_H__ */
arch/arm/mach- renamed from arch/arm/mach-ebsa110/include/mach/timex.h +0 -0

ebsa110/include/mach/timex.h
index 4fb43b2..e0e6623 100644

arch/arm/mach-ebsa110/include/mach/timex.h +1 -1
@@ -15,5 +15,5 @@
  * This is therefore not used to calculate the
  * divisor.
  */
-#define CLOCK_TICK_RATE		47894000
+#define ARM_TICK_RATE		47894000
 
arch/arm/mach-ep93xx/core.c +1 -1
index ae24486..22279b6 100644
@@ -98,7 +98,7 @@ void __init ep93xx_map_io(void)
  */
 static unsigned int last_jiffy_time;
 
-#define TIMER4_TICKS_PER_JIFFY		((CLOCK_TICK_RATE + (HZ/2)) / HZ)
+#define TIMER4_TICKS_PER_JIFFY		((ARM_TICK_RATE + (HZ/2)) / HZ)
 
 static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id)
 {
arch/arm/mach- renamed from arch/arm/mach-ep93xx/include/mach/timex.h +0 -0

ep93xx/include/mach/timex.h
index 6b3503b..d157204 100644

arch/arm/mach-ep93xx/include/mach/timex.h +1 -1
@@ -2,4 +2,4 @@
  * arch/arm/mach-ep93xx/include/mach/timex.h
  */
 
-#define CLOCK_TICK_RATE		983040
+#define ARM_TICK_RATE		983040
arch/arm/mach- renamed from arch/arm/mach-footbridge/include/mach/timex.h +0 -0

footbridge/include/mach/timex.h
index d0fea9d..20534ac 100644

arch/arm/mach-footbridge/include/mach/timex.h +2 -2
@@ -12,7 +12,7 @@
 
 /*
  * We assume a constant here; this satisfies the maths in linux/timex.h
- * and linux/time.h.  CLOCK_TICK_RATE is actually system dependent, but
+ * and linux/time.h.  ARM_TICK_RATE is actually system dependent, but
  * this must be a constant.
  */
-#define CLOCK_TICK_RATE		(50000000/16)
+#define ARM_TICK_RATE		(50000000/16)
arch/arm/mach- renamed from arch/arm/mach-gemini/include/mach/timex.h +0 -0

gemini/include/mach/timex.h
index dc5690b..b0eec31 100644

arch/arm/mach-gemini/include/mach/timex.h +1 -1
@@ -10,4 +10,4 @@
  */
 
 /* When AHB bus frequency is 150MHz */
-#define CLOCK_TICK_RATE	38000000
+#define ARM_TICK_RATE	38000000
arch/arm/mach- renamed from arch/arm/mach-h720x/include/mach/timex.h +0 -0

h720x/include/mach/timex.h
index 3f2f447..ebe075c 100644

arch/arm/mach-h720x/include/mach/timex.h +1 -1
@@ -10,6 +10,6 @@
 #ifndef __ASM_ARCH_TIMEX
 #define __ASM_ARCH_TIMEX
 
-#define CLOCK_TICK_RATE		3686400
+#define ARM_TICK_RATE		3686400
 
 #endif
arch/arm/mach- renamed from arch/arm/mach-imx/include/mach/timex.h +0 -0

imx/include/mach/timex.h
index e22ba78..1e1ef9c 100644

arch/arm/mach-imx/include/mach/timex.h +1 -1
@@ -21,6 +21,6 @@
 #ifndef __ASM_ARCH_TIMEX_H
 #define __ASM_ARCH_TIMEX_H
 
-#define CLOCK_TICK_RATE		(16000000)
+#define ARM_TICK_RATE		(16000000)
 
 #endif
arch/arm/mach- renamed from arch/arm/mach-integrator/include/mach/timex.h +0 -0

integrator/include/mach/timex.h
index 1dcb420..4c06d90 100644

arch/arm/mach-integrator/include/mach/timex.h +1 -1
@@ -23,4 +23,4 @@
 /*
  * ??
  */
-#define CLOCK_TICK_RATE		(50000000 / 16)
+#define ARM_TICK_RATE		(50000000 / 16)
arch/arm/mach- renamed from arch/arm/mach-iop13xx/include/mach/timex.h +0 -0

iop13xx/include/mach/timex.h
index 45fb274..4e8d4e6 100644

arch/arm/mach-iop13xx/include/mach/timex.h +1 -1
@@ -1 +1 @@
-#define CLOCK_TICK_RATE (100 * HZ)
+#define ARM_TICK_RATE (100 * HZ)
arch/arm/mach- renamed from arch/arm/mach-iop32x/include/mach/timex.h +0 -0

iop32x/include/mach/timex.h
index 7262ab8..5ead7ca 100644

arch/arm/mach-iop32x/include/mach/timex.h +1 -1
@@ -3,4 +3,4 @@
  *
  * IOP32x architecture timex specifications
  */
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
arch/arm/mach- renamed from arch/arm/mach-iop33x/include/mach/timex.h +0 -0

iop33x/include/mach/timex.h
index 54c5890..e925e77 100644

arch/arm/mach-iop33x/include/mach/timex.h +1 -1
@@ -3,4 +3,4 @@
  *
  * IOP3xx architecture timex specifications
  */
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
arch/arm/mach- renamed from arch/arm/mach-ixp2000/include/mach/timex.h +0 -0

ixp2000/include/mach/timex.h
index 835e659..479cbab 100644

arch/arm/mach-ixp2000/include/mach/timex.h +1 -1
@@ -8,6 +8,6 @@
 /*
  * Default clock is 50MHz APB, but platform code can override this
  */
-#define CLOCK_TICK_RATE	50000000
+#define ARM_TICK_RATE	50000000
 
 
arch/arm/mach-ixp23xx/core.c +1 -1
index aa4c442..aed022b 100644
@@ -329,7 +329,7 @@ void __init ixp23xx_init_irq(void)
 /*************************************************************************
  * Timer-tick functions for IXP23xx
  *************************************************************************/
-#define CLOCK_TICKS_PER_USEC	(CLOCK_TICK_RATE / USEC_PER_SEC)
+#define CLOCK_TICKS_PER_USEC	(ARM_TICK_RATE / USEC_PER_SEC)
 
 static unsigned long next_jiffy_time;
 
arch/arm/mach- renamed from arch/arm/mach-ixp23xx/include/mach/timex.h +0 -0

ixp23xx/include/mach/timex.h
index e341e9c..c84435b 100644

arch/arm/mach-ixp23xx/include/mach/timex.h +1 -1
@@ -4,4 +4,4 @@
  * XScale architecture timex specifications
  */
 
-#define CLOCK_TICK_RATE 75000000
+#define ARM_TICK_RATE 75000000
arch/arm/mach- renamed from arch/arm/mach-ixp4xx/include/mach/timex.h +0 -0

ixp4xx/include/mach/timex.h
index 89ce3ee..1f5c87b 100644

arch/arm/mach-ixp4xx/include/mach/timex.h +2 -2
@@ -7,9 +7,9 @@
 
 /*
  * We use IXP425 General purpose timer for our timer needs, it runs at 
- * 66.66... MHz. We do a convulted calculation of CLOCK_TICK_RATE b/c the
+ * 66.66... MHz. We do a convulted calculation of ARM_TICK_RATE b/c the
  * timer register ignores the bottom 2 bits of the LATCH value.
  */
 #define FREQ 66666666
-#define CLOCK_TICK_RATE (((FREQ / HZ & ~IXP4XX_OST_RELOAD_MASK) + 1) * HZ)
+#define ARM_TICK_RATE (((FREQ / HZ & ~IXP4XX_OST_RELOAD_MASK) + 1) * HZ)
 
arch/arm/mach- renamed from arch/arm/mach-kirkwood/include/mach/timex.h +0 -0

kirkwood/include/mach/timex.h
index c923cd1..67d1e54 100644

arch/arm/mach-kirkwood/include/mach/timex.h +1 -1
@@ -6,5 +6,5 @@
  * warranty of any kind, whether express or implied.
  */
 
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
 
arch/arm/mach- renamed from arch/arm/mach-ks8695/include/mach/timex.h +0 -0

ks8695/include/mach/timex.h
index 4682e35..83e971b 100644

arch/arm/mach-ks8695/include/mach/timex.h +1 -1
@@ -15,6 +15,6 @@
 #define __ASM_ARCH_TIMEX_H
 
 /* timers are derived from MCLK, which is 25MHz */
-#define CLOCK_TICK_RATE 25000000
+#define ARM_TICK_RATE 25000000
 
 #endif
arch/arm/mach-ks8695/time.c +3 -3
index 69c072c..c51fe85 100644
@@ -55,11 +55,11 @@ static unsigned long ks8695_gettimeoffset (void)
 	} while (elapsed > tick2);
 
 	/* Convert to number of ticks expired (not remaining) */
-	elapsed = (CLOCK_TICK_RATE / HZ) - elapsed;
+	elapsed = (ARM_TICK_RATE / HZ) - elapsed;
 
 	/* Is interrupt pending?  If so, then timer has been reloaded already. */
 	if (intpending)
-		elapsed += (CLOCK_TICK_RATE / HZ);
+		elapsed += (ARM_TICK_RATE / HZ);
 
 	/* Convert ticks to usecs */
 	return (unsigned long)(elapsed * (tick_nsec / 1000)) / LATCH;
@@ -82,7 +82,7 @@ static struct irqaction ks8695_timer_irq = {
 
 static void ks8695_timer_setup(void)
 {
-	unsigned long tmout = CLOCK_TICK_RATE / HZ;
+	unsigned long tmout = ARM_TICK_RATE / HZ;
 	unsigned long tmcon;
 
 	/* disable timer1 */
arch/arm/mach- renamed from arch/arm/mach-l7200/include/mach/timex.h +0 -0

l7200/include/mach/timex.h
index ffc96a6..b7ed766 100644

arch/arm/mach-l7200/include/mach/timex.h +1 -1
@@ -17,4 +17,4 @@
  *       rate. The value of HZ in 'param.h' must also
  *       be changed to match below.
  */
-#define CLOCK_TICK_RATE		128
+#define ARM_TICK_RATE		128
arch/arm/mach- renamed from arch/arm/mach-lh7a40x/include/mach/timex.h +0 -0

lh7a40x/include/mach/timex.h
index 08028ce..87d3657 100644

arch/arm/mach-lh7a40x/include/mach/timex.h +2 -2
@@ -10,8 +10,8 @@
 
 #include <mach/constants.h>
 
-#define CLOCK_TICK_RATE		(PLL_CLOCK/6/16)
+#define ARM_TICK_RATE		(PLL_CLOCK/6/16)
 
 /*
-#define CLOCK_TICK_RATE		3686400
+#define ARM_TICK_RATE		3686400
 */
arch/arm/mach- renamed from arch/arm/mach-loki/include/mach/timex.h +0 -0

loki/include/mach/timex.h
index 9df2109..640b53a 100644

arch/arm/mach-loki/include/mach/timex.h +1 -1
@@ -6,6 +6,6 @@
  * warranty of any kind, whether express or implied.
  */
 
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
 
 #define LOKI_TCLK		180000000
arch/arm/mach- renamed from arch/arm/mach-mmp/include/mach/timex.h +0 -0

mmp/include/mach/timex.h
index 6cebbd0..dcf8e87 100644

arch/arm/mach-mmp/include/mach/timex.h +1 -1
@@ -6,4 +6,4 @@
  * published by the Free Software Foundation.
  */
 
-#define CLOCK_TICK_RATE		3250000
+#define ARM_TICK_RATE		3250000
arch/arm/mach-mmp/time.c +3 -3
index b03a6ed..c85c1e1 100644
@@ -183,14 +183,14 @@ void __init timer_init(int irq)
 {
 	timer_config();
 
-	set_tcr2ns_scale(CLOCK_TICK_RATE);
+	set_tcr2ns_scale(ARM_TICK_RATE);
 
-	ckevt.mult = div_sc(CLOCK_TICK_RATE, NSEC_PER_SEC, ckevt.shift);
+	ckevt.mult = div_sc(ARM_TICK_RATE, NSEC_PER_SEC, ckevt.shift);
 	ckevt.max_delta_ns = clockevent_delta2ns(MAX_DELTA, &ckevt);
 	ckevt.min_delta_ns = clockevent_delta2ns(MIN_DELTA, &ckevt);
 	ckevt.cpumask = cpumask_of(0);
 
-	cksrc.mult = clocksource_hz2mult(CLOCK_TICK_RATE, cksrc.shift);
+	cksrc.mult = clocksource_hz2mult(ARM_TICK_RATE, cksrc.shift);
 
 	setup_irq(irq, &timer_irq);
 
arch/arm/mach- renamed from arch/arm/mach-msm/include/mach/timex.h +0 -0

msm/include/mach/timex.h
index a62e6b2..4bf65ab 100644

arch/arm/mach-msm/include/mach/timex.h +1 -1
@@ -16,6 +16,6 @@
 #ifndef __ASM_ARCH_MSM_TIMEX_H
 #define __ASM_ARCH_MSM_TIMEX_H
 
-#define CLOCK_TICK_RATE		1000000
+#define ARM_TICK_RATE		1000000
 
 #endif
arch/arm/mach- renamed from arch/arm/mach-mv78xx0/include/mach/timex.h +0 -0

mv78xx0/include/mach/timex.h
index 0e8c443..c074de8 100644

arch/arm/mach-mv78xx0/include/mach/timex.h +1 -1
@@ -6,4 +6,4 @@
  * warranty of any kind, whether express or implied.
  */
 
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
arch/arm/mach- renamed from arch/arm/mach-netx/include/mach/timex.h +0 -0

netx/include/mach/timex.h
index 1120dd0..ea1aa8f 100644

arch/arm/mach-netx/include/mach/timex.h +1 -1
@@ -17,4 +17,4 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define CLOCK_TICK_RATE 100000000
+#define ARM_TICK_RATE 100000000
arch/arm/mach-netx/time.c +2 -2
index 82801db..85b0969 100644
@@ -152,10 +152,10 @@ static void __init netx_timer_init(void)
 			NETX_GPIO_COUNTER_CTRL(TIMER_CLOCKSOURCE));
 
 	clocksource_netx.mult =
-		clocksource_hz2mult(CLOCK_TICK_RATE, clocksource_netx.shift);
+		clocksource_hz2mult(ARM_TICK_RATE, clocksource_netx.shift);
 	clocksource_register(&clocksource_netx);
 
-	netx_clockevent.mult = div_sc(CLOCK_TICK_RATE, NSEC_PER_SEC,
+	netx_clockevent.mult = div_sc(ARM_TICK_RATE, NSEC_PER_SEC,
 			netx_clockevent.shift);
 	netx_clockevent.max_delta_ns =
 		clockevent_delta2ns(0xfffffffe, &netx_clockevent);
arch/arm/mach- renamed from arch/arm/mach-ns9xxx/include/mach/timex.h +0 -0

ns9xxx/include/mach/timex.h
index 734a8d8..9cd49e8 100644

arch/arm/mach-ns9xxx/include/mach/timex.h +0 -1
@@ -12,9 +12,9 @@
 #define __ASM_ARCH_TIMEX_H
 
 /*
- * value for CLOCK_TICK_RATE stolen from arch/arm/mach-

s3c2410/include/mach/timex.h.
+ * value for ARM_TICK_RATE stolen from arch/arm/mach- s3c2410/include/mach/timex.h.
* See there for an explanation.
*/
-#define CLOCK_TICK_RATE 12000000
+#define ARM_TICK_RATE 12000000

#endif /* ifndef __ASM_ARCH_TIMEX_H */

arch/arm/mach- renamed from arch/arm/mach-orion5x/include/mach/timex.h +0 -0

orion5x/include/mach/timex.h
index 4c69820..957c434 100644

arch/arm/mach-orion5x/include/mach/timex.h +1 -1
@@ -8,4 +8,4 @@
  * warranty of any kind, whether express or implied.
  */
 
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
arch/arm/mach- renamed from arch/arm/mach-pnx4008/include/mach/timex.h +0 -0

pnx4008/include/mach/timex.h
index 5ff0196..b0faff3 100644

arch/arm/mach-pnx4008/include/mach/timex.h +1 -1
@@ -17,7 +17,7 @@
 #include <linux/io.h>
 #include <mach/hardware.h>
 
-#define CLOCK_TICK_RATE		1000000
+#define ARM_TICK_RATE		1000000
 
 #define TICKS2USECS(x)	(x)
 
arch/arm/mach- renamed from arch/arm/mach-pxa/include/mach/timex.h +0 -0

pxa/include/mach/timex.h
index af6760a..337fdac 100644

arch/arm/mach-pxa/include/mach/timex.h +5 -5
@@ -10,7 +10,7 @@
  * published by the Free Software Foundation.
  */
 
-/* Various drivers are still using the constant of CLOCK_TICK_RATE, for
+/* Various drivers are still using the constant of ARM_TICK_RATE, for
  * those drivers to at least work, the definition is provided here.
  *
  * NOTE: this is no longer accurate when multiple processors and boards
@@ -21,14 +21,14 @@
 
 #if defined(CONFIG_PXA25x)
 /* PXA250/210 timer base */
-#define CLOCK_TICK_RATE 3686400
+#define ARM_TICK_RATE 3686400
 #elif defined(CONFIG_PXA27x)
 /* PXA27x timer base */
 #ifdef CONFIG_MACH_MAINSTONE
-#define CLOCK_TICK_RATE 3249600
+#define ARM_TICK_RATE 3249600
 #else
-#define CLOCK_TICK_RATE 3250000
+#define ARM_TICK_RATE 3250000
 #endif
 #else
-#define CLOCK_TICK_RATE 3250000
+#define ARM_TICK_RATE 3250000
 #endif
arch/arm/mach- renamed from arch/arm/mach-realview/include/mach/timex.h +0 -0

realview/include/mach/timex.h
index 4eeb069..adcfee9 100644

arch/arm/mach-realview/include/mach/timex.h +1 -1
@@ -20,4 +20,4 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define CLOCK_TICK_RATE		(50000000 / 16)
+#define ARM_TICK_RATE		(50000000 / 16)
arch/arm/mach- renamed from arch/arm/mach-rpc/include/mach/timex.h +0 -0

rpc/include/mach/timex.h
index dd75e73..3518567 100644

arch/arm/mach-rpc/include/mach/timex.h +1 -1
@@ -13,5 +13,5 @@
 /*
  * On the RiscPC, the clock ticks at 2MHz.
  */
-#define CLOCK_TICK_RATE		2000000
+#define ARM_TICK_RATE		2000000
 
arch/arm/mach- renamed from arch/arm/mach-s3c24a0/include/mach/timex.h +0 -0

s3c24a0/include/mach/timex.h
index 9857342..cb00161 100644

arch/arm/mach-s3c24a0/include/mach/timex.h +1 -1
@@ -13,6 +13,6 @@
 #ifndef __ASM_ARCH_TIMEX_H
 #define __ASM_ARCH_TIMEX_H
 
-#define CLOCK_TICK_RATE 12000000
+#define ARM_TICK_RATE 12000000
 
 #endif /* __ASM_ARCH_TIMEX_H */
arch/arm/mach- renamed from arch/arm/mach-sa1100/include/mach/timex.h +0 -0

sa1100/include/mach/timex.h
index 7a5d017..d3a4fd0 100644

arch/arm/mach-sa1100/include/mach/timex.h +1 -1
@@ -9,4 +9,4 @@
 /*
  * SA1100 timer
  */
-#define CLOCK_TICK_RATE		3686400
+#define ARM_TICK_RATE		3686400
arch/arm/mach-sa1100/time.c +1 -1
index 711c029..a561628 100644
@@ -112,7 +112,7 @@ static void __init sa1100_timer_init(void)
 	ckevt_sa1100_osmr0.cpumask = cpumask_of(0);
 
 	cksrc_sa1100_oscr.mult =
-		clocksource_hz2mult(CLOCK_TICK_RATE, cksrc_sa1100_oscr.shift);
+		clocksource_hz2mult(ARM_TICK_RATE, cksrc_sa1100_oscr.shift);
 
 	setup_irq(IRQ_OST0, &sa1100_timer_irq);
 
arch/arm/mach- renamed from arch/arm/mach-shark/include/mach/timex.h +0 -0

shark/include/mach/timex.h
index bb6eeae..d32920d 100644

arch/arm/mach-shark/include/mach/timex.h +1 -1
@@ -4,4 +4,4 @@
  * by Alexander Schulz
  */
 
-#define CLOCK_TICK_RATE 1193180
+#define ARM_TICK_RATE 1193180
arch/arm/mach- renamed from arch/arm/mach-versatile/include/mach/timex.h +0 -0

versatile/include/mach/timex.h
index 426199b..07176df 100644

arch/arm/mach-versatile/include/mach/timex.h +1 -1
@@ -20,4 +20,4 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define CLOCK_TICK_RATE		(50000000 / 16)
+#define ARM_TICK_RATE		(50000000 / 16)
arch/arm/mach- renamed from arch/arm/mach-w90x900/include/mach/timex.h +0 -0

w90x900/include/mach/timex.h
index 164dce0..906fb72 100644

arch/arm/mach-w90x900/include/mach/timex.h +2 -2
@@ -18,8 +18,8 @@
 #ifndef __ASM_ARCH_TIMEX_H
 #define __ASM_ARCH_TIMEX_H
 
-/* CLOCK_TICK_RATE Now, I don't use it. */
+/* ARM_TICK_RATE Now, I don't use it. */
 
-#define CLOCK_TICK_RATE 15000000
+#define ARM_TICK_RATE 15000000
 
 #endif /* __ASM_ARCH_TIMEX_H */
arch/arm/plat- renamed from arch/arm/plat-mxc/include/mach/timex.h +0 -0

mxc/include/mach/timex.h
index 07b4a73..4f8919d 100644

arch/arm/plat-mxc/include/mach/timex.h +3 -3
@@ -21,11 +21,11 @@
 #define __ASM_ARCH_MXC_TIMEX_H__
 
 #if defined CONFIG_ARCH_MX1
-#define CLOCK_TICK_RATE		16000000
+#define ARM_TICK_RATE		16000000
 #elif defined CONFIG_ARCH_MX2
-#define CLOCK_TICK_RATE		13300000
+#define ARM_TICK_RATE		13300000
 #elif defined CONFIG_ARCH_MX3
-#define CLOCK_TICK_RATE		16625000
+#define ARM_TICK_RATE		16625000
 #endif
 
 #endif				/* __ASM_ARCH_MXC_TIMEX_H__ */
arch/arm/plat- renamed from arch/arm/plat-omap/include/mach/timex.h +0 -0

omap/include/mach/timex.h
index 6d35767..d572956 100644

arch/arm/plat-omap/include/mach/timex.h +3 -3
@@ -30,12 +30,12 @@
 
 /*
  * OMAP 32KHz timer updates time one jiffie at a time from a secondary timer,
- * and that's why the CLOCK_TICK_RATE is not 32768.
+ * and that's why the ARM_TICK_RATE is not 32768.
  */
 #ifdef CONFIG_OMAP_32K_TIMER
-#define CLOCK_TICK_RATE		(CONFIG_OMAP_32K_TIMER_HZ)
+#define ARM_TICK_RATE		(CONFIG_OMAP_32K_TIMER_HZ)
 #else
-#define CLOCK_TICK_RATE		(HZ * 100000UL)
+#define ARM_TICK_RATE		(HZ * 100000UL)
 #endif
 
 #endif /* __ASM_ARCH_OMAP_TIMEX_H */
arch/arm/plat- renamed from arch/arm/plat-s3c/include/mach/timex.h +0 -0

s3c/include/mach/timex.h
index 2a425ed..a32574a 100644

arch/arm/plat-s3c/include/mach/timex.h +2 -2
@@ -13,14 +13,14 @@
 #ifndef __ASM_ARCH_TIMEX_H
 #define __ASM_ARCH_TIMEX_H
 
-/* CLOCK_TICK_RATE needs to be evaluatable by the cpp, so making it
+/* ARM_TICK_RATE needs to be evaluatable by the cpp, so making it
  * a variable is useless. It seems as long as we make our timers an
  * exact multiple of HZ, any value that makes a 1->1 correspondence
  * for the time conversion functions to/from jiffies is acceptable.
 */
 
 
-#define CLOCK_TICK_RATE 12000000
+#define ARM_TICK_RATE 12000000
 
 
 #endif /* __ASM_ARCH_TIMEX_H */
drivers/rtc/rtc-pxa.c +1 -1
index bb8cc05..22133f4 100644
@@ -29,7 +29,7 @@
 
 #include <mach/hardware.h>
 
-#define TIMER_FREQ		CLOCK_TICK_RATE
+#define TIMER_FREQ		ARM_TICK_RATE
 #define RTC_DEF_DIVIDER		(32768 - 1)
 #define RTC_DEF_TRIM		0
 #define MAXFREQ_PERIODIC	1000
drivers/serial/serial_ks8695.c +0 -0
index 998e89d..5d66a2f 100644
@@ -549,7 +549,7 @@ static struct uart_port ks8695uart_ports[SERIAL_KS8695_NR] 

= {
.mapbase = KS8695_UART_VA,
.iotype = SERIAL_IO_MEM,
.irq = KS8695_IRQ_UART_TX,
- .uartclk = CLOCK_TICK_RATE * 16,
+ .uartclk = ARM_TICK_RATE * 16,
.fifosize = 16,
.ops = &ks8695uart_pops,
.flags = ASYNC_BOOT_AUTOCONF,

drivers/watchdog/davinci_wdt.c +2 -2
index c51d0b0..de7f784 100644
@@ -99,9 +99,9 @@ static void wdt_enable(void)
 	iowrite32(0, wdt_base + TIM12);
 	iowrite32(0, wdt_base + TIM34);
 	/* set timeout period */
-	timer_margin = (((u64)heartbeat * CLOCK_TICK_RATE) & 0xffffffff);
+	timer_margin = (((u64)heartbeat * ARM_TICK_RATE) & 0xffffffff);
 	iowrite32(timer_margin, wdt_base + PRD12);
-	timer_margin = (((u64)heartbeat * CLOCK_TICK_RATE) >> 32);
+	timer_margin = (((u64)heartbeat * ARM_TICK_RATE) >> 32);
 	iowrite32(timer_margin, wdt_base + PRD34);
 	/* enable run continuously */
 	iowrite32(ENAMODE12_PERIODIC, wdt_base + TCR);
drivers/watchdog/ks8695_wdt.c +1 -1
index ae38321..4594e93 100644
@@ -66,7 +66,7 @@ static inline void ks8695_wdt_stop(void)
 static inline void ks8695_wdt_start(void)
 {
 	unsigned long tmcon;
-	unsigned long tval = wdt_time * CLOCK_TICK_RATE;
+	unsigned long tval = wdt_time * ARM_TICK_RATE;
 
 	spin_lock(&ks8695_lock);
 	/* disable timer0 */
Signature · 3 lines
1.6.0.4

-- 
author maintainer
#51 lore raw

PATCH v2 1/1 arm: rename CLOCK_TICK_RATE to ARM_TICK_RATE

Most of the users of CLOCK_TICK_RATE in the kernel outside of ARM assume that it refers to the i8253 base frequency of 1.193182 Mhz, while in ARM it actually is the clock frequency of the timer.

By renaming it to ARM_TICK_RATE for all arm specific device drivers, we can hopefully reduce the amount of confusion slightly.

--

re-sent without the wordwrap...

 arch/arm/mach-aaec2000/include/mach/timex.h   |    2 +-
 arch/arm/mach-at91/include/mach/timex.h       |   16 ++++++++--------
 arch/arm/mach-clps711x/include/mach/timex.h   |    2 +-
 arch/arm/mach-clps711x/time.c                 |    2 +-
 arch/arm/mach-davinci/include/mach/timex.h    |    2 +-
 arch/arm/mach-ebsa110/include/mach/timex.h    |    2 +-
 arch/arm/mach-ep93xx/core.c                   |    2 +-
 arch/arm/mach-ep93xx/include/mach/timex.h     |    2 +-
 arch/arm/mach-footbridge/include/mach/timex.h |    4 ++--
 arch/arm/mach-gemini/include/mach/timex.h     |    2 +-
 arch/arm/mach-h720x/include/mach/timex.h      |    2 +-
 arch/arm/mach-imx/include/mach/timex.h        |    2 +-
 arch/arm/mach-integrator/include/mach/timex.h |    2 +-
 arch/arm/mach-iop13xx/include/mach/timex.h    |    2 +-
 arch/arm/mach-iop32x/include/mach/timex.h     |    2 +-
 arch/arm/mach-iop33x/include/mach/timex.h     |    2 +-
 arch/arm/mach-ixp2000/include/mach/timex.h    |    2 +-
 arch/arm/mach-ixp23xx/core.c                  |    2 +-
 arch/arm/mach-ixp23xx/include/mach/timex.h    |    2 +-
 arch/arm/mach-ixp4xx/include/mach/timex.h     |    4 ++--
 arch/arm/mach-kirkwood/include/mach/timex.h   |    2 +-
 arch/arm/mach-ks8695/include/mach/timex.h     |    2 +-
 arch/arm/mach-ks8695/time.c                   |    6 +++---
 arch/arm/mach-l7200/include/mach/timex.h      |    2 +-
 arch/arm/mach-lh7a40x/include/mach/timex.h    |    4 ++--
 arch/arm/mach-loki/include/mach/timex.h       |    2 +-
 arch/arm/mach-mmp/include/mach/timex.h        |    2 +-
 arch/arm/mach-mmp/time.c                      |    6 +++---
 arch/arm/mach-msm/include/mach/timex.h        |    2 +-
 arch/arm/mach-mv78xx0/include/mach/timex.h    |    2 +-
 arch/arm/mach-netx/include/mach/timex.h       |    2 +-
 arch/arm/mach-netx/time.c                     |    4 ++--
 arch/arm/mach-ns9xxx/include/mach/timex.h     |    4 ++--
 arch/arm/mach-orion5x/include/mach/timex.h    |    2 +-
 arch/arm/mach-pnx4008/include/mach/timex.h    |    2 +-
 arch/arm/mach-pxa/include/mach/timex.h        |   10 +++++-----
 arch/arm/mach-realview/include/mach/timex.h   |    2 +-
 arch/arm/mach-rpc/include/mach/timex.h        |    2 +-
 arch/arm/mach-s3c24a0/include/mach/timex.h    |    2 +-
 arch/arm/mach-sa1100/include/mach/timex.h     |    2 +-
 arch/arm/mach-sa1100/time.c                   |    2 +-
 arch/arm/mach-shark/include/mach/timex.h      |    2 +-
 arch/arm/mach-versatile/include/mach/timex.h  |    2 +-
 arch/arm/mach-w90x900/include/mach/timex.h    |    4 ++--
 arch/arm/plat-mxc/include/mach/timex.h        |    6 +++---
 arch/arm/plat-omap/include/mach/timex.h       |    6 +++---
 arch/arm/plat-s3c/include/mach/timex.h        |    4 ++--
 drivers/rtc/rtc-pxa.c                         |    2 +-
 drivers/serial/serial_ks8695.c                |    2 +-
 drivers/watchdog/davinci_wdt.c                |    4 ++--
 drivers/watchdog/ks8695_wdt.c                 |    2 +-
 51 files changed, 78 insertions(+), 78 deletions(-)
arch/arm/mach-aaec2000/include/mach/timex.h +1 -1
index 6c8edf4..80d82de 100644
@@ -13,6 +13,6 @@
 #ifndef __ASM_ARCH_TIMEX_H
 #define __ASM_ARCH_TIMEX_H
 
-#define CLOCK_TICK_RATE		508000
+#define ARM_TICK_RATE		508000
 
 #endif /* __ASM_ARCH_TIMEX_H */
arch/arm/mach-at91/include/mach/timex.h +8 -8
index d84c994..86215f1 100644
@@ -25,7 +25,7 @@
 
 #if defined(CONFIG_ARCH_AT91RM9200)
 
-#define CLOCK_TICK_RATE		(AT91_SLOW_CLOCK)
+#define ARM_TICK_RATE		(AT91_SLOW_CLOCK)
 
 #elif defined(CONFIG_ARCH_AT91SAM9260)
 
@@ -35,12 +35,12 @@
 #define AT91SAM9_MASTER_CLOCK	99300000
 #endif
 
-#define CLOCK_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91SAM9261)
 
 #define AT91SAM9_MASTER_CLOCK	99300000
-#define CLOCK_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91SAM9263)
 
@@ -50,27 +50,27 @@
 #define AT91SAM9_MASTER_CLOCK	99959500
 #endif
 
-#define CLOCK_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91SAM9RL)
 
 #define AT91SAM9_MASTER_CLOCK	100000000
-#define CLOCK_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91SAM9G20)
 
 #define AT91SAM9_MASTER_CLOCK	132096000
-#define CLOCK_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91SAM9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91CAP9)
 
 #define AT91CAP9_MASTER_CLOCK	100000000
-#define CLOCK_TICK_RATE		(AT91CAP9_MASTER_CLOCK/16)
+#define ARM_TICK_RATE		(AT91CAP9_MASTER_CLOCK/16)
 
 #elif defined(CONFIG_ARCH_AT91X40)
 
 #define AT91X40_MASTER_CLOCK	40000000
-#define CLOCK_TICK_RATE		(AT91X40_MASTER_CLOCK)
+#define ARM_TICK_RATE		(AT91X40_MASTER_CLOCK)
 
 #endif
 
arch/arm/mach-clps711x/include/mach/timex.h +1 -1
index ac8823c..0965041 100644
@@ -20,4 +20,4 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define CLOCK_TICK_RATE 512000
+#define ARM_TICK_RATE 512000
arch/arm/mach-clps711x/time.c +1 -1
index d581ef0..e5daed0 100644
@@ -34,7 +34,7 @@
 /*
  * gettimeoffset() returns time since last timer tick, in usecs.
  *
- * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.
+ * 'LATCH' is hwclock ticks (see ARM_TICK_RATE in timex.h) per jiffy.
  * 'tick' is usecs per jiffy.
  */
 static unsigned long clps711x_gettimeoffset(void)
arch/arm/mach-davinci/include/mach/timex.h +1 -1
index 5282756..38314d3 100644
@@ -12,6 +12,6 @@
 #define __ASM_ARCH_TIMEX_H
 
 /* The source frequency for the timers is the 27MHz clock */
-#define CLOCK_TICK_RATE 27000000
+#define ARM_TICK_RATE 27000000
 
 #endif /* __ASM_ARCH_TIMEX_H__ */
arch/arm/mach-ebsa110/include/mach/timex.h +1 -1
index 4fb43b2..e0e6623 100644
@@ -15,5 +15,5 @@
  * This is therefore not used to calculate the
  * divisor.
  */
-#define CLOCK_TICK_RATE		47894000
+#define ARM_TICK_RATE		47894000
 
arch/arm/mach-ep93xx/core.c +1 -1
index ae24486..22279b6 100644
@@ -98,7 +98,7 @@ void __init ep93xx_map_io(void)
  */
 static unsigned int last_jiffy_time;
 
-#define TIMER4_TICKS_PER_JIFFY		((CLOCK_TICK_RATE + (HZ/2)) / HZ)
+#define TIMER4_TICKS_PER_JIFFY		((ARM_TICK_RATE + (HZ/2)) / HZ)
 
 static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id)
 {
arch/arm/mach-ep93xx/include/mach/timex.h +1 -1
index 6b3503b..d157204 100644
@@ -2,4 +2,4 @@
  * arch/arm/mach-ep93xx/include/mach/timex.h
  */
 
-#define CLOCK_TICK_RATE		983040
+#define ARM_TICK_RATE		983040
arch/arm/mach-footbridge/include/mach/timex.h +2 -2
index d0fea9d..20534ac 100644
@@ -12,7 +12,7 @@
 
 /*
  * We assume a constant here; this satisfies the maths in linux/timex.h
- * and linux/time.h.  CLOCK_TICK_RATE is actually system dependent, but
+ * and linux/time.h.  ARM_TICK_RATE is actually system dependent, but
  * this must be a constant.
  */
-#define CLOCK_TICK_RATE		(50000000/16)
+#define ARM_TICK_RATE		(50000000/16)
arch/arm/mach-gemini/include/mach/timex.h +1 -1
index dc5690b..b0eec31 100644
@@ -10,4 +10,4 @@
  */
 
 /* When AHB bus frequency is 150MHz */
-#define CLOCK_TICK_RATE	38000000
+#define ARM_TICK_RATE	38000000
arch/arm/mach-h720x/include/mach/timex.h +1 -1
index 3f2f447..ebe075c 100644
@@ -10,6 +10,6 @@
 #ifndef __ASM_ARCH_TIMEX
 #define __ASM_ARCH_TIMEX
 
-#define CLOCK_TICK_RATE		3686400
+#define ARM_TICK_RATE		3686400
 
 #endif
arch/arm/mach-imx/include/mach/timex.h +1 -1
index e22ba78..1e1ef9c 100644
@@ -21,6 +21,6 @@
 #ifndef __ASM_ARCH_TIMEX_H
 #define __ASM_ARCH_TIMEX_H
 
-#define CLOCK_TICK_RATE		(16000000)
+#define ARM_TICK_RATE		(16000000)
 
 #endif
arch/arm/mach-integrator/include/mach/timex.h +1 -1
index 1dcb420..4c06d90 100644
@@ -23,4 +23,4 @@
 /*
  * ??
  */
-#define CLOCK_TICK_RATE		(50000000 / 16)
+#define ARM_TICK_RATE		(50000000 / 16)
arch/arm/mach-iop13xx/include/mach/timex.h +1 -1
index 45fb274..4e8d4e6 100644
@@ -1 +1 @@
-#define CLOCK_TICK_RATE (100 * HZ)
+#define ARM_TICK_RATE (100 * HZ)
arch/arm/mach-iop32x/include/mach/timex.h +1 -1
index 7262ab8..5ead7ca 100644
@@ -3,4 +3,4 @@
  *
  * IOP32x architecture timex specifications
  */
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
arch/arm/mach-iop33x/include/mach/timex.h +1 -1
index 54c5890..e925e77 100644
@@ -3,4 +3,4 @@
  *
  * IOP3xx architecture timex specifications
  */
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
arch/arm/mach-ixp2000/include/mach/timex.h +1 -1
index 835e659..479cbab 100644
@@ -8,6 +8,6 @@
 /*
  * Default clock is 50MHz APB, but platform code can override this
  */
-#define CLOCK_TICK_RATE	50000000
+#define ARM_TICK_RATE	50000000
 
 
arch/arm/mach-ixp23xx/core.c +1 -1
index aa4c442..aed022b 100644
@@ -329,7 +329,7 @@ void __init ixp23xx_init_irq(void)
 /*************************************************************************
  * Timer-tick functions for IXP23xx
  *************************************************************************/
-#define CLOCK_TICKS_PER_USEC	(CLOCK_TICK_RATE / USEC_PER_SEC)
+#define CLOCK_TICKS_PER_USEC	(ARM_TICK_RATE / USEC_PER_SEC)
 
 static unsigned long next_jiffy_time;
 
arch/arm/mach-ixp23xx/include/mach/timex.h +1 -1
index e341e9c..c84435b 100644
@@ -4,4 +4,4 @@
  * XScale architecture timex specifications
  */
 
-#define CLOCK_TICK_RATE 75000000
+#define ARM_TICK_RATE 75000000
arch/arm/mach-ixp4xx/include/mach/timex.h +2 -2
index 89ce3ee..1f5c87b 100644
@@ -7,9 +7,9 @@
 
 /*
  * We use IXP425 General purpose timer for our timer needs, it runs at 
- * 66.66... MHz. We do a convulted calculation of CLOCK_TICK_RATE b/c the
+ * 66.66... MHz. We do a convulted calculation of ARM_TICK_RATE b/c the
  * timer register ignores the bottom 2 bits of the LATCH value.
  */
 #define FREQ 66666666
-#define CLOCK_TICK_RATE (((FREQ / HZ & ~IXP4XX_OST_RELOAD_MASK) + 1) * HZ)
+#define ARM_TICK_RATE (((FREQ / HZ & ~IXP4XX_OST_RELOAD_MASK) + 1) * HZ)
 
arch/arm/mach-kirkwood/include/mach/timex.h +1 -1
index c923cd1..67d1e54 100644
@@ -6,5 +6,5 @@
  * warranty of any kind, whether express or implied.
  */
 
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
 
arch/arm/mach-ks8695/include/mach/timex.h +1 -1
index 4682e35..83e971b 100644
@@ -15,6 +15,6 @@
 #define __ASM_ARCH_TIMEX_H
 
 /* timers are derived from MCLK, which is 25MHz */
-#define CLOCK_TICK_RATE 25000000
+#define ARM_TICK_RATE 25000000
 
 #endif
arch/arm/mach-ks8695/time.c +3 -3
index 69c072c..c51fe85 100644
@@ -55,11 +55,11 @@ static unsigned long ks8695_gettimeoffset (void)
 	} while (elapsed > tick2);
 
 	/* Convert to number of ticks expired (not remaining) */
-	elapsed = (CLOCK_TICK_RATE / HZ) - elapsed;
+	elapsed = (ARM_TICK_RATE / HZ) - elapsed;
 
 	/* Is interrupt pending?  If so, then timer has been reloaded already. */
 	if (intpending)
-		elapsed += (CLOCK_TICK_RATE / HZ);
+		elapsed += (ARM_TICK_RATE / HZ);
 
 	/* Convert ticks to usecs */
 	return (unsigned long)(elapsed * (tick_nsec / 1000)) / LATCH;
@@ -82,7 +82,7 @@ static struct irqaction ks8695_timer_irq = {
 
 static void ks8695_timer_setup(void)
 {
-	unsigned long tmout = CLOCK_TICK_RATE / HZ;
+	unsigned long tmout = ARM_TICK_RATE / HZ;
 	unsigned long tmcon;
 
 	/* disable timer1 */
arch/arm/mach-l7200/include/mach/timex.h +1 -1
index ffc96a6..b7ed766 100644
@@ -17,4 +17,4 @@
  *       rate. The value of HZ in 'param.h' must also
  *       be changed to match below.
  */
-#define CLOCK_TICK_RATE		128
+#define ARM_TICK_RATE		128
arch/arm/mach-lh7a40x/include/mach/timex.h +2 -2
index 08028ce..87d3657 100644
@@ -10,8 +10,8 @@
 
 #include <mach/constants.h>
 
-#define CLOCK_TICK_RATE		(PLL_CLOCK/6/16)
+#define ARM_TICK_RATE		(PLL_CLOCK/6/16)
 
 /*
-#define CLOCK_TICK_RATE		3686400
+#define ARM_TICK_RATE		3686400
 */
arch/arm/mach-loki/include/mach/timex.h +1 -1
index 9df2109..640b53a 100644
@@ -6,6 +6,6 @@
  * warranty of any kind, whether express or implied.
  */
 
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
 
 #define LOKI_TCLK		180000000
arch/arm/mach-mmp/include/mach/timex.h +1 -1
index 6cebbd0..dcf8e87 100644
@@ -6,4 +6,4 @@
  * published by the Free Software Foundation.
  */
 
-#define CLOCK_TICK_RATE		3250000
+#define ARM_TICK_RATE		3250000
arch/arm/mach-mmp/time.c +3 -3
index b03a6ed..c85c1e1 100644
@@ -183,14 +183,14 @@ void __init timer_init(int irq)
 {
 	timer_config();
 
-	set_tcr2ns_scale(CLOCK_TICK_RATE);
+	set_tcr2ns_scale(ARM_TICK_RATE);
 
-	ckevt.mult = div_sc(CLOCK_TICK_RATE, NSEC_PER_SEC, ckevt.shift);
+	ckevt.mult = div_sc(ARM_TICK_RATE, NSEC_PER_SEC, ckevt.shift);
 	ckevt.max_delta_ns = clockevent_delta2ns(MAX_DELTA, &ckevt);
 	ckevt.min_delta_ns = clockevent_delta2ns(MIN_DELTA, &ckevt);
 	ckevt.cpumask = cpumask_of(0);
 
-	cksrc.mult = clocksource_hz2mult(CLOCK_TICK_RATE, cksrc.shift);
+	cksrc.mult = clocksource_hz2mult(ARM_TICK_RATE, cksrc.shift);
 
 	setup_irq(irq, &timer_irq);
 
arch/arm/mach-msm/include/mach/timex.h +1 -1
index a62e6b2..4bf65ab 100644
@@ -16,6 +16,6 @@
 #ifndef __ASM_ARCH_MSM_TIMEX_H
 #define __ASM_ARCH_MSM_TIMEX_H
 
-#define CLOCK_TICK_RATE		1000000
+#define ARM_TICK_RATE		1000000
 
 #endif
arch/arm/mach-mv78xx0/include/mach/timex.h +1 -1
index 0e8c443..c074de8 100644
@@ -6,4 +6,4 @@
  * warranty of any kind, whether express or implied.
  */
 
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
arch/arm/mach-netx/include/mach/timex.h +1 -1
index 1120dd0..ea1aa8f 100644
@@ -17,4 +17,4 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define CLOCK_TICK_RATE 100000000
+#define ARM_TICK_RATE 100000000
arch/arm/mach-netx/time.c +2 -2
index 82801db..85b0969 100644
@@ -152,10 +152,10 @@ static void __init netx_timer_init(void)
 			NETX_GPIO_COUNTER_CTRL(TIMER_CLOCKSOURCE));
 
 	clocksource_netx.mult =
-		clocksource_hz2mult(CLOCK_TICK_RATE, clocksource_netx.shift);
+		clocksource_hz2mult(ARM_TICK_RATE, clocksource_netx.shift);
 	clocksource_register(&clocksource_netx);
 
-	netx_clockevent.mult = div_sc(CLOCK_TICK_RATE, NSEC_PER_SEC,
+	netx_clockevent.mult = div_sc(ARM_TICK_RATE, NSEC_PER_SEC,
 			netx_clockevent.shift);
 	netx_clockevent.max_delta_ns =
 		clockevent_delta2ns(0xfffffffe, &netx_clockevent);
arch/arm/mach-ns9xxx/include/mach/timex.h +2 -2
index 734a8d8..9cd49e8 100644
@@ -12,9 +12,9 @@
 #define __ASM_ARCH_TIMEX_H
 
 /*
- * value for CLOCK_TICK_RATE stolen from arch/arm/mach-s3c2410/include/mach/timex.h.
+ * value for ARM_TICK_RATE stolen from arch/arm/mach-s3c2410/include/mach/timex.h.
  * See there for an explanation.
  */
-#define CLOCK_TICK_RATE         12000000
+#define ARM_TICK_RATE         12000000
 
 #endif /* ifndef __ASM_ARCH_TIMEX_H */
arch/arm/mach-orion5x/include/mach/timex.h +1 -1
index 4c69820..957c434 100644
@@ -8,4 +8,4 @@
  * warranty of any kind, whether express or implied.
  */
 
-#define CLOCK_TICK_RATE		(100 * HZ)
+#define ARM_TICK_RATE		(100 * HZ)
arch/arm/mach-pnx4008/include/mach/timex.h +1 -1
index 5ff0196..b0faff3 100644
@@ -17,7 +17,7 @@
 #include <linux/io.h>
 #include <mach/hardware.h>
 
-#define CLOCK_TICK_RATE		1000000
+#define ARM_TICK_RATE		1000000
 
 #define TICKS2USECS(x)	(x)
 
arch/arm/mach-pxa/include/mach/timex.h +5 -5
index af6760a..337fdac 100644
@@ -10,7 +10,7 @@
  * published by the Free Software Foundation.
  */
 
-/* Various drivers are still using the constant of CLOCK_TICK_RATE, for
+/* Various drivers are still using the constant of ARM_TICK_RATE, for
  * those drivers to at least work, the definition is provided here.
  *
  * NOTE: this is no longer accurate when multiple processors and boards
@@ -21,14 +21,14 @@
 
 #if defined(CONFIG_PXA25x)
 /* PXA250/210 timer base */
-#define CLOCK_TICK_RATE 3686400
+#define ARM_TICK_RATE 3686400
 #elif defined(CONFIG_PXA27x)
 /* PXA27x timer base */
 #ifdef CONFIG_MACH_MAINSTONE
-#define CLOCK_TICK_RATE 3249600
+#define ARM_TICK_RATE 3249600
 #else
-#define CLOCK_TICK_RATE 3250000
+#define ARM_TICK_RATE 3250000
 #endif
 #else
-#define CLOCK_TICK_RATE 3250000
+#define ARM_TICK_RATE 3250000
 #endif
arch/arm/mach-realview/include/mach/timex.h +1 -1
index 4eeb069..adcfee9 100644
@@ -20,4 +20,4 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define CLOCK_TICK_RATE		(50000000 / 16)
+#define ARM_TICK_RATE		(50000000 / 16)
arch/arm/mach-rpc/include/mach/timex.h +1 -1
index dd75e73..3518567 100644
@@ -13,5 +13,5 @@
 /*
  * On the RiscPC, the clock ticks at 2MHz.
  */
-#define CLOCK_TICK_RATE		2000000
+#define ARM_TICK_RATE		2000000
 
arch/arm/mach-s3c24a0/include/mach/timex.h +1 -1
index 9857342..cb00161 100644
@@ -13,6 +13,6 @@
 #ifndef __ASM_ARCH_TIMEX_H
 #define __ASM_ARCH_TIMEX_H
 
-#define CLOCK_TICK_RATE 12000000
+#define ARM_TICK_RATE 12000000
 
 #endif /* __ASM_ARCH_TIMEX_H */
arch/arm/mach-sa1100/include/mach/timex.h +1 -1
index 7a5d017..d3a4fd0 100644
@@ -9,4 +9,4 @@
 /*
  * SA1100 timer
  */
-#define CLOCK_TICK_RATE		3686400
+#define ARM_TICK_RATE		3686400
arch/arm/mach-sa1100/time.c +1 -1
index 711c029..a561628 100644
@@ -112,7 +112,7 @@ static void __init sa1100_timer_init(void)
 	ckevt_sa1100_osmr0.cpumask = cpumask_of(0);
 
 	cksrc_sa1100_oscr.mult =
-		clocksource_hz2mult(CLOCK_TICK_RATE, cksrc_sa1100_oscr.shift);
+		clocksource_hz2mult(ARM_TICK_RATE, cksrc_sa1100_oscr.shift);
 
 	setup_irq(IRQ_OST0, &sa1100_timer_irq);
 
arch/arm/mach-shark/include/mach/timex.h +1 -1
index bb6eeae..d32920d 100644
@@ -4,4 +4,4 @@
  * by Alexander Schulz
  */
 
-#define CLOCK_TICK_RATE 1193180
+#define ARM_TICK_RATE 1193180
arch/arm/mach-versatile/include/mach/timex.h +1 -1
index 426199b..07176df 100644
@@ -20,4 +20,4 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#define CLOCK_TICK_RATE		(50000000 / 16)
+#define ARM_TICK_RATE		(50000000 / 16)
arch/arm/mach-w90x900/include/mach/timex.h +2 -2
index 164dce0..906fb72 100644
@@ -18,8 +18,8 @@
 #ifndef __ASM_ARCH_TIMEX_H
 #define __ASM_ARCH_TIMEX_H
 
-/* CLOCK_TICK_RATE Now, I don't use it. */
+/* ARM_TICK_RATE Now, I don't use it. */
 
-#define CLOCK_TICK_RATE 15000000
+#define ARM_TICK_RATE 15000000
 
 #endif /* __ASM_ARCH_TIMEX_H */
arch/arm/plat-mxc/include/mach/timex.h +3 -3
index 07b4a73..4f8919d 100644
@@ -21,11 +21,11 @@
 #define __ASM_ARCH_MXC_TIMEX_H__
 
 #if defined CONFIG_ARCH_MX1
-#define CLOCK_TICK_RATE		16000000
+#define ARM_TICK_RATE		16000000
 #elif defined CONFIG_ARCH_MX2
-#define CLOCK_TICK_RATE		13300000
+#define ARM_TICK_RATE		13300000
 #elif defined CONFIG_ARCH_MX3
-#define CLOCK_TICK_RATE		16625000
+#define ARM_TICK_RATE		16625000
 #endif
 
 #endif				/* __ASM_ARCH_MXC_TIMEX_H__ */
arch/arm/plat-omap/include/mach/timex.h +3 -3
index 6d35767..d572956 100644
@@ -30,12 +30,12 @@
 
 /*
  * OMAP 32KHz timer updates time one jiffie at a time from a secondary timer,
- * and that's why the CLOCK_TICK_RATE is not 32768.
+ * and that's why the ARM_TICK_RATE is not 32768.
  */
 #ifdef CONFIG_OMAP_32K_TIMER
-#define CLOCK_TICK_RATE		(CONFIG_OMAP_32K_TIMER_HZ)
+#define ARM_TICK_RATE		(CONFIG_OMAP_32K_TIMER_HZ)
 #else
-#define CLOCK_TICK_RATE		(HZ * 100000UL)
+#define ARM_TICK_RATE		(HZ * 100000UL)
 #endif
 
 #endif /* __ASM_ARCH_OMAP_TIMEX_H */
arch/arm/plat-s3c/include/mach/timex.h +2 -2
index 2a425ed..a32574a 100644
@@ -13,14 +13,14 @@
 #ifndef __ASM_ARCH_TIMEX_H
 #define __ASM_ARCH_TIMEX_H
 
-/* CLOCK_TICK_RATE needs to be evaluatable by the cpp, so making it
+/* ARM_TICK_RATE needs to be evaluatable by the cpp, so making it
  * a variable is useless. It seems as long as we make our timers an
  * exact multiple of HZ, any value that makes a 1->1 correspondence
  * for the time conversion functions to/from jiffies is acceptable.
 */
 
 
-#define CLOCK_TICK_RATE 12000000
+#define ARM_TICK_RATE 12000000
 
 
 #endif /* __ASM_ARCH_TIMEX_H */
drivers/rtc/rtc-pxa.c +1 -1
index bb8cc05..22133f4 100644
@@ -29,7 +29,7 @@
 
 #include <mach/hardware.h>
 
-#define TIMER_FREQ		CLOCK_TICK_RATE
+#define TIMER_FREQ		ARM_TICK_RATE
 #define RTC_DEF_DIVIDER		(32768 - 1)
 #define RTC_DEF_TRIM		0
 #define MAXFREQ_PERIODIC	1000
drivers/serial/serial_ks8695.c +1 -1
index 998e89d..5d66a2f 100644
@@ -549,7 +549,7 @@ static struct uart_port ks8695uart_ports[SERIAL_KS8695_NR] = {
 		.mapbase	= KS8695_UART_VA,
 		.iotype		= SERIAL_IO_MEM,
 		.irq		= KS8695_IRQ_UART_TX,
-		.uartclk	= CLOCK_TICK_RATE * 16,
+		.uartclk	= ARM_TICK_RATE * 16,
 		.fifosize	= 16,
 		.ops		= &ks8695uart_pops,
 		.flags		= ASYNC_BOOT_AUTOCONF,
drivers/watchdog/davinci_wdt.c +2 -2
index c51d0b0..de7f784 100644
@@ -99,9 +99,9 @@ static void wdt_enable(void)
 	iowrite32(0, wdt_base + TIM12);
 	iowrite32(0, wdt_base + TIM34);
 	/* set timeout period */
-	timer_margin = (((u64)heartbeat * CLOCK_TICK_RATE) & 0xffffffff);
+	timer_margin = (((u64)heartbeat * ARM_TICK_RATE) & 0xffffffff);
 	iowrite32(timer_margin, wdt_base + PRD12);
-	timer_margin = (((u64)heartbeat * CLOCK_TICK_RATE) >> 32);
+	timer_margin = (((u64)heartbeat * ARM_TICK_RATE) >> 32);
 	iowrite32(timer_margin, wdt_base + PRD34);
 	/* enable run continuously */
 	iowrite32(ENAMODE12_PERIODIC, wdt_base + TCR);
drivers/watchdog/ks8695_wdt.c +1 -1
index ae38321..4594e93 100644
@@ -66,7 +66,7 @@ static inline void ks8695_wdt_stop(void)
 static inline void ks8695_wdt_start(void)
 {
 	unsigned long tmcon;
-	unsigned long tval = wdt_time * CLOCK_TICK_RATE;
+	unsigned long tval = wdt_time * ARM_TICK_RATE;
 
 	spin_lock(&ks8695_lock);
 	/* disable timer0 */
Signature · 1 line
1.6.0.4
author maintainer
#52 lore raw

Re: [PATCH] arm: rename CLOCK_TICK_RATE to ARM_TICK_RATE

In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

Most of the users of CLOCK_TICK_RATE in the kernel outside of ARM assume that it refers to the i8253 base frequency of 1.193182 Mhz, while in ARM it actually is the clock frequency of the timer.

By renaming it to ARM_TICK_RATE for all arm specific device drivers, we can hopefully reduce the amount of confusion slightly.

My patch was missing one important change to make this a nonintrusive change:

arch/arm/include/asm/timex.h +2 -0
@@ -14,6 +14,8 @@
 
 #include <mach/timex.h>
 
+#define CLOCK_TICK_RATE ARM_TICK_RATE
+
 typedef unsigned long cycles_t;
 
 static inline cycles_t get_cycles (void)
	Arnd <><
author maintainer
#53 lore raw

PATCH 1/1 x86: use PIT_TICK_RATE consistently

In reply to a message not in the archive

On x86, the CLOCK_TICK_RATE is defined in terms of PIT_TICK_RATE, from the original i8253 PIT frequency. Change all users to refer to PIT_TICK_RATE directly, in order to reduce the number of overloaded meanings for CLOCK_TICK_RATE.

---
 arch/x86/include/asm/mach_timer.h |    2 +-
 arch/x86/kernel/i8253.c           |    4 ++--
 arch/x86/kernel/tsc.c             |    4 ++--
 drivers/clocksource/acpi_pm.c     |    2 +-
 drivers/input/joystick/analog.c   |    2 +-
 sound/oss/pas2_pcm.c              |    8 ++++----
 6 files changed, 11 insertions(+), 11 deletions(-)
(quoted diff) +0 -0

b/arch/x86/include/asm/mach_timer.h
index 8537285..88d0c3c 100644

arch/x86/include/asm/mach_timer.h +1 -1
@@ -15,7 +15,7 @@
 
 #define CALIBRATE_TIME_MSEC 30 /* 30 msecs */
 #define CALIBRATE_LATCH	\
-	((CLOCK_TICK_RATE * CALIBRATE_TIME_MSEC + 1000/2)/1000)
+	((PIT_TICK_RATE * CALIBRATE_TIME_MSEC + 1000/2)/1000)
 
 static inline void mach_prepare_counter(void)
 {
arch/x86/kernel/i8253.c +2 -2
index c2e0bb0..5b0ef4e 100644
@@ -115,7 +115,7 @@ void __init setup_pit_timer(void)
 	 * IO_APIC has been initialized.
 	 */
 	pit_ce.cpumask = cpumask_of(smp_processor_id());
-	pit_ce.mult = div_sc(CLOCK_TICK_RATE, NSEC_PER_SEC, pit_ce.shift);
+	pit_ce.mult = div_sc(PIT_TICK_RATE, NSEC_PER_SEC, pit_ce.shift);
 	pit_ce.max_delta_ns = clockevent_delta2ns(0x7FFF, &pit_ce);
 	pit_ce.min_delta_ns = clockevent_delta2ns(0xF, &pit_ce);
 
@@ -223,7 +223,7 @@ static int __init init_pit_clocksource(void)
 	    pit_ce.mode != CLOCK_EVT_MODE_PERIODIC)
 		return 0;
 
-	pit_cs.mult = clocksource_hz2mult(CLOCK_TICK_RATE, pit_cs.shift);
+	pit_cs.mult = clocksource_hz2mult(PIT_TICK_RATE, pit_cs.shift);
 
 	return clocksource_register(&pit_cs);
 }
arch/x86/kernel/tsc.c +0 -0
index d57de05..d1cb3e5 100644
@@ -172,11 +172,11 @@ static unsigned long calc_pmtimer_ref(u64 deltatsc, u64 

pm1, u64 pm2)
}

#define CAL_MS 10
-#define CAL_LATCH (CLOCK_TICK_RATE / (1000 / CAL_MS))
+#define CAL_LATCH (PIT_TICK_RATE / (1000 / CAL_MS))
#define CAL_PIT_LOOPS 1000

#define CAL2_MS 50
-#define CAL2_LATCH (CLOCK_TICK_RATE / (1000 / CAL2_MS))
+#define CAL2_LATCH (PIT_TICK_RATE / (1000 / CAL2_MS))
#define CAL2_PIT_LOOPS 5000

drivers/clocksource/acpi_pm.c +0 -0
index 40bd8c6..8e4c896 100644
@@ -145,7 +145,7 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 

PCI_DEVICE_ID_SERVERWORKS_LE,
#ifndef CONFIG_X86_64
#include <asm/mach_timer.h>
#define PMTMR_EXPECTED_RATE \
- ((CALIBRATE_LATCH * (PMTMR_TICKS_PER_SEC >> 10)) / (CLOCK_TICK_RATE>>10))
+ ((CALIBRATE_LATCH * (PMTMR_TICKS_PER_SEC >> 10)) / (PIT_TICK_RATE>>10)) /*
* Some boards have the PMTMR running way too fast. We check
* the PMTMR rate against PIT channel 2 to catch these cases.

drivers/input/joystick/analog.c +0 -0
index 356b3a2..3f99867 100644
@@ -139,7 +139,7 @@ struct analog_port {
 #include <asm/i8253.h>
 
 #define GET_TIME(x)	do { if (cpu_has_tsc) rdtscl(x); else x = get_time_pit(); 

} while (0)
-#define DELTA(x,y) (cpu_has_tsc ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ?
CLOCK_TICK_RATE / HZ : 0)))
+#define DELTA(x,y) (cpu_has_tsc ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ?
PIT_TICK_RATE / HZ : 0)))
#define TIME_NAME (cpu_has_tsc?"TSC":"PIT")
static unsigned int get_time_pit(void)
{

sound/oss/pas2_pcm.c +4 -4
index 36c3ea6..0891e3b 100644
@@ -63,13 +63,13 @@ static int pcm_set_speed(int arg)
 
 	if (pcm_channels & 2)
 	{
-		foo = ((CLOCK_TICK_RATE / 2) + (arg / 2)) / arg;
-		arg = ((CLOCK_TICK_RATE / 2) + (foo / 2)) / foo;
+		foo = ((PIT_TICK_RATE / 2) + (arg / 2)) / arg;
+		arg = ((PIT_TICK_RATE / 2) + (foo / 2)) / foo;
 	}
 	else
 	{
-		foo = (CLOCK_TICK_RATE + (arg / 2)) / arg;
-		arg = (CLOCK_TICK_RATE + (foo / 2)) / foo;
+		foo = (PIT_TICK_RATE + (arg / 2)) / arg;
+		arg = (PIT_TICK_RATE + (foo / 2)) / foo;
 	}
 
 	pcm_speed = arg;
Signature · 3 lines
1.6.0.4

-- 
author maintainer
#54 lore raw

Re: [PATCH] x86: use PIT_TICK_RATE consistently

Quoted 1 line

From 5939f98adbf5ae727f0d3fa708247fc855f49dd2 Mon Sep 17 00:00:00 2001

From: Arnd Bergmann <[email protected]>
Date: Sun, 3 May 2009 22:42:56 +0000
Subject: [PATCH] x86: use PIT_TICK_RATE consistently

On x86, the CLOCK_TICK_RATE is defined in terms of PIT_TICK_RATE, from the original i8253 PIT frequency. Change all users to refer to PIT_TICK_RATE directly, in order to reduce the number of overloaded meanings for CLOCK_TICK_RATE.

---

resend without wordwrap...

 arch/x86/include/asm/mach_timer.h |    2 +-
 arch/x86/kernel/i8253.c           |    4 ++--
 arch/x86/kernel/tsc.c             |    4 ++--
 drivers/clocksource/acpi_pm.c     |    2 +-
 drivers/input/joystick/analog.c   |    2 +-
 sound/oss/pas2_pcm.c              |    8 ++++----
 6 files changed, 11 insertions(+), 11 deletions(-)
arch/x86/include/asm/mach_timer.h +1 -1
index 8537285..88d0c3c 100644
@@ -15,7 +15,7 @@
 
 #define CALIBRATE_TIME_MSEC 30 /* 30 msecs */
 #define CALIBRATE_LATCH	\
-	((CLOCK_TICK_RATE * CALIBRATE_TIME_MSEC + 1000/2)/1000)
+	((PIT_TICK_RATE * CALIBRATE_TIME_MSEC + 1000/2)/1000)
 
 static inline void mach_prepare_counter(void)
 {
arch/x86/kernel/i8253.c +2 -2
index c2e0bb0..5b0ef4e 100644
@@ -115,7 +115,7 @@ void __init setup_pit_timer(void)
 	 * IO_APIC has been initialized.
 	 */
 	pit_ce.cpumask = cpumask_of(smp_processor_id());
-	pit_ce.mult = div_sc(CLOCK_TICK_RATE, NSEC_PER_SEC, pit_ce.shift);
+	pit_ce.mult = div_sc(PIT_TICK_RATE, NSEC_PER_SEC, pit_ce.shift);
 	pit_ce.max_delta_ns = clockevent_delta2ns(0x7FFF, &pit_ce);
 	pit_ce.min_delta_ns = clockevent_delta2ns(0xF, &pit_ce);
 
@@ -223,7 +223,7 @@ static int __init init_pit_clocksource(void)
 	    pit_ce.mode != CLOCK_EVT_MODE_PERIODIC)
 		return 0;
 
-	pit_cs.mult = clocksource_hz2mult(CLOCK_TICK_RATE, pit_cs.shift);
+	pit_cs.mult = clocksource_hz2mult(PIT_TICK_RATE, pit_cs.shift);
 
 	return clocksource_register(&pit_cs);
 }
arch/x86/kernel/tsc.c +2 -2
index d57de05..d1cb3e5 100644
@@ -172,11 +172,11 @@ static unsigned long calc_pmtimer_ref(u64 deltatsc, u64 pm1, u64 pm2)
 }
 
 #define CAL_MS		10
-#define CAL_LATCH	(CLOCK_TICK_RATE / (1000 / CAL_MS))
+#define CAL_LATCH	(PIT_TICK_RATE / (1000 / CAL_MS))
 #define CAL_PIT_LOOPS	1000
 
 #define CAL2_MS		50
-#define CAL2_LATCH	(CLOCK_TICK_RATE / (1000 / CAL2_MS))
+#define CAL2_LATCH	(PIT_TICK_RATE / (1000 / CAL2_MS))
 #define CAL2_PIT_LOOPS	5000
 
 
drivers/clocksource/acpi_pm.c +1 -1
index 40bd8c6..8e4c896 100644
@@ -145,7 +145,7 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_LE,
 #ifndef CONFIG_X86_64
 #include <asm/mach_timer.h>
 #define PMTMR_EXPECTED_RATE \
-  ((CALIBRATE_LATCH * (PMTMR_TICKS_PER_SEC >> 10)) / (CLOCK_TICK_RATE>>10))
+  ((CALIBRATE_LATCH * (PMTMR_TICKS_PER_SEC >> 10)) / (PIT_TICK_RATE>>10))
 /*
  * Some boards have the PMTMR running way too fast. We check
  * the PMTMR rate against PIT channel 2 to catch these cases.
drivers/input/joystick/analog.c +1 -1
index 356b3a2..3f99867 100644
@@ -139,7 +139,7 @@ struct analog_port {
 #include <asm/i8253.h>
 
 #define GET_TIME(x)	do { if (cpu_has_tsc) rdtscl(x); else x = get_time_pit(); } while (0)
-#define DELTA(x,y)	(cpu_has_tsc ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? CLOCK_TICK_RATE / HZ : 0)))
+#define DELTA(x,y)	(cpu_has_tsc ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? PIT_TICK_RATE / HZ : 0)))
 #define TIME_NAME	(cpu_has_tsc?"TSC":"PIT")
 static unsigned int get_time_pit(void)
 {
sound/oss/pas2_pcm.c +4 -4
index 36c3ea6..0891e3b 100644
@@ -63,13 +63,13 @@ static int pcm_set_speed(int arg)
 
 	if (pcm_channels & 2)
 	{
-		foo = ((CLOCK_TICK_RATE / 2) + (arg / 2)) / arg;
-		arg = ((CLOCK_TICK_RATE / 2) + (foo / 2)) / foo;
+		foo = ((PIT_TICK_RATE / 2) + (arg / 2)) / arg;
+		arg = ((PIT_TICK_RATE / 2) + (foo / 2)) / foo;
 	}
 	else
 	{
-		foo = (CLOCK_TICK_RATE + (arg / 2)) / arg;
-		arg = (CLOCK_TICK_RATE + (foo / 2)) / foo;
+		foo = (PIT_TICK_RATE + (arg / 2)) / arg;
+		arg = (PIT_TICK_RATE + (foo / 2)) / foo;
 	}
 
 	pcm_speed = arg;
Signature · 1 line
1.6.0.4
author maintainer
#55 lore raw

PATCH 1/1 move PIT_TICK_RATE to linux/timex.h

In reply to a message not in the archive

PIT_TICK_RATE is currently defined in four architectures, but in three different places. While linux/timex.h is not the perfect place for it, it is still a reasonable replacement for those drivers that traditionally use asm/timex.h to get CLOCK_TICK_RATE and expect it to be the PIT frequency.

---
 arch/alpha/include/asm/8253pit.h   |    7 -------
 arch/alpha/kernel/sys_ruffian.c    |    1 +
 arch/mips/include/asm/i8253.h      |    2 --
 arch/powerpc/include/asm/8253pit.h |    7 -------
 arch/x86/include/asm/timex.h       |    4 +---
 arch/x86/kernel/i8253.c            |    1 +
 arch/x86/kernel/tsc.c              |    1 +
 drivers/clocksource/acpi_pm.c      |    1 +
 drivers/input/joystick/analog.c    |    2 +-
 drivers/input/misc/pcspkr.c        |    1 +
 include/linux/timex.h              |    3 +++
 sound/drivers/pcsp/pcsp.h          |    1 +
 sound/oss/pas2_pcm.c               |    2 +-
 13 files changed, 12 insertions(+), 21 deletions(-)
(quoted diff) +0 -0

b/arch/alpha/include/asm/8253pit.h
index fef5c14..a71c9c1 100644

arch/alpha/include/asm/8253pit.h +0 -7
@@ -1,10 +1,3 @@
 /*
  * 8253/8254 Programmable Interval Timer
  */
-
-#ifndef _8253PIT_H
-#define _8253PIT_H
-
-#define PIT_TICK_RATE 	1193180UL
-
-#endif
arch/alpha/kernel/sys_ruffian.c +1 -0
index f15a329..d9f9cfe 100644
@@ -14,6 +14,7 @@
 #include <linux/sched.h>
 #include <linux/pci.h>
 #include <linux/ioport.h>
+#include <linux/timex.h>
 #include <linux/init.h>
 
 #include <asm/ptrace.h>
arch/mips/include/asm/i8253.h +0 -2
index 5dabc87..032ca73 100644
@@ -12,8 +12,6 @@
 #define PIT_CH0			0x40
 #define PIT_CH2			0x42
 
-#define PIT_TICK_RATE		1193182UL
-
 extern spinlock_t i8253_lock;
 
 extern void setup_pit_timer(void);
(quoted diff) +0 -0

b/arch/powerpc/include/asm/8253pit.h
index b70d6e5..a71c9c1 100644

arch/powerpc/include/asm/8253pit.h +0 -7
@@ -1,10 +1,3 @@
-#ifndef _ASM_POWERPC_8253PIT_H
-#define _ASM_POWERPC_8253PIT_H
-
 /*
  * 8253/8254 Programmable Interval Timer
  */
-
-#define PIT_TICK_RATE	1193182UL
-
-#endif	/* _ASM_POWERPC_8253PIT_H */
arch/x86/include/asm/timex.h +1 -3
index b5c9d45..1375cfc 100644
@@ -4,9 +4,7 @@
 #include <asm/processor.h>
 #include <asm/tsc.h>
 
-/* The PIT ticks at this frequency (in HZ): */
-#define PIT_TICK_RATE		1193182
-
+/* Assume we use the PIT time source for the clock tick */
 #define CLOCK_TICK_RATE		PIT_TICK_RATE
 
 #define ARCH_HAS_READ_CURRENT_TIMER
arch/x86/kernel/i8253.c +1 -0
index 5b0ef4e..3e5ec80 100644
@@ -7,6 +7,7 @@
 #include <linux/spinlock.h>
 #include <linux/jiffies.h>
 #include <linux/module.h>
+#include <linux/timex.h>
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/io.h>
arch/x86/kernel/tsc.c +1 -0
index d1cb3e5..5c627ff 100644
@@ -9,6 +9,7 @@
 #include <linux/delay.h>
 #include <linux/clocksource.h>
 #include <linux/percpu.h>
+#include <linux/timex.h>
 
 #include <asm/hpet.h>
 #include <asm/timer.h>
drivers/clocksource/acpi_pm.c +1 -0
index 8e4c896..f6d351c 100644
@@ -18,6 +18,7 @@
 
 #include <linux/acpi_pmtmr.h>
 #include <linux/clocksource.h>
+#include <linux/timex.h>
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/pci.h>
drivers/input/joystick/analog.c +1 -1
index 3f99867..5776f72 100644
@@ -35,7 +35,7 @@
 #include <linux/input.h>
 #include <linux/gameport.h>
 #include <linux/jiffies.h>
-#include <asm/timex.h>
+#include <linux/timex.h>
 
 #define DRIVER_DESC	"Analog joystick and gamepad driver"
 
drivers/input/misc/pcspkr.c +1 -0
index d6a30ce..6d67af5 100644
@@ -17,6 +17,7 @@
 #include <linux/init.h>
 #include <linux/input.h>
 #include <linux/platform_device.h>
+#include <linux/timex.h>
 #include <asm/io.h>
 
 MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
include/linux/timex.h +3 -0
index aa3475f..66cbf74 100644
@@ -260,6 +260,9 @@ extern int do_adjtimex(struct timex *);
 
 int read_current_timer(unsigned long *timer_val);
 
+/* The clock frequency of the i8253/i8254 PIT */
+#define PIT_TICK_RATE 1193182ul
+
 #endif /* KERNEL */
 
 #endif /* LINUX_TIMEX_H */
sound/drivers/pcsp/pcsp.h +1 -0
index cdef266..174dd2f 100644
@@ -10,6 +10,7 @@
 #define __PCSP_H__
 
 #include <linux/hrtimer.h>
+#include <linux/timex.h>
 #if defined(CONFIG_MIPS) || defined(CONFIG_X86)
 /* Use the global PIT lock ! */
 #include <asm/i8253.h>
sound/oss/pas2_pcm.c +1 -1
index 0891e3b..6f13ab4 100644
@@ -17,7 +17,7 @@
 
 #include <linux/init.h>
 #include <linux/spinlock.h>
-#include <asm/timex.h>
+#include <linux/timex.h>
 #include "sound_config.h"
 
 #include "pas2.h"
Signature · 3 lines
1.6.0.4

-- 
#56 lore raw

Re: [PATCH] move PIT_TICK_RATE to linux/timex.h

Review

Quoted 13 lines · On Mon, 11 May 2009 22:55:36 +0000 Arnd Bergmann <[email protected]> wrote:

PIT_TICK_RATE is currently defined in four architectures, but in three different places. While linux/timex.h is not the perfect place for it, it is still a reasonable replacement for those drivers that traditionally use asm/timex.h to get CLOCK_TICK_RATE and expect it to be the PIT frequency.

...

(quoted diff) +1 -4
-#define PIT_TICK_RATE 	1193180UL
-#define PIT_TICK_RATE		1193182UL
-#define PIT_TICK_RATE	1193182UL
-#define PIT_TICK_RATE		1193182
+#define PIT_TICK_RATE 1193182ul

So the type got changed in arch/x86/include/asm/timex.h. Did you check whether that changes anything? I did a quick check and didn't see any obvious problems..

author maintainer
#57 lore raw

Re: [PATCH] move PIT_TICK_RATE to linux/timex.h

Quoted 3 lines · Andrew Morton

So the type got changed in arch/x86/include/asm/timex.h.  Did you check whether that changes anything? I did a quick check and didn't see any obvious problems..

I did not check if the object file changes, just checked that the macro is not used in assembly code, which would break.

Note that for Alpha, the actual value changed from 1193182UL to 1193180UL. This is unlikely to make a difference, and probably can only improve accuracy. There was a discussion on the correct value of CLOCK_TICK_RATE a few years ago, after which every existing instance was getting changed to 1193182. According to the specification, it should be 1193181.818181...

	Arnd <><
author maintainer
#58 lore raw

PATCH 1/1 mips: use PIT_TICK_RATE in i8253

In reply to a message not in the archive

Using PIT_TICK_RATE instead of CLOCK_TICK_RATE allows us to later change CLOCK_TICK_RATE to a more sensible time base value for platforms that do not base their system timer off an i8253.

---
 arch/mips/kernel/i8253.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
arch/mips/kernel/i8253.c +3 -2
index ed20e7f..3545419 100644
@@ -8,6 +8,7 @@
 #include <linux/jiffies.h>
 #include <linux/module.h>
 #include <linux/spinlock.h>
+#include <linux/timex.h>
 
 #include <asm/delay.h>
 #include <asm/i8253.h>
@@ -115,7 +116,7 @@ void __init setup_pit_timer(void)
 	 * IO_APIC has been initialized.
 	 */
 	cd->cpumask = cpumask_of(cpu);
-	clockevent_set_clock(cd, CLOCK_TICK_RATE);
+	clockevent_set_clock(cd, PIT_TICK_RATE);
 	cd->max_delta_ns = clockevent_delta2ns(0x7FFF, cd);
 	cd->min_delta_ns = clockevent_delta2ns(0xF, cd);
 	clockevents_register_device(cd);
@@ -203,7 +204,7 @@ static int __init init_pit_clocksource(void)
 	if (num_possible_cpus() > 1) /* PIT does not scale! */
 		return 0;
 
-	clocksource_pit.mult = clocksource_hz2mult(CLOCK_TICK_RATE, 20);
+	clocksource_pit.mult = clocksource_hz2mult(PIT_TICK_RATE, 20);
 	return clocksource_register(&clocksource_pit);
 }
 arch_initcall(init_pit_clocksource);
Signature · 3 lines
1.6.0.4

-- 
author maintainer
#59 lore raw

PATCH 1/1 input: use PIT_TICK_RATE in vt beep ioctl

In reply to a message not in the archive

The KIOCSOUND and KDMKTONE ioctls are based on the CLOCK_TICK_RATE, which is architecture and sometimes configuration specific.

In practice, most user applications assume that it is actually defined as the i8253 PIT base clock of 1193182 Hz, which is true on some architectures but not on others.

This patch makes the vt code use the PIT frequency on all architectures, which is much more well-defined. It will change the behavior of user applications sending the beep ioctl on all architectures that define CLOCK_TICK_RATE different from PIT_TICK_RATE.

Hopefully, this change will make the frequency correct in more cases than it will make it incorrect.

This patch depends on "move PIT_TICK_RATE to linux/timex.h" in order to build on architectures that previously did not define PIT_TICK_RATE.

---
 drivers/char/vt_ioctl.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/char/vt_ioctl.c +2 -2
index e6ce632..00f96b6 100644
@@ -404,7 +404,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
 		   supported and somehow separate the historic advertised
 		   tick rate from any real one */
 		if (arg)
-			arg = CLOCK_TICK_RATE / arg;
+			arg = PIT_TICK_RATE / arg;
 		kd_mksound(arg, 0);
 		break;
 
@@ -424,7 +424,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
 		   supported and somehow separate the historic advertised
 		   tick rate from any real one */
 		if (count)
-			count = CLOCK_TICK_RATE / count;
+			count = PIT_TICK_RATE / count;
 		kd_mksound(count, ticks);
 		break;
 	}
Signature · 3 lines
1.6.0.4

-- 
author maintainer
#61 lore raw

PATCH 1/1 x86: fix ktermios-termio conversion

In reply to a message not in the archive

The operation with the variable 'c_line' was missing in the function 'user_termio_to_kernel_termios'. Also the casting '*(unsigned short *)' in the macro 'SET_LOW_TERMIOS_BITS' was a bit 'unhealthy'. So the macro was removed and the function was changed to be like in other archs (e.g. h8300, m68k, sparc) that have a more elegant solution.

In the function 'kernel_termios_to_user_termio' the return values of the functions calls 'put_user' and 'copy_to_user' were not being checked.

---
 arch/x86/include/asm/termios.h |   54 +++++++++++++++++++++++++++------------
 1 files changed, 37 insertions(+), 17 deletions(-)
arch/x86/include/asm/termios.h +28 -11
index f729563..47420df 100644
@@ -54,20 +54,37 @@ struct termio {
 /*
  * Translate a "termio" structure into a "termios". Ugh.
  */
-#define SET_LOW_TERMIOS_BITS(termios, termio, x) { \
-	unsigned short __tmp; \
-	get_user(__tmp,&(termio)->x); \
-	*(unsigned short *) &(termios)->x = __tmp; \
-}
-
 static inline int user_termio_to_kernel_termios(struct ktermios *termios,
 						struct termio __user *termio)
 {
-	SET_LOW_TERMIOS_BITS(termios, termio, c_iflag);
-	SET_LOW_TERMIOS_BITS(termios, termio, c_oflag);
-	SET_LOW_TERMIOS_BITS(termios, termio, c_cflag);
-	SET_LOW_TERMIOS_BITS(termios, termio, c_lflag);
-	return copy_from_user(termios->c_cc, termio->c_cc, NCC);
+	unsigned short tmp;
+
+	if (get_user(tmp, &termio->c_iflag) < 0)
+		goto fault;
+	termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
+
+	if (get_user(tmp, &termio->c_oflag) < 0)
+		goto fault;
+	termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
+
+	if (get_user(tmp, &termio->c_cflag) < 0)
+		goto fault;
+	termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;
+
+	if (get_user(tmp, &termio->c_lflag) < 0)
+		goto fault;
+	termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
+
+	if (get_user(termios->c_line, &termio->c_line) < 0)
+		goto fault;
+
+	if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
+		goto fault;
+
+	return 0;
+
+ fault:
+	return -EFAULT;
 }
 
 /*
@@ -76,12 +93,15 @@ static inline int user_termio_to_kernel_termios(struct 

ktermios *termios,
static inline int kernel_termios_to_user_termio(struct termio __user *termio,
struct ktermios *termios)
{
- put_user((termios)->c_iflag, &(termio)->c_iflag);
- put_user((termios)->c_oflag, &(termio)->c_oflag);
- put_user((termios)->c_cflag, &(termio)->c_cflag);
- put_user((termios)->c_lflag, &(termio)->c_lflag);
- put_user((termios)->c_line, &(termio)->c_line);
- return copy_to_user((termio)->c_cc, (termios)->c_cc, NCC);

+	if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
+	    put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
+	    put_user(termios->c_cflag, &termio->c_cflag) < 0 ||
+	    put_user(termios->c_lflag, &termio->c_lflag) < 0 ||
+	    put_user(termios->c_line,  &termio->c_line) < 0 ||

+ copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0)
+ return -EFAULT;
+
+ return 0;
}

static inline int user_termios_to_kernel_termios(struct ktermios *k,

Signature · 3 lines
1.6.0.4

-- 
author maintainer
#62 lore raw

PATCH v2 1/1 x86: fix ktermios-termio conversion

The operation with the variable 'c_line' was missing in the function 'user_termio_to_kernel_termios'. Also the casting '*(unsigned short *)' in the macro 'SET_LOW_TERMIOS_BITS' was a bit 'unhealthy'. So the macro was removed and the function was changed to be like in other archs (e.g. h8300, m68k, sparc) that have a more elegant solution.

In the function 'kernel_termios_to_user_termio' the return values of the functions calls 'put_user' and 'copy_to_user' were not being checked.

---

initial patch was wordwrapped, resend

 arch/x86/include/asm/termios.h |   54 +++++++++++++++++++++++++++------------
 1 files changed, 37 insertions(+), 17 deletions(-)
arch/x86/include/asm/termios.h +37 -17
index f729563..47420df 100644
@@ -54,20 +54,37 @@ struct termio {
 /*
  * Translate a "termio" structure into a "termios". Ugh.
  */
-#define SET_LOW_TERMIOS_BITS(termios, termio, x) { \
-	unsigned short __tmp; \
-	get_user(__tmp,&(termio)->x); \
-	*(unsigned short *) &(termios)->x = __tmp; \
-}
-
 static inline int user_termio_to_kernel_termios(struct ktermios *termios,
 						struct termio __user *termio)
 {
-	SET_LOW_TERMIOS_BITS(termios, termio, c_iflag);
-	SET_LOW_TERMIOS_BITS(termios, termio, c_oflag);
-	SET_LOW_TERMIOS_BITS(termios, termio, c_cflag);
-	SET_LOW_TERMIOS_BITS(termios, termio, c_lflag);
-	return copy_from_user(termios->c_cc, termio->c_cc, NCC);
+	unsigned short tmp;
+
+	if (get_user(tmp, &termio->c_iflag) < 0)
+		goto fault;
+	termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
+
+	if (get_user(tmp, &termio->c_oflag) < 0)
+		goto fault;
+	termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
+
+	if (get_user(tmp, &termio->c_cflag) < 0)
+		goto fault;
+	termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;
+
+	if (get_user(tmp, &termio->c_lflag) < 0)
+		goto fault;
+	termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
+
+	if (get_user(termios->c_line, &termio->c_line) < 0)
+		goto fault;
+
+	if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
+		goto fault;
+
+	return 0;
+
+ fault:
+	return -EFAULT;
 }
 
 /*
@@ -76,12 +93,15 @@ static inline int user_termio_to_kernel_termios(struct ktermios *termios,
 static inline int kernel_termios_to_user_termio(struct termio __user *termio,
 					    struct ktermios *termios)
 {
-	put_user((termios)->c_iflag, &(termio)->c_iflag);
-	put_user((termios)->c_oflag, &(termio)->c_oflag);
-	put_user((termios)->c_cflag, &(termio)->c_cflag);
-	put_user((termios)->c_lflag, &(termio)->c_lflag);
-	put_user((termios)->c_line,  &(termio)->c_line);
-	return copy_to_user((termio)->c_cc, (termios)->c_cc, NCC);
+	if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
+	    put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
+	    put_user(termios->c_cflag, &termio->c_cflag) < 0 ||
+	    put_user(termios->c_lflag, &termio->c_lflag) < 0 ||
+	    put_user(termios->c_line,  &termio->c_line) < 0 ||
+	    copy_to_user(termio->c_cc, termios->c_cc, NCC) != 0)
+		return -EFAULT;
+
+	return 0;
 }
 
 static inline int user_termios_to_kernel_termios(struct ktermios *k,
Signature · 1 line
1.6.0.4
#63 lore raw

Re: [PATCH v2] x86: fix ktermios-termio conversion

Quoted 54 lines · Arnd Bergmann

The operation with the variable 'c_line' was missing in the function 'user_termio_to_kernel_termios'. Also the casting '*(unsigned short *)' in the macro 'SET_LOW_TERMIOS_BITS' was a bit 'unhealthy'. So the macro was removed and the function was changed to be like in other archs (e.g. h8300, m68k, sparc) that have a more elegant solution.

In the function 'kernel_termios_to_user_termio' the return values of the functions calls 'put_user' and 'copy_to_user' were not being checked.

---

initial patch was wordwrapped, resend

 arch/x86/include/asm/termios.h |   54 +++++++++++++++++++++++++++------------
 1 files changed, 37 insertions(+), 17 deletions(-)
arch/x86/include/asm/termios.h +13 -11
index f729563..47420df 100644
@@ -54,20 +54,37 @@ struct termio {
 /*
  * Translate a "termio" structure into a "termios". Ugh.
  */
-#define SET_LOW_TERMIOS_BITS(termios, termio, x) { \
-	unsigned short __tmp; \
-	get_user(__tmp,&(termio)->x); \
-	*(unsigned short *) &(termios)->x = __tmp; \
-}
-
 static inline int user_termio_to_kernel_termios(struct ktermios *termios,
 						struct termio __user *termio)
 {
-	SET_LOW_TERMIOS_BITS(termios, termio, c_iflag);
-	SET_LOW_TERMIOS_BITS(termios, termio, c_oflag);
-	SET_LOW_TERMIOS_BITS(termios, termio, c_cflag);
-	SET_LOW_TERMIOS_BITS(termios, termio, c_lflag);
-	return copy_from_user(termios->c_cc, termio->c_cc, NCC);
+	unsigned short tmp;
+
+	if (get_user(tmp, &termio->c_iflag) < 0)
+		goto fault;
+	termios->c_iflag = (0xffff0000 & termios->c_iflag) | tmp;
+
+	if (get_user(tmp, &termio->c_oflag) < 0)
+		goto fault;
+	termios->c_oflag = (0xffff0000 & termios->c_oflag) | tmp;
+
+	if (get_user(tmp, &termio->c_cflag) < 0)
+		goto fault;
+	termios->c_cflag = (0xffff0000 & termios->c_cflag) | tmp;

arch/x86/include/asm/termios.h struct termio { · line 82

Quoted 10 lines
arch/x86/include/asm/termios.h +10 -0
+
+	if (get_user(tmp, &termio->c_lflag) < 0)
+		goto fault;
+	termios->c_lflag = (0xffff0000 & termios->c_lflag) | tmp;
+
+	if (get_user(termios->c_line, &termio->c_line) < 0)
+		goto fault;
+
+	if (copy_from_user(termios->c_cc, termio->c_cc, NCC) != 0)
+		goto fault;

Hm, that looks a bit ugly and it also adds 150 bytes of bloat to the kernel:

drivers/char/tty_ioctl.o:

text data bss dec hex filename

   4704	      0	      0	   4704	   1260	tty_ioctl.o.before
   4841	      0	      0	   4841	   12e9	tty_ioctl.o.after

(64-bit 'make defconfig', on latest tip:master)

Ingo

author maintainer
#64 lore raw

Re: [PATCH v2] x86: fix ktermios-termio conversion

Quoted 8 lines · Ingo Molnar

Hm, that looks a bit ugly and it also adds 150 bytes of bloat to the kernel:

drivers/char/tty_ioctl.o:

   text    data     bss     dec     hex filename 4704       0       0    4704    1260 tty_ioctl.o.before 4841       0       0    4841    12e9 tty_ioctl.o.after

It's easy to go back to a macro (or replace it by another inline function if you prefer that stylistically) to make it look nicer.

Regarding the bloat, I'm still looking for a better version. The code I posted is basically what is in asm-generic/termios.h traditionally, so at least I'm reasonably confident that it is correct, while the x86 version currently fails to return -EFAULT on incorrect pointers and misses c_line changes.

I now tried this version, which theoretically should be fairly compact on most architectures:

static inline int set_low_termios_bits(unsigned int *termios,
const short __user *termio)

{
	unsigned short tmp;
	int ret;

	ret = __get_user(tmp, termio);
	*termios = (0xffff0000 & *termios) | tmp;

	return ret;
}

/*
* Translate a "termio" structure into a "termios". Ugh.
*/
static inline int user_termio_to_kernel_termios(struct ktermios *termios,
const struct termio __user *termio)

{
	if (access_ok(VERIFY_READ, termio, sizeof (*termio)))
		return -EFAULT;

	return set_low_termios_bits(&termios->c_iflag, &termio->c_iflag) |
	       set_low_termios_bits(&termios->c_oflag, &termio->c_oflag) |
	       set_low_termios_bits(&termios->c_cflag, &termio->c_cflag) |
	       set_low_termios_bits(&termios->c_lflag, &termio->c_lflag) |
	       __get_user(termios->c_line, &termio->c_line) |
	       (__copy_from_user(termios->c_cc, termio->c_cc, NCC)
				? -EFAULT : 0);
}

/*
* Translate a "termios" structure into a "termio". Ugh.
*/
static inline int kernel_termios_to_user_termio(struct termio __user *termio,
struct ktermios *termios)

{
	if (access_ok(VERIFY_WRITE, termio, sizeof (*termio)))
		return -EFAULT;

	return __put_user(termios->c_iflag, &termio->c_iflag) |
	       __put_user(termios->c_oflag, &termio->c_oflag) |
	       __put_user(termios->c_cflag, &termio->c_cflag) |
	       __put_user(termios->c_lflag, &termio->c_lflag) |
	       __put_user(termios->c_line,  &termio->c_line) |
	       (__copy_to_user(termio->c_cc, termios->c_cc, NCC)
				? -EFAULT : 0);
}

Unfortunately, this is even more code on x86, where get_user/put_user is out-of-line, while __get_user/__put_user is inline and produces fixup code.
The best I could come up with is somewhat slower but also shorter:

static inline int set_low_termios_bits(unsigned int *termios,
const short __user *termio)

{
	unsigned short tmp;
	int ret;

	ret = get_user(tmp, termio);
	*termios = (0xffff0000 & *termios) | tmp;

	return ret;
}

/*
* Translate a "termio" structure into a "termios". Ugh.
*/
static inline int user_termio_to_kernel_termios(struct ktermios *termios,
const struct termio __user *termio)

{
	return (set_low_termios_bits(&termios->c_iflag, &termio->c_iflag) ||
		set_low_termios_bits(&termios->c_oflag, &termio->c_oflag) ||
		set_low_termios_bits(&termios->c_cflag, &termio->c_cflag) ||
		set_low_termios_bits(&termios->c_lflag, &termio->c_lflag) ||
		get_user(termios->c_line, &termio->c_line) ||
		copy_from_user(termios->c_cc, termio->c_cc, NCC))
				? -EFAULT : 0;
}

/*
* Translate a "termios" structure into a "termio". Ugh.
*/
static inline int kernel_termios_to_user_termio(struct termio __user *termio,
struct ktermios *termios)

{
	return put_user(termios->c_iflag, &termio->c_iflag) ||
	       put_user(termios->c_oflag, &termio->c_oflag) ||
	       put_user(termios->c_cflag, &termio->c_cflag) ||
	       put_user(termios->c_lflag, &termio->c_lflag) ||
	       put_user(termios->c_line,  &termio->c_line) ||
	       (copy_to_user(termio->c_cc, termios->c_cc, NCC))
				? -EFAULT : 0;
}

If you think that looks better, I can send another patch. I have not tested this code functionally though.

	Arnd <><
#65 lore raw

Re: [PATCH v2] x86: fix ktermios-termio conversion

Quoted 4 lines · Arnd Bergmann
Quoted 3 lines · Ingo Molnar

Hm, that looks a bit ugly and it also adds 150 bytes of bloat to the kernel:

Quoted 8 lines
Quoted 5 lines

drivers/char/tty_ioctl.o:

   text    data     bss     dec     hex filename 4704       0       0    4704    1260 tty_ioctl.o.before 4841       0       0    4841    12e9 tty_ioctl.o.after

It's easy to go back to a macro (or replace it by another inline function if you prefer that stylistically) to make it look nicer.

no, we shouldnt go back to a macro.

Quoted 104 lines

Regarding the bloat, I'm still looking for a better version. The code I posted is basically what is in asm-generic/termios.h traditionally, so at least I'm reasonably confident that it is correct, while the x86 version currently fails to return -EFAULT on incorrect pointers and misses c_line changes.

I now tried this version, which theoretically should be fairly compact on most architectures:

static inline int set_low_termios_bits(unsigned int *termios,
const short __user *termio)

{
	unsigned short tmp;
	int ret;

	ret = __get_user(tmp, termio);
	*termios = (0xffff0000 & *termios) | tmp;

	return ret;
}

/*
* Translate a "termio" structure into a "termios". Ugh.
*/
static inline int user_termio_to_kernel_termios(struct ktermios *termios,
const struct termio __user *termio)

{
	if (access_ok(VERIFY_READ, termio, sizeof (*termio)))
		return -EFAULT;

	return set_low_termios_bits(&termios->c_iflag, &termio->c_iflag) |
	       set_low_termios_bits(&termios->c_oflag, &termio->c_oflag) |
	       set_low_termios_bits(&termios->c_cflag, &termio->c_cflag) |
	       set_low_termios_bits(&termios->c_lflag, &termio->c_lflag) |
	       __get_user(termios->c_line, &termio->c_line) |
	       (__copy_from_user(termios->c_cc, termio->c_cc, NCC)
				? -EFAULT : 0);
}

/*
* Translate a "termios" structure into a "termio". Ugh.
*/
static inline int kernel_termios_to_user_termio(struct termio __user *termio,
struct ktermios *termios)

{
	if (access_ok(VERIFY_WRITE, termio, sizeof (*termio)))
		return -EFAULT;

	return __put_user(termios->c_iflag, &termio->c_iflag) |
	       __put_user(termios->c_oflag, &termio->c_oflag) |
	       __put_user(termios->c_cflag, &termio->c_cflag) |
	       __put_user(termios->c_lflag, &termio->c_lflag) |
	       __put_user(termios->c_line,  &termio->c_line) |
	       (__copy_to_user(termio->c_cc, termios->c_cc, NCC)
				? -EFAULT : 0);
}

Unfortunately, this is even more code on x86, where get_user/put_user is out-of-line, while __get_user/__put_user is inline and produces fixup code.
The best I could come up with is somewhat slower but also shorter:

static inline int set_low_termios_bits(unsigned int *termios,
const short __user *termio)

{
	unsigned short tmp;
	int ret;

	ret = get_user(tmp, termio);
	*termios = (0xffff0000 & *termios) | tmp;

	return ret;
}

/*
* Translate a "termio" structure into a "termios". Ugh.
*/
static inline int user_termio_to_kernel_termios(struct ktermios *termios,
const struct termio __user *termio)

{
	return (set_low_termios_bits(&termios->c_iflag, &termio->c_iflag) ||
		set_low_termios_bits(&termios->c_oflag, &termio->c_oflag) ||
		set_low_termios_bits(&termios->c_cflag, &termio->c_cflag) ||
		set_low_termios_bits(&termios->c_lflag, &termio->c_lflag) ||
		get_user(termios->c_line, &termio->c_line) ||
		copy_from_user(termios->c_cc, termio->c_cc, NCC))
				? -EFAULT : 0;
}

/*
* Translate a "termios" structure into a "termio". Ugh.
*/
static inline int kernel_termios_to_user_termio(struct termio __user *termio,
struct ktermios *termios)

{
	return put_user(termios->c_iflag, &termio->c_iflag) ||
	       put_user(termios->c_oflag, &termio->c_oflag) ||
	       put_user(termios->c_cflag, &termio->c_cflag) ||
	       put_user(termios->c_lflag, &termio->c_lflag) ||
	       put_user(termios->c_line,  &termio->c_line) ||
	       (copy_to_user(termio->c_cc, termios->c_cc, NCC))
				? -EFAULT : 0;
}
Quoted 2 lines

If you think that looks better, I can send another patch. I have not tested this code functionally though.

hm, on x86 you could use get_user_try / get_user_ex() / get_user_catch() approach to linearize the dependencies and reduce register pressure.

Ingo

#66 lore raw

Re: [PATCH v2] x86: fix ktermios-termio conversion

Quoted 3 lines

hm, on x86 you could use get_user_try / get_user_ex() / get_user_catch() approach to linearize the dependencies and reduce register pressure.

It used *once*, in a path that is never executed except by some ancient binaries. It isn't worth the effort.

#67 lore raw

Re: [PATCH v2] x86: fix ktermios-termio conversion

Quoted 6 lines · Alan Cox
Quoted 3 lines

hm, on x86 you could use get_user_try / get_user_ex() / get_user_catch() approach to linearize the dependencies and reduce register pressure.

It used *once*, in a path that is never executed except by some ancient binaries. It isn't worth the effort.

i know, and i tested the patch so i know what effects it has.

I never made any argument about inlining, it's obviously correct to have a use-once function inline.

My argument was very simple: the patch causes +150 bytes of bloat. The try/ex/catch method can help reduce register pressure and can reducethe size of code quite visibly.

Ingo

#68 lore raw

Re: [PATCH v2] x86: fix ktermios-termio conversion

Quoted 3 lines

My argument was very simple: the patch causes +150 bytes of bloat. The try/ex/catch method can help reduce register pressure and can reducethe size of code quite visibly.

My argument is even simpler - its not worth the effort in the first place.

I'm sure you could use the same time to shave 150 bytes and a few clocks of a path that actually gets executed.

Arnd - can you send me a diff that keeps the existing horrible macro version, the existing __put_user usage and just fixes c_line ? It's worked for 15 years, its not worth the time being fancy with it.

Alan

#69 lore raw

Re: [PATCH v2] x86: fix ktermios-termio conversion

Quoted 9 lines · Alan Cox
Quoted 3 lines

My argument was very simple: the patch causes +150 bytes of bloat. The try/ex/catch method can help reduce register pressure and can reducethe size of code quite visibly.

My argument is even simpler - its not worth the effort in the first place.

I'm sure you could use the same time to shave 150 bytes and a few clocks of a path that actually gets executed.

This is about kernel image size as well. This version of the patch bloats the kernel. The death of a thousand cuts ...

Quoted 4 lines

Arnd - can you send me a diff that keeps the existing horrible macro version, the existing __put_user usage and just fixes c_line ? It's worked for 15 years, its not worth the time being fancy with it.

Agreed.

Ingo

author maintainer
#70 lore raw

PATCH v3 1/1 x86: fix ktermios-termio conversion

In reply to Alan Cox

The legacy TCSETA{,W,F} ioctls failed to set the termio->c_line field on x86. This adds a missing get_user.

The same ioctls also fail to report faulting user pointers, which we keep ignoring.

---

Quoted 3 lines · Alan Cox

Arnd - can you send me a diff that keeps the existing horrible macro version, the existing __put_user usage and just fixes c_line ? It's worked for 15 years, its not worth the time being fancy with it.

I should probably have made my intention clearer. I'm sitting on a series of patches [1] that generalize a lot of headers by making an asm-generic version and falling back on this in all architectures that have the same code.

The x86 SET_LOW_TERMIOS_BITS macro, besides its own stylistic problems, only works on little-endian architectures and generates compiler warnings on architectures on which get_user returns 'int __must_check'. My asm-generic version fixes this by using the architecture independent code I posted in this thread.

One of my later patches removes all x86 specific headers that are identical to the asm-generic version. The termios.h header is almost identical, so I first wanted to submit the patch to make it actually the same.

	Arnd <><

[1] git.kernel.org:/pub/scm/linux/kernel/git/arnd/asm-generic.git

arch/x86/include/asm/termios.h +1 -0
index f729563..c4ee805 100644
@@ -67,6 +67,7 @@ static inline int user_termio_to_kernel_termios(struct ktermios *termios,
 	SET_LOW_TERMIOS_BITS(termios, termio, c_oflag);
 	SET_LOW_TERMIOS_BITS(termios, termio, c_cflag);
 	SET_LOW_TERMIOS_BITS(termios, termio, c_lflag);
+	get_user(termios->c_line, &termio->c_line);
 	return copy_from_user(termios->c_cc, termio->c_cc, NCC);
 }
 
author maintainer
#71 lore raw

Re: [PATCH v2] x86: fix ktermios-termio conversion

In reply to Ingo Molnar
Quoted 3 lines · Ingo Molnar

hm, on x86 you could use get_user_try / get_user_ex() / get_user_catch() approach to linearize the dependencies and reduce register pressure.

Yes, but that would not help my intention of making the file more generic. The x86 code was copied into a number of architectures, and at least arm, m32r, parisc, sh and xtensa have big-endian configurations where the implementation is wrong.

I only realized that while writing this email though and I guess I need to fix those as well now ;-)

	Arnd <><
#72 lore raw

Re: [PATCH v2] x86: fix ktermios-termio conversion

In reply to Arnd Bergmann
Quoted 2 lines

I now tried this version, which theoretically should be fairly compact on most architectures:

We don't really need to inline any of this btw - its an back compat obscure path so its not performance relevant at all.

We probably should fix c_line but the rest is hardly worth the bother.

author maintainer
#73 lore raw

PATCH 1/1 syscalls.h add the missing sys_pipe2 declaration

In reply to a message not in the archive

In order to build the generic syscall table, we need a declaration for every system call. sys_pipe2 was added without a proper declaration, so add this to syscalls.h now.

---
 include/linux/syscalls.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/syscalls.h +0 -0
index 40617c1..3052084 100644
@@ -433,6 +433,7 @@ asmlinkage long sys_fcntl(unsigned int fd, unsigned int 

cmd, unsigned long arg);
asmlinkage long sys_fcntl64(unsigned int fd,
unsigned int cmd, unsigned long arg);
#endif
+asmlinkage long sys_pipe2(int __user *fildes, int flags);
asmlinkage long sys_dup(unsigned int fildes);
asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd); asmlinkage long sys_dup3(unsigned int oldfd, unsigned int newfd, int flags);

Signature · 3 lines
1.6.0.4

-- 
author maintainer
#74 lore raw

PATCH 1/1 syscalls.h add the missing sys_pipe2 declaration

In order to build the generic syscall table, we need a declaration for every system call. sys_pipe2 was added without a proper declaration, so add this to syscalls.h now.

---
re-sent without the wordwrap...

 include/linux/syscalls.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/syscalls.h +1 -0
index 40617c1..3052084 100644
@@ -433,6 +433,7 @@ asmlinkage long sys_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg);
 asmlinkage long sys_fcntl64(unsigned int fd,
 				unsigned int cmd, unsigned long arg);
 #endif
+asmlinkage long sys_pipe2(int __user *fildes, int flags);
 asmlinkage long sys_dup(unsigned int fildes);
 asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd);
 asmlinkage long sys_dup3(unsigned int oldfd, unsigned int newfd, int flags);
Signature · 1 line
1.6.0.4
author maintainer
#75 lore raw

PATCH 1/1 ipc: use __ARCH_WANT_IPC_PARSE_VERSION in ipc/util.h

In reply to a message not in the archive

The definition of ipc_parse_version depends on __ARCH_WANT_IPC_PARSE_VERSION, but the header file declares it conditionally based on the architecture.

Use the macro consistently to make it easier to add new architectures.

---
 ipc/util.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
ipc/util.h +1 -1
index 1187332..f9fe90e 100644
@@ -128,7 +128,7 @@ void ipc_update_perm(struct ipc64_perm *in, struct kern_ipc_perm *out);
 struct kern_ipc_perm *ipcctl_pre_down(struct ipc_ids *ids, int id, int cmd,
 				      struct ipc64_perm *perm, int extra_perm);
 
-#if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__)
+#ifndef __ARCH_WANT_IPC_PARSE_VERSION
   /* On IA-64, we always use the "64-bit version" of the IPC structures.  */ 
 # define ipc_parse_version(cmd)	IPC_64
 #else
Signature · 3 lines
1.6.0.4

-- 
Acked-by on v1 1/1
#76 lore raw

Re: [PATCH] ipc: use __ARCH_WANT_IPC_PARSE_VERSION in ipc/util.h

Quoted 8 lines · Arnd Bergmann

The definition of ipc_parse_version depends on __ARCH_WANT_IPC_PARSE_VERSION, but the header file declares it conditionally based on the architecture.

Use the macro consistently to make it easier to add new architectures.

Makes sense!

thanks,
-serge

Quoted 22 lines
---
 ipc/util.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
ipc/util.h +1 -1
index 1187332..f9fe90e 100644
@@ -128,7 +128,7 @@ void ipc_update_perm(struct ipc64_perm *in, struct kern_ipc_perm *out);
 struct kern_ipc_perm *ipcctl_pre_down(struct ipc_ids *ids, int id, int cmd,
 				      struct ipc64_perm *perm, int extra_perm);
 
-#if defined(__ia64__) || defined(__x86_64__) || defined(__hppa__) || defined(__XTENSA__)
+#ifndef __ARCH_WANT_IPC_PARSE_VERSION
   /* On IA-64, we always use the "64-bit version" of the IPC structures.  */ 
 # define ipc_parse_version(cmd)	IPC_64
 #else
Signature · 3 lines
1.6.0.4

--