Skip to contentSkip to conversation

unicore32 machine related files: hardware registers

PATCH In review Guan Xuetao 2 participants 10 messages Feb 16, 2011 – Feb 27, 2011 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 9/12 unicore32 machine related files: hardware registers

Message-Id: <6a0404f13ab84fd4c730ab718eed1561e56f8ba7.1297842537.git.gxt@mprc.pku.edu.cn>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: GuanXuetao <[email protected]>
Date: Sat, 15 Jan 2011 18:24:44 +0800

This patch adds all hardware registers definitions.

---
 arch/unicore32/include/mach/PKUnity.h     |  104 +++++++++++++
 arch/unicore32/include/mach/bitfield.h    |   24 +++
 arch/unicore32/include/mach/hardware.h    |   45 ++++++
 arch/unicore32/include/mach/regs-ac97.h   |   32 ++++
 arch/unicore32/include/mach/regs-dmac.h   |   81 ++++++++++
 arch/unicore32/include/mach/regs-gpio.h   |   70 +++++++++
 arch/unicore32/include/mach/regs-i2c.h    |   63 ++++++++
 arch/unicore32/include/mach/regs-intc.h   |   28 ++++
 arch/unicore32/include/mach/regs-nand.h   |   79 ++++++++++
 arch/unicore32/include/mach/regs-ost.h    |   92 ++++++++++++
 arch/unicore32/include/mach/regs-pci.h    |   94 ++++++++++++
 arch/unicore32/include/mach/regs-pm.h     |  126 ++++++++++++++++
 arch/unicore32/include/mach/regs-ps2.h    |   20 +++
 arch/unicore32/include/mach/regs-resetc.h |   34 +++++
 arch/unicore32/include/mach/regs-rtc.h    |   37 +++++
 arch/unicore32/include/mach/regs-sdc.h    |  156 ++++++++++++++++++++
 arch/unicore32/include/mach/regs-spi.h    |   98 ++++++++++++
 arch/unicore32/include/mach/regs-uart.h   |    3 +
 arch/unicore32/include/mach/regs-umal.h   |  229 +++++++++++++++++++++++++++++
 arch/unicore32/include/mach/regs-unigfx.h |  200 +++++++++++++++++++++++++
 20 files changed, 1615 insertions(+), 0 deletions(-)
 create mode 100644 arch/unicore32/include/mach/PKUnity.h
 create mode 100644 arch/unicore32/include/mach/bitfield.h
 create mode 100644 arch/unicore32/include/mach/hardware.h
 create mode 100644 arch/unicore32/include/mach/regs-ac97.h
 create mode 100644 arch/unicore32/include/mach/regs-dmac.h
 create mode 100644 arch/unicore32/include/mach/regs-gpio.h
 create mode 100644 arch/unicore32/include/mach/regs-i2c.h
 create mode 100644 arch/unicore32/include/mach/regs-intc.h
 create mode 100644 arch/unicore32/include/mach/regs-nand.h
 create mode 100644 arch/unicore32/include/mach/regs-ost.h
 create mode 100644 arch/unicore32/include/mach/regs-pci.h
 create mode 100644 arch/unicore32/include/mach/regs-pm.h
 create mode 100644 arch/unicore32/include/mach/regs-ps2.h
 create mode 100644 arch/unicore32/include/mach/regs-resetc.h
 create mode 100644 arch/unicore32/include/mach/regs-rtc.h
 create mode 100644 arch/unicore32/include/mach/regs-sdc.h
 create mode 100644 arch/unicore32/include/mach/regs-spi.h
 create mode 100644 arch/unicore32/include/mach/regs-uart.h
 create mode 100644 arch/unicore32/include/mach/regs-umal.h
 create mode 100644 arch/unicore32/include/mach/regs-unigfx.h
arch/unicore32/include/mach/PKUnity.h new file +104 -0
new file mode 100644
index 0000000..1e13208
@@ -0,0 +1,104 @@
+/*
+ * linux/arch/unicore32/include/mach/PKUnity.h
+ *
+ * Code specific to PKUnity SoC and UniCore ISA
+ *
+ * Copyright (C) 2001-2010 GUAN Xue-tao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+/* Be sure that virtual mapping is defined right */
+#ifndef __MACH_PUV3_HARDWARE_H__
+#error You must include hardware.h not PKUnity.h
+#endif
+
+#include "bitfield.h"
+
+/*
+ * Memory Definitions
+ */
+#define PKUNITY_SDRAM_BASE		0x00000000 /* 0x00000000 - 0x7FFFFFFF 2GB */
+#define PKUNITY_IOSPACE_BASE            0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */
+#define PKUNITY_PCI_BASE		0x80000000 /* 0x80000000 - 0xBFFFFFFF 1GB */
+#include "regs-pci.h"
+#define PKUNITY_BOOT_ROM2_BASE		0xF4000000 /* 0xF4000000 - 0xF7FFFFFF 64MB */
+#define PKUNITY_BOOT_SRAM2_BASE		0xF8000000 /* 0xF8000000 - 0xFBFFFFFF 64MB */
+#define PKUNITY_BOOT_FLASH_BASE		0xFC000000 /* 0xFC000000 - 0xFFFFFFFF 64MB */
+
+/*
+ * PKUNITY Memory Map Addresses: 0x03000000 - 0x03FFFFFF (16MB)
+ */
+#define PKUNITY_UVC_MMAP_BASE		0x02000000 /* 0x02000000 - 0x02FFFFFF 16MB */
+#define PKUNITY_UVC_MMAP_SIZE		0x01000000 /* 16MB */
+#define PKUNITY_UNIGFX_MMAP_BASE        0x03000000 /* 0x03000000 - 0x03FFFFFF 16MB */
+#define PKUNITY_UNIGFX_MMAP_SIZE        0x01000000 /* 16MB */
+
+/*
+ * PKUNITY System Bus Addresses (PCI): 0x80000000 - 0xBFFFFFFF (1GB)
+ */
+/* PCI Configuration regs */
+#define PKUNITY_PCICFG_BASE             0x80000000 /* 0x80000000 - 0x8000000B 12B */
+/* PCI Bridge Base */
+#define PKUNITY_PCIBRI_BASE             0x80010000 /* 0x80010000 - 0x80010250 592B */
+/* PCI Legacy IO */
+#define PKUNITY_PCILIO_BASE             0x80030000 /* 0x80030000 - 0x8003FFFF 64KB */
+/* PCI AHB-PCI MEM-mapping */
+#define PKUNITY_PCIMEM_BASE             0x90000000 /* 0x90000000 - 0x97FFFFFF 128MB */
+/* PCI PCI-AHB MEM-mapping */
+#define PKUNITY_PCIAHB_BASE             0x98000000 /* 0x98000000 - 0x9FFFFFFF 128MB */
+
+/*
+ * PKUNITY System Bus Addresses (AHB): 0xC0000000 - 0xEDFFFFFF (640MB)
+ */
+/* AHB-0 is DDR2 SDRAM */
+/* AHB-1 is PCI Space */
+#define PKUNITY_ARBITER_BASE		0xC0000000 /* AHB-2 */
+#define PKUNITY_DDR2CTRL_BASE		0xC0100000 /* AHB-3 */
+#define PKUNITY_DMAC_BASE		0xC0200000 /* AHB-4 */
+#include "regs-dmac.h"
+#define PKUNITY_UMAL_BASE		0xC0300000 /* AHB-5 */
+#include "regs-umal.h"
+#define PKUNITY_USB_BASE		0xC0400000 /* AHB-6 */
+#define PKUNITY_SATA_BASE		0xC0500000 /* AHB-7 */
+#define PKUNITY_SMC_BASE		0xC0600000 /* AHB-8 */
+/* AHB-9 is for APB bridge */
+#define PKUNITY_MME_BASE		0xC0700000 /* AHB-10 */
+#define PKUNITY_UNIGFX_BASE		0xC0800000 /* AHB-11 */
+#include "regs-unigfx.h"
+#define PKUNITY_NAND_BASE		0xC0900000 /* AHB-12 */
+#include "regs-nand.h"
+#define PKUNITY_H264D_BASE		0xC0A00000 /* AHB-13 */
+#define PKUNITY_H264E_BASE		0xC0B00000 /* AHB-14 */
+
+/*
+ * PKUNITY Peripheral Bus Addresses (APB): 0xEE000000 - 0xEFFFFFFF (128MB)
+ */
+#define PKUNITY_UART0_BASE		0xEE000000 /* APB-0 */
+#define PKUNITY_UART1_BASE		0xEE100000 /* APB-1 */
+#include "regs-uart.h"
+#define PKUNITY_I2C_BASE		0xEE200000 /* APB-2 */
+#include "regs-i2c.h"
+#define PKUNITY_SPI_BASE		0xEE300000 /* APB-3 */
+#include "regs-spi.h"
+#define PKUNITY_AC97_BASE		0xEE400000 /* APB-4 */
+#include "regs-ac97.h"
+#define PKUNITY_GPIO_BASE		0xEE500000 /* APB-5 */
+#include "regs-gpio.h"
+#define PKUNITY_INTC_BASE		0xEE600000 /* APB-6 */
+#include "regs-intc.h"
+#define PKUNITY_RTC_BASE		0xEE700000 /* APB-7 */
+#include "regs-rtc.h"
+#define PKUNITY_OST_BASE		0xEE800000 /* APB-8 */
+#include "regs-ost.h"
+#define PKUNITY_RESETC_BASE		0xEE900000 /* APB-9 */
+#include "regs-resetc.h"
+#define PKUNITY_PM_BASE			0xEEA00000 /* APB-10 */
+#include "regs-pm.h"
+#define PKUNITY_PS2_BASE		0xEEB00000 /* APB-11 */
+#include "regs-ps2.h"
+#define PKUNITY_SDC_BASE		0xEEC00000 /* APB-12 */
+#include "regs-sdc.h"
+
arch/unicore32/include/mach/bitfield.h new file +24 -0
new file mode 100644
index 0000000..128a702
@@ -0,0 +1,24 @@
+/*
+ * linux/arch/unicore32/include/mach/bitfield.h
+ *
+ * Code specific to PKUnity SoC and UniCore ISA
+ *
+ * Copyright (C) 2001-2010 GUAN Xue-tao
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __MACH_PUV3_BITFIELD_H__
+#define __MACH_PUV3_BITFIELD_H__
+
+#ifndef __ASSEMBLY__
+#define UData(Data)	((unsigned long) (Data))
+#else
+#define UData(Data)	(Data)
+#endif
+
+#define FIELD(val, vmask, vshift)	(((val) & ((UData(1) << (vmask)) - 1)) << (vshift))
+#define FMASK(vmask, vshift)		(((UData(1) << (vmask)) - 1) << (vshift))
+
+#endif /* __MACH_PUV3_BITFIELD_H__ */
arch/unicore32/include/mach/hardware.h new file +45 -0

45 lines not on this page · raw message

arch/unicore32/include/mach/regs-ac97.h new file +32 -0
new file mode 100644
index 0000000..ce299bf
@@ -0,0 +1,32 @@
+/*
+ * PKUnity AC97 Registers
+ */
+
+#define PKUNITY_AC97_CONR		__REG(PKUNITY_AC97_BASE + 0x0000)
+#define PKUNITY_AC97_OCR		__REG(PKUNITY_AC97_BASE + 0x0004)
+#define PKUNITY_AC97_ICR		__REG(PKUNITY_AC97_BASE + 0x0008)
+#define PKUNITY_AC97_CRAC		__REG(PKUNITY_AC97_BASE + 0x000C)
+#define PKUNITY_AC97_INTR		__REG(PKUNITY_AC97_BASE + 0x0010)
+#define PKUNITY_AC97_INTRSTAT		__REG(PKUNITY_AC97_BASE + 0x0014)
+#define PKUNITY_AC97_INTRCLEAR		__REG(PKUNITY_AC97_BASE + 0x0018)
+#define PKUNITY_AC97_ENABLE		__REG(PKUNITY_AC97_BASE + 0x001C)
+#define PKUNITY_AC97_OUT_FIFO		__REG(PKUNITY_AC97_BASE + 0x0020)
+#define PKUNITY_AC97_IN_FIFO		__REG(PKUNITY_AC97_BASE + 0x0030)
+
+#define AC97_CODEC_REG(v)               FIELD((v), 7, 16)
+#define AC97_CODEC_VAL(v)               FIELD((v), 16, 0)
+#define AC97_CODEC_WRITECOMPLETE        FIELD(1, 1, 2)
+
+/*
+ * VAR PLAY SAMPLE RATE
+ */
+#define AC97_CMD_VPSAMPLE		(FIELD(3, 2, 16) | FIELD(3, 2, 0))
+
+/*
+ * FIX CAPTURE SAMPLE RATE
+ */
+#define AC97_CMD_FCSAMPLE		FIELD(7, 3, 0)
+
+#define AC97_CMD_RESET			FIELD(1, 1, 0)
+#define AC97_CMD_ENABLE			FIELD(1, 1, 0)
+#define AC97_CMD_DISABLE		FIELD(0, 1, 0)
arch/unicore32/include/mach/regs-dmac.h new file +81 -0

81 lines not on this page · raw message

arch/unicore32/include/mach/regs-gpio.h new file +70 -0

70 lines not on this page · raw message

arch/unicore32/include/mach/regs-i2c.h new file +63 -0

63 lines not on this page · raw message

arch/unicore32/include/mach/regs-intc.h new file +28 -0
new file mode 100644
index 0000000..409ae47
@@ -0,0 +1,28 @@
+/*
+ * PKUNITY Interrupt Controller (INTC) Registers
+ */
+/*
+ * INTC Level Reg INTC_ICLR.
+ */
+#define INTC_ICLR	__REG(PKUNITY_INTC_BASE + 0x0000)
+/*
+ * INTC Mask Reg INTC_ICMR.
+ */
+#define INTC_ICMR	__REG(PKUNITY_INTC_BASE + 0x0004)
+/*
+ * INTC Pending Reg INTC_ICPR.
+ */
+#define INTC_ICPR	__REG(PKUNITY_INTC_BASE + 0x0008)
+/*
+ * INTC IRQ Pending Reg INTC_ICIP.
+ */
+#define INTC_ICIP	__REG(PKUNITY_INTC_BASE + 0x000C)
+/*
+ * INTC REAL Pending Reg INTC_ICFP.
+ */
+#define INTC_ICFP	__REG(PKUNITY_INTC_BASE + 0x0010)
+/*
+ * INTC Control Reg INTC_ICCR.
+ */
+#define INTC_ICCR	__REG(PKUNITY_INTC_BASE + 0x0014)
+
arch/unicore32/include/mach/regs-nand.h new file +79 -0

79 lines not on this page · raw message

arch/unicore32/include/mach/regs-ost.h new file +92 -0

92 lines not on this page · raw message

arch/unicore32/include/mach/regs-pci.h new file +94 -0

94 lines not on this page · raw message

arch/unicore32/include/mach/regs-pm.h new file +126 -0

126 lines not on this page · raw message

arch/unicore32/include/mach/regs-ps2.h new file +20 -0
new file mode 100644
index 0000000..7da2071
@@ -0,0 +1,20 @@
+/*
+ * PKUnity PS2 Controller Registers
+ */
+/*
+ * the same as I8042_DATA_REG PS2_DATA
+ */
+#define PS2_DATA	__REG(PKUNITY_PS2_BASE + 0x0060)
+/*
+ * the same as I8042_COMMAND_REG PS2_COMMAND
+ */
+#define PS2_COMMAND	__REG(PKUNITY_PS2_BASE + 0x0064)
+/*
+ * the same as I8042_STATUS_REG PS2_STATUS
+ */
+#define PS2_STATUS	__REG(PKUNITY_PS2_BASE + 0x0064)
+/*
+ * counter reg PS2_CNT
+ */
+#define PS2_CNT		__REG(PKUNITY_PS2_BASE + 0x0068)
+
arch/unicore32/include/mach/regs-resetc.h new file +34 -0
new file mode 100644
index 0000000..1763989
@@ -0,0 +1,34 @@
+/*
+ * PKUnity Reset Controller (RC) Registers
+ */
+/*
+ * Software Reset Register
+ */
+#define RESETC_SWRR	__REG(PKUNITY_RESETC_BASE + 0x0000)
+/*
+ * Reset Status Register
+ */
+#define RESETC_RSSR	__REG(PKUNITY_RESETC_BASE + 0x0004)
+
+/*
+ * Software Reset Bit
+ */
+#define RESETC_SWRR_SRB		FIELD(1, 1, 0)
+
+/*
+ * Hardware Reset
+ */
+#define RESETC_RSSR_HWR		FIELD(1, 1, 0)
+/*
+ * Software Reset
+ */
+#define RESETC_RSSR_SWR		FIELD(1, 1, 1)
+/*
+ * Watchdog Reset
+ */
+#define RESETC_RSSR_WDR		FIELD(1, 1, 2)
+/*
+ * Sleep Mode Reset
+ */
+#define RESETC_RSSR_SMR		FIELD(1, 1, 3)
+
arch/unicore32/include/mach/regs-rtc.h new file +37 -0
new file mode 100644
index 0000000..155e387
@@ -0,0 +1,37 @@
+/*
+ * PKUnity Real-Time Clock (RTC) control registers
+ */
+/*
+ * RTC Alarm Reg RTC_RTAR
+ */
+#define RTC_RTAR	__REG(PKUNITY_RTC_BASE + 0x0000)
+/*
+ * RTC Count Reg RTC_RCNR
+ */
+#define RTC_RCNR	__REG(PKUNITY_RTC_BASE + 0x0004)
+/*
+ * RTC Trim Reg RTC_RTTR
+ */
+#define RTC_RTTR	__REG(PKUNITY_RTC_BASE + 0x0008)
+/*
+ * RTC Status Reg RTC_RTSR
+ */
+#define RTC_RTSR	__REG(PKUNITY_RTC_BASE + 0x0010)
+
+/*
+ * ALarm detected RTC_RTSR_AL
+ */
+#define RTC_RTSR_AL		FIELD(1, 1, 0)
+/*
+ * 1 Hz clock detected RTC_RTSR_HZ
+ */
+#define RTC_RTSR_HZ		FIELD(1, 1, 1)
+/*
+ * ALarm interrupt Enable RTC_RTSR_ALE
+ */
+#define RTC_RTSR_ALE		FIELD(1, 1, 2)
+/*
+ * 1 Hz clock interrupt Enable RTC_RTSR_HZE
+ */
+#define RTC_RTSR_HZE		FIELD(1, 1, 3)
+
arch/unicore32/include/mach/regs-sdc.h new file +156 -0

156 lines not on this page · raw message

arch/unicore32/include/mach/regs-spi.h new file +98 -0

98 lines not on this page · raw message

arch/unicore32/include/mach/regs-uart.h new file +3 -0
new file mode 100644
index 0000000..9fa6b19
@@ -0,0 +1,3 @@
+/*
+ * PKUnity Universal Asynchronous Receiver/Transmitter (UART) Registers
+ */
arch/unicore32/include/mach/regs-umal.h new file +229 -0

229 lines not on this page · raw message

arch/unicore32/include/mach/regs-unigfx.h new file +200 -0

200 lines not on this page · raw message

Signature · 1 line
1.6.2.2
maintainer
#1 lore raw
Quoted 13 lines · Guan Xuetao
arch/unicore32/include/mach/hardware.h new file +12 -0
+#define io_p2v(x)      ((x) - PKUNITY_IOSPACE_BASE)
+#define io_v2p(x)      ((x) + PKUNITY_IOSPACE_BASE)
+
+#ifndef __ASSEMBLY__
+
+# define __REG(x)      (*((volatile unsigned long *)io_p2v(x)))
+# define __PREG(x)     (io_v2p((unsigned long)&(x)))
+
+#else
+
+# define __REG(x)      io_p2v(x)
+# define __PREG(x)     io_v2p(x)
Quoted 1 line

#define PKUNITY_IOSPACE_BASE 0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */

The typecasts look wrong here:

- "volatile unsigned long*" is not the right pointer type to do I/O on. It should instead be "void __iomem *". Please use the "sparse" tool with "make C=1" to get warnings about incorrect pointer type accesses.

- PKUNITY_IOSPACE_BASE seems to be both a virtual and a physical address, which is a bad idea, because it prevents a lot of the checks from working correctly.

- The __REG/__PREG macros seem to have the same purpose as io_p2v/io_v2p, you should not require both.

- The term IOSPACE is confusing, because it normally refers to the PCI PIO space, while you mean the SoC's MMIO region

I would recommend defining these as

#ifndef __ASSEMBLY__
#define PKUNITY_MMIO_VIRT ((void __iomem *)0x80000000) #else
#define PKUNITY_MMIO_VIRT 0x80000000
#endif

#define io_p2v(x) ((x) - PKUNITY_MMIO_VIRT)
#define io_v2p(x) ((x) + PKUNITY_MMIO_VIRT)

/* please remove the two macros below as soon as all users are changed to use io_p2v */ #define __REG(x) io_p2v(x)
#define __PREG(x) io_v2p(x)

Arnd

#2 lore raw
Quoted 23 lines

-----Original Message-----
From: Arnd Bergmann [mailto:[email protected]]
Sent: Friday, February 18, 2011 1:00 AM
To: Guan Xuetao
Cc: [email protected]; [email protected]; 'Greg KH'
Subject: Re: [PATCH 09/12] unicore32 machine related files: hardware registers

Quoted 12 lines · Guan Xuetao
(quoted diff) +12 -0
+#define io_p2v(x)      ((x) - PKUNITY_IOSPACE_BASE)
+#define io_v2p(x)      ((x) + PKUNITY_IOSPACE_BASE)
+
+#ifndef __ASSEMBLY__
+
+# define __REG(x)      (*((volatile unsigned long *)io_p2v(x)))
+# define __PREG(x)     (io_v2p((unsigned long)&(x)))
+
+#else
+
+# define __REG(x)      io_p2v(x)
+# define __PREG(x)     io_v2p(x)
Quoted 7 lines
Quoted 1 line

#define PKUNITY_IOSPACE_BASE 0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */

The typecasts look wrong here:

- "volatile unsigned long*" is not the right pointer type to do I/O on. It should instead be "void __iomem *". Please use the "sparse" tool with "make C=1" to get warnings about incorrect pointer type accesses.

__REG() macro could be used in both left and right sides of assignment sentence. This idea is borrowed from arm/sa1100.
When used in left side, __REG is a register port, and when used in right side, __REG is just the value of the register.
It is a trick, but very useful. I'd like to remain the macros.

Quoted 3 lines

- PKUNITY_IOSPACE_BASE seems to be both a virtual and a physical address, which is a bad idea, because it prevents a lot of the checks from working correctly.

PKUNITY_IOSPACE_BASE is only used for physical-virtual address transformation. (void *) prefix will introduce type cast error.
In addition, in unicore32, io space and memory space are all in the same 4G address space, but only different in address range.

Quoted 6 lines

- The __REG/__PREG macros seem to have the same purpose as io_p2v/io_v2p, you should not require both.

- The term IOSPACE is confusing, because it normally refers to the PCI PIO space, while you mean the SoC's MMIO region

Ok, renamed to PKUNITY_MMIO_BASE.

Quoted 9 lines

I would recommend defining these as

#ifndef __ASSEMBLY__
#define PKUNITY_MMIO_VIRT ((void __iomem *)0x80000000) #else
#define PKUNITY_MMIO_VIRT 0x80000000
#endif

Quoted 6 lines

#define io_p2v(x) ((x) - PKUNITY_MMIO_VIRT)
#define io_v2p(x) ((x) + PKUNITY_MMIO_VIRT)

/* please remove the two macros below as soon as all users are changed to use io_p2v */ #define __REG(x) io_p2v(x)
#define __PREG(x) io_v2p(x)

For the reason above, I can only apply the patch as following:

From: GuanXuetao <[email protected]>
Date: Fri, 18 Feb 2011 18:05:23 +0800
Subject: [PATCH] unicore32: rename PKUNITY_IOSPACE_BASE to PKUNITY_MMIO_BASE
for the term IOSPACE normally refers to the PCI PIO space, and remove unused __REG/__PREG macros when __ASSEMBLY__ defined -- by advice with Arnd Bergmann

---
 arch/unicore32/include/mach/PKUnity.h  |    2 +-
 arch/unicore32/include/mach/hardware.h |    9 ++-------
 2 files changed, 3 insertions(+), 8 deletions(-)
arch/unicore32/include/mach/PKUnity.h +1 -1
index 1e13208..39f27f4 100644
@@ -21,7 +21,7 @@
  * Memory Definitions
  */
 #define PKUNITY_SDRAM_BASE		0x00000000 /* 0x00000000 - 0x7FFFFFFF 2GB */
-#define PKUNITY_IOSPACE_BASE            0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */
+#define PKUNITY_MMIO_BASE		0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */
 #define PKUNITY_PCI_BASE		0x80000000 /* 0x80000000 - 0xBFFFFFFF 1GB */
 #include "regs-pci.h"
 #define PKUNITY_BOOT_ROM2_BASE		0xF4000000 /* 0xF4000000 - 0xF7FFFFFF 64MB */
arch/unicore32/include/mach/hardware.h +2 -7
index 3fb7236..ebce7de 100644
@@ -17,19 +17,14 @@
 
 #include "PKUnity.h"
 
-#define io_p2v(x)	((x) - PKUNITY_IOSPACE_BASE)
-#define io_v2p(x)	((x) + PKUNITY_IOSPACE_BASE)
+#define io_p2v(x)	((x) - PKUNITY_MMIO_BASE)
+#define io_v2p(x)	((x) + PKUNITY_MMIO_BASE)
 
 #ifndef __ASSEMBLY__
 
 # define __REG(x)	(*((volatile unsigned long *)io_p2v(x)))
 # define __PREG(x)	(io_v2p((unsigned long)&(x)))
 
-#else
-
-# define __REG(x)	io_p2v(x)
-# define __PREG(x)	io_v2p(x)
-
 #endif
 
 #define PCIBIOS_MIN_IO			0x4000 /* should lower than 64KB */
Signature · 1 line
1.6.2.2
Quoted 2 lines

Arnd

Thanks & Regards.

Guan Xuetao

maintainer
#3 lore raw
Quoted 21 lines · On Friday 18 February 2011 10:52:12 Guan Xuetao wrote:
Quoted 14 lines · Guan Xuetao
Quoted 12 lines
(quoted diff) +12 -0
+#define io_p2v(x)      ((x) - PKUNITY_IOSPACE_BASE)
+#define io_v2p(x)      ((x) + PKUNITY_IOSPACE_BASE)
+
+#ifndef __ASSEMBLY__
+
+# define __REG(x)      (*((volatile unsigned long *)io_p2v(x)))
+# define __PREG(x)     (io_v2p((unsigned long)&(x)))
+
+#else
+
+# define __REG(x)      io_p2v(x)
+# define __PREG(x)     io_v2p(x)
Quoted 7 lines
Quoted 1 line

#define PKUNITY_IOSPACE_BASE 0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */

The typecasts look wrong here:

- "volatile unsigned long*" is not the right pointer type to do I/O on. It should instead be "void __iomem *". Please use the "sparse" tool with "make C=1" to get warnings about incorrect pointer type accesses.

Quoted 6 lines

__REG() macro could be used in both left and right sides of assignment sentence. This idea is borrowed from arm/sa1100.

When used in left side, __REG is a register port, and when used in right side, __REG is just the value of the register.
It is a trick, but very useful. I'd like to remain the macros.

Ok, I didn't realize this. However, this is a really bad idea and I would strongly advise removing this throughout the code.

The only way we do MMIO accesses in Linux is through the readl()/writel() functions. On many architectures, these contain more than just a pointer dereference, and if you need that, you can change it in just one place.

Things that can go wrong with volatile pointer dereferences include:

* compiler turns 32 bit access into four 8-bit accesses
* I/O bus reorders access and it moves outside of a spinlock
* non-volatile accesses to system RAM get reordered around MMIO access, which may break if the MMIO triggers a DMA.

arch/unicore32/include/mach/PKUnity.h line 27

Quoted 13 lines
arch/unicore32/include/mach/PKUnity.h +1 -1
index 1e13208..39f27f4 100644
@@ -21,7 +21,7 @@
  * Memory Definitions
  */
 #define PKUNITY_SDRAM_BASE		0x00000000 /* 0x00000000 - 0x7FFFFFFF 2GB */
-#define PKUNITY_IOSPACE_BASE            0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */
+#define PKUNITY_MMIO_BASE		0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */
 #define PKUNITY_PCI_BASE		0x80000000 /* 0x80000000 - 0xBFFFFFFF 1GB */
 #include "regs-pci.h"
 #define PKUNITY_BOOT_ROM2_BASE		0xF4000000 /* 0xF4000000 - 0xF7FFFFFF 64MB */

This change is ok.

Quoted 5 lines
arch/unicore32/include/mach/hardware.h +0 -0
index 3fb7236..ebce7de 100644

arch/unicore32/include/mach/hardware.h line 23

Quoted 9 lines
arch/unicore32/include/mach/hardware.h +2 -2
@@ -17,19 +17,14 @@
 
 #include "PKUnity.h"
 
-#define io_p2v(x)	((x) - PKUNITY_IOSPACE_BASE)
-#define io_v2p(x)	((x) + PKUNITY_IOSPACE_BASE)
+#define io_p2v(x)	((x) - PKUNITY_MMIO_BASE)
+#define io_v2p(x)	((x) + PKUNITY_MMIO_BASE)
 
 #ifndef __ASSEMBLY__

The result of io_p2v really needs to be a (void __iomem *) pointer, not an integer, so the accesses can work.

arch/unicore32/include/mach/hardware.h line 26

Quoted 2 lines
arch/unicore32/include/mach/hardware.h +0 -0
 # define __REG(x)	(*((volatile unsigned long *)io_p2v(x)))
 # define __PREG(x)	(io_v2p((unsigned long)&(x)))

And as explained, these should be removed and all users converted to use readl()/writel().

Arnd

#4 lore raw
Quoted 88 lines

-----Original Message-----
From: Arnd Bergmann [mailto:[email protected]]
Sent: Friday, February 18, 2011 6:43 PM
To: Guan Xuetao
Cc: [email protected]; [email protected]; 'Greg KH'
Subject: Re: [PATCH 09/12] unicore32 machine related files: hardware registers

Quoted 21 lines · On Friday 18 February 2011 10:52:12 Guan Xuetao wrote:
Quoted 14 lines · Guan Xuetao
Quoted 12 lines
(quoted diff) +12 -0
+#define io_p2v(x)      ((x) - PKUNITY_IOSPACE_BASE)
+#define io_v2p(x)      ((x) + PKUNITY_IOSPACE_BASE)
+
+#ifndef __ASSEMBLY__
+
+# define __REG(x)      (*((volatile unsigned long *)io_p2v(x)))
+# define __PREG(x)     (io_v2p((unsigned long)&(x)))
+
+#else
+
+# define __REG(x)      io_p2v(x)
+# define __PREG(x)     io_v2p(x)
Quoted 7 lines
Quoted 1 line

#define PKUNITY_IOSPACE_BASE 0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */

The typecasts look wrong here:

- "volatile unsigned long*" is not the right pointer type to do I/O on. It should instead be "void __iomem *". Please use the "sparse" tool with "make C=1" to get warnings about incorrect pointer type accesses.

Quoted 6 lines

__REG() macro could be used in both left and right sides of assignment sentence. This idea is borrowed from arm/sa1100.

When used in left side, __REG is a register port, and when used in right side, __REG is just the value of the register.
It is a trick, but very useful. I'd like to remain the macros.

Ok, I didn't realize this. However, this is a really bad idea and I would strongly advise removing this throughout the code.

The only way we do MMIO accesses in Linux is through the readl()/writel() functions. On many architectures, these contain more than just a pointer dereference, and if you need that, you can change it in just one place.

Things that can go wrong with volatile pointer dereferences include:

* compiler turns 32 bit access into four 8-bit accesses
* I/O bus reorders access and it moves outside of a spinlock
* non-volatile accesses to system RAM get reordered around MMIO access, which may break if the MMIO triggers a DMA.

arch/unicore32/include/mach/PKUnity.h line 27

Quoted 13 lines
arch/unicore32/include/mach/PKUnity.h +1 -1
index 1e13208..39f27f4 100644
@@ -21,7 +21,7 @@
  * Memory Definitions
  */
 #define PKUNITY_SDRAM_BASE		0x00000000 /* 0x00000000 - 0x7FFFFFFF 2GB */
-#define PKUNITY_IOSPACE_BASE            0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */
+#define PKUNITY_MMIO_BASE		0x80000000 /* 0x80000000 - 0xFFFFFFFF 2GB */
 #define PKUNITY_PCI_BASE		0x80000000 /* 0x80000000 - 0xBFFFFFFF 1GB */
 #include "regs-pci.h"
 #define PKUNITY_BOOT_ROM2_BASE		0xF4000000 /* 0xF4000000 - 0xF7FFFFFF 64MB */

This change is ok.

Quoted 5 lines
arch/unicore32/include/mach/hardware.h +0 -0
index 3fb7236..ebce7de 100644

arch/unicore32/include/mach/hardware.h line 23

Quoted 9 lines
arch/unicore32/include/mach/hardware.h +2 -2
@@ -17,19 +17,14 @@
 
 #include "PKUnity.h"
 
-#define io_p2v(x)	((x) - PKUNITY_IOSPACE_BASE)
-#define io_v2p(x)	((x) + PKUNITY_IOSPACE_BASE)
+#define io_p2v(x)	((x) - PKUNITY_MMIO_BASE)
+#define io_v2p(x)	((x) + PKUNITY_MMIO_BASE)
 
 #ifndef __ASSEMBLY__

The result of io_p2v really needs to be a (void __iomem *) pointer, not an integer, so the accesses can work.

Quoted 5 lines

arch/unicore32/include/mach/hardware.h line 25

Quoted 2 lines
arch/unicore32/include/mach/hardware.h +0 -0
 # define __REG(x)	(*((volatile unsigned long *)io_p2v(x)))
 # define __PREG(x)	(io_v2p((unsigned long)&(x)))

And as explained, these should be removed and all users converted to use readl()/writel().

I see.
I apply the patch as following:
arch/unicore32/include/mach/hardware.h | 3 +--

 1 files changed, 1 insertions(+), 2 deletions(-)
arch/unicore32/include/mach/hardware.h +1 -2
index ebce7de..b71405a 100644
@@ -22,8 +22,7 @@
 
 #ifndef __ASSEMBLY__
 
-# define __REG(x)	(*((volatile unsigned long *)io_p2v(x)))
-# define __PREG(x)	(io_v2p((unsigned long)&(x)))
+# define __REG(x)	(void __iomem *)io_p2v(x)
 
 #endif
 

---
__REG reserved only for all registers prefix. And all using for __REG converted to readl/writel.

Quoted 2 lines

Arnd

Thanks Arnd

Guan Xuetao

maintainer
#5 lore raw
Quoted 16 lines · Guan Xuetao
Quoted 6 lines
Quoted 6 lines
arch/unicore32/include/mach/hardware.h +0 -0
index 3fb7236..ebce7de 100644
@@ -17,19 +17,14 @@
 
Quoted 7 lines

arch/unicore32/include/mach/hardware.h line 22

Quoted 7 lines
arch/unicore32/include/mach/hardware.h +2 -2
 #include "PKUnity.h"
 
-#define io_p2v(x)  ((x) - PKUNITY_IOSPACE_BASE)
-#define io_v2p(x)  ((x) + PKUNITY_IOSPACE_BASE)
+#define io_p2v(x)  ((x) - PKUNITY_MMIO_BASE)
+#define io_v2p(x)  ((x) + PKUNITY_MMIO_BASE)
 

I apply the patch as following:

arch/unicore32/include/mach/hardware.h line 25

Quoted 6 lines
arch/unicore32/include/mach/hardware.h +1 -2
@@ -22,8 +22,7 @@
 
 #ifndef __ASSEMBLY__
 
-# define __REG(x)      (*((volatile unsigned long *)io_p2v(x)))
-# define __PREG(x)     (io_v2p((unsigned long)&(x)))
+# define __REG(x)      (void __iomem *)io_p2v(x)

The patch looks correct, but if you make the the definition for PKUNITY_MMIO_BASE contain the cast to (void __iomem *), you no longer need another cast.

Quoted 2 lines

__REG reserved only for all registers prefix. And all using for __REG converted to readl/writel.

Fair enough.

Arnd

#6 lore raw
Quoted 29 lines

-----Original Message-----
From: Arnd Bergmann [mailto:[email protected]]
Sent: Tuesday, February 22, 2011 10:19 PM
To: Guan Xuetao
Cc: [email protected]; [email protected]; 'Greg KH'
Subject: Re: [PATCH 09/12] unicore32 machine related files: hardware registers

Quoted 19 lines · Guan Xuetao
Quoted 6 lines
Quoted 6 lines
arch/unicore32/include/mach/hardware.h +0 -0
index 3fb7236..ebce7de 100644
@@ -17,19 +17,14 @@
 
Quoted 7 lines

arch/unicore32/include/mach/hardware.h line 22

Quoted 7 lines
arch/unicore32/include/mach/hardware.h +2 -2
 #include "PKUnity.h"
 
-#define io_p2v(x)  ((x) - PKUNITY_IOSPACE_BASE)
-#define io_v2p(x)  ((x) + PKUNITY_IOSPACE_BASE)
+#define io_p2v(x)  ((x) - PKUNITY_MMIO_BASE)
+#define io_v2p(x)  ((x) + PKUNITY_MMIO_BASE)
 

I apply the patch as following:

arch/unicore32/include/mach/hardware.h +0 -0
@@ -22,8 +22,7 @@
 
 #ifndef __ASSEMBLY__
 
Quoted 7 lines

arch/unicore32/include/mach/hardware.h line 25

Quoted 3 lines
arch/unicore32/include/mach/hardware.h +1 -2
-# define __REG(x)      (*((volatile unsigned long *)io_p2v(x)))
-# define __PREG(x)     (io_v2p((unsigned long)&(x)))
+# define __REG(x)      (void __iomem *)io_p2v(x)

The patch looks correct, but if you make the the definition for PKUNITY_MMIO_BASE contain the cast to (void __iomem *), you no longer need another cast.

Because the io_p2v(x) calculate x and PKUNITY_IOSPACE_BASE, all registers should be added with (void __iomem *). So I prefer to remain the previous patch.

Quoted 7 lines
Quoted 3 lines

__REG reserved only for all registers prefix. And all using for __REG converted to readl/writel.

Fair enough.

Arnd

maintainer
#7 lore raw
Quoted 10 lines · Guan Xuetao
Quoted 9 lines

arch/unicore32/include/mach/hardware.h line 25

Quoted 5 lines

#ifndef __ASSEMBLY__

arch/unicore32/include/mach/hardware.h +1 -2
-# define __REG(x)      (*((volatile unsigned long *)io_p2v(x)))
-# define __PREG(x)     (io_v2p((unsigned long)&(x)))
+# define __REG(x)      (void __iomem *)io_p2v(x)

The patch looks correct, but if you make the the definition for PKUNITY_MMIO_BASE contain the cast to (void __iomem *), you no longer need another cast.

Quoted 3 lines

Because the io_p2v(x) calculate x and PKUNITY_IOSPACE_BASE, all registers should be added with (void __iomem *). So I prefer to remain the previous patch.

The problem with the definition of io_p2v is that it gives you an type that is impossible to use correctly, except in assembly code. Linux assumes that MMIO registers in virtual space are __iomem pointers, and we like that to be consistent.

If you have a function that returns a virtual address, it should really have the same type as any other function that uses a virtual address.

Arnd

#8 lore raw
Quoted 24 lines

-----Original Message-----
From: Arnd Bergmann [mailto:[email protected]]
Sent: Saturday, February 26, 2011 9:16 PM
To: Guan Xuetao
Cc: [email protected]; [email protected]; 'Greg KH'
Subject: Re: [PATCH 09/12] unicore32 machine related files: hardware registers

Quoted 10 lines · Guan Xuetao
Quoted 9 lines

Review

Quoted 5 lines

#ifndef __ASSEMBLY__

(quoted diff) +1 -2
-# define __REG(x)      (*((volatile unsigned long *)io_p2v(x)))
-# define __PREG(x)     (io_v2p((unsigned long)&(x)))
+# define __REG(x)      (void __iomem *)io_p2v(x)

The patch looks correct, but if you make the the definition for PKUNITY_MMIO_BASE contain the cast to (void __iomem *), you no longer need another cast.

Quoted 3 lines

Because the io_p2v(x) calculate x and PKUNITY_IOSPACE_BASE, all registers should be added with (void __iomem *). So I prefer to remain the previous patch.

Quoted 8 lines

The problem with the definition of io_p2v is that it gives you an type that is impossible to use correctly, except in assembly code. Linux assumes that MMIO registers in virtual space are __iomem pointers, and we like that to be consistent.

If you have a function that returns a virtual address, it should really have the same type as any other function that uses a virtual address.

Ok, I see.
Please see following patch, __REG removed and __iomem added to io_p2v:

arch/unicore32/include/mach/hardware.h +3 -6
index b71405a..b197b0b 100644
@@ -17,13 +17,10 @@
 
 #include "PKUnity.h"
 
-#define io_p2v(x)	((x) - PKUNITY_MMIO_BASE)
-#define io_v2p(x)	((x) + PKUNITY_MMIO_BASE)
-
 #ifndef __ASSEMBLY__
-
-# define __REG(x)	(void __iomem *)io_p2v(x)
-
+#define io_p2v(x)	(void __iomem *)((x) - PKUNITY_MMIO_BASE)
+#else
+#define io_p2v(x)	((x) - PKUNITY_MMIO_BASE)
 #endif
 
 #define PCIBIOS_MIN_IO			0x4000 /* should lower than 64KB */
Quoted 2 lines

Arnd

Thanks & Regards.
Guan Xuetao

maintainer Acked-by
#9 lore raw
Quoted 13 lines · Guan Xuetao

Please see following patch, __REG removed and __iomem added to io_p2v:

arch/unicore32/include/mach/hardware.h +0 -3
index b71405a..b197b0b 100644
@@ -17,13 +17,10 @@
 
 #include "PKUnity.h"
 
-#define io_p2v(x)      ((x) - PKUNITY_MMIO_BASE)
-#define io_v2p(x)      ((x) + PKUNITY_MMIO_BASE)
-

arch/unicore32/include/mach/hardware.h line 26

Quoted 10 lines
arch/unicore32/include/mach/hardware.h +3 -3
 #ifndef __ASSEMBLY__
-
-# define __REG(x)      (void __iomem *)io_p2v(x)
-
+#define io_p2v(x)      (void __iomem *)((x) - PKUNITY_MMIO_BASE)
+#else
+#define io_p2v(x)      ((x) - PKUNITY_MMIO_BASE)
 #endif
 
 #define PCIBIOS_MIN_IO                 0x4000 /* should lower than 64KB */

Yes, looks good!