Freescale mxs/imx23 + Olimex Olinuxino support
PATCH 3/13 mxs/imx23: Add uart driver
In reply to Michel PolletPrototype driver for the mxs/imx23 uart IO block. This has no real 'uart' functional code, apart from letting itself be initialized by linux without generating a timeout error.
--- hw/char/Makefile.objs | 1 + hw/char/mxs_uart.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 hw/char/mxs_uart.c
hw/char/Makefile.objs +1 -0
@@ -19,6 +19,7 @@ common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o common-obj-$(CONFIG_ISA_DEBUG) += debugcon.o common-obj-$(CONFIG_GRLIB) += grlib_apbuart.o common-obj-$(CONFIG_IMX) += imx_serial.o +common-obj-$(CONFIG_MXS) += mxs_uart.o common-obj-$(CONFIG_LM32) += lm32_juart.o common-obj-$(CONFIG_LM32) += lm32_uart.o common-obj-$(CONFIG_MILKYMIST) += milkymist-uart.o
hw/char/mxs_uart.c new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
1.8.5.1
cover Freescale mxs/imx23 + Olimex Olinuxino support
This series adds support for the imx233 SoC, and also adds support for emulating an Olinux Olinuxino board with a few peripherals, as a test harness. The emulation works pretty well, boots linux 3.12 vanilla from an emulated SD card, has USB bridge support (but no support for USB 1.1 devices like mouse+keyboard), RTC and quite a few other bits (some of them fairly skeletal)
This series has been in used for quite a few months; it was posted here a few month back and one of the question was to wether I would stick around to support it. Perhaps the fact that I reworked it all on trunk and reposted it will help answer this question.
This patch series is also available on this github branch, in case its' more convenient to use the inline comment function there.
https://github.com/buserror-uk/qemu-buserror/commits/dev-imx233
Michel Pollet (13):
mxs/imx23: Add main header file
mxs: Add CONFIG_MXS to the arm-softmmu config mxs/imx23: Add uart driver
mxs/imx23: Add DMA driver
mxs/imx23: Add the interrupt collector mxs/imx23: Add digctl driver
mxs/imx23: Implements the pin mux, GPIOs mxs/imx23: Add SSP/SPI driver
mxs/imx23: Add the RTC block
mxs/imx23: Add the timers
mxs/imx23: Add the USB driver
mxs/imx23: Main core instantiation and minor IO blocks mxs/imx23: Adds support for an Olinuxino board
default-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 2 + hw/arm/imx233-olinuxino.c | 169 +++++++++++++++++ hw/arm/imx23_digctl.c | 110 ++++++++++++ hw/arm/imx23_pinctrl.c | 293 ++++++++++++++++++++++++++++++ hw/arm/mxs.c | 388 ++++++++++++++++++++++++++++++++++++++++ hw/arm/mxs.h | 208 +++++++++++++++++++++ hw/char/Makefile.objs | 1 + hw/char/mxs_uart.c | 146 +++++++++++++++ hw/dma/Makefile.objs | 1 + hw/dma/mxs_dma.c | 347 +++++++++++++++++++++++++++++++++++ hw/intc/Makefile.objs | 1 + hw/intc/mxs_icoll.c | 200 +++++++++++++++++++++ hw/ssi/Makefile.objs | 1 + hw/ssi/mxs_spi.c | 239 +++++++++++++++++++++++++ hw/timer/Makefile.objs | 1 + hw/timer/mxs_rtc.c | 147 +++++++++++++++ hw/timer/mxs_timrot.c | 271 ++++++++++++++++++++++++++++ hw/usb/Makefile.objs | 1 + hw/usb/mxs_usb.c | 254 ++++++++++++++++++++++++++ 20 files changed, 2781 insertions(+) create mode 100644 hw/arm/imx233-olinuxino.c create mode 100644 hw/arm/imx23_digctl.c create mode 100644 hw/arm/imx23_pinctrl.c create mode 100644 hw/arm/mxs.c create mode 100644 hw/arm/mxs.h create mode 100644 hw/char/mxs_uart.c create mode 100644 hw/dma/mxs_dma.c create mode 100644 hw/intc/mxs_icoll.c create mode 100644 hw/ssi/mxs_spi.c create mode 100644 hw/timer/mxs_rtc.c create mode 100644 hw/timer/mxs_timrot.c create mode 100644 hw/usb/mxs_usb.c
Signature · 1 line
1.8.5.1
PATCH 1/13 mxs/imx23: Add main header file
Header file containing most of the base addresses and IO registers needed for the Freescale mxs/imx23 SoC emumation.
Also contains a generic helper to implement the SET/AND/OR/XOR trick shared by pretty much all of the IO blocks on this SoC
--- hw/arm/mxs.h | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 hw/arm/mxs.h
hw/arm/mxs.h new file +208 -0
@@ -0,0 +1,208 @@ +/* +* mxs.h +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence, the bits that aren't from linux's +*/ +/* +* Copyright (C) 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef MXS_H_ +#define MXS_H_ + +/* +* OCRAM +*/ +#define MX23_OCRAM_BASE_ADDR 0x00000000 +#define MX23_OCRAM_SIZE SZ_32K + +/* +* IO +*/ +#define MX23_IO_BASE_ADDR 0x80000000 +#define MX23_IO_SIZE SZ_1M + +#define MX23_ICOLL_BASE_ADDR (MX23_IO_BASE_ADDR + 0x000000) +#define MX23_APBH_DMA_BASE_ADDR (MX23_IO_BASE_ADDR + 0x004000) +#define MX23_BCH_BASE_ADDR (MX23_IO_BASE_ADDR + 0x00a000) +#define MX23_GPMI_BASE_ADDR (MX23_IO_BASE_ADDR + 0x00c000) +#define MX23_SSP1_BASE_ADDR (MX23_IO_BASE_ADDR + 0x010000) +#define MX23_PINCTRL_BASE_ADDR (MX23_IO_BASE_ADDR + 0x018000) +#define MX23_DIGCTL_BASE_ADDR (MX23_IO_BASE_ADDR + 0x01c000) +#define MX23_ETM_BASE_ADDR (MX23_IO_BASE_ADDR + 0x020000) +#define MX23_APBX_DMA_BASE_ADDR (MX23_IO_BASE_ADDR + 0x024000) +#define MX23_DCP_BASE_ADDR (MX23_IO_BASE_ADDR + 0x028000) +#define MX23_PXP_BASE_ADDR (MX23_IO_BASE_ADDR + 0x02a000) +#define MX23_OCOTP_BASE_ADDR (MX23_IO_BASE_ADDR + 0x02c000) +#define MX23_AXI_AHB0_BASE_ADDR (MX23_IO_BASE_ADDR + 0x02e000) +#define MX23_LCDIF_BASE_ADDR (MX23_IO_BASE_ADDR + 0x030000) +#define MX23_SSP2_BASE_ADDR (MX23_IO_BASE_ADDR + 0x034000) +#define MX23_TVENC_BASE_ADDR (MX23_IO_BASE_ADDR + 0x038000) +#define MX23_CLKCTRL_BASE_ADDR (MX23_IO_BASE_ADDR + 0x040000) +#define MX23_SAIF0_BASE_ADDR (MX23_IO_BASE_ADDR + 0x042000) +#define MX23_POWER_BASE_ADDR (MX23_IO_BASE_ADDR + 0x044000) +#define MX23_SAIF1_BASE_ADDR (MX23_IO_BASE_ADDR + 0x046000) +#define MX23_AUDIOOUT_BASE_ADDR (MX23_IO_BASE_ADDR + 0x048000) +#define MX23_AUDIOIN_BASE_ADDR (MX23_IO_BASE_ADDR + 0x04c000) +#define MX23_LRADC_BASE_ADDR (MX23_IO_BASE_ADDR + 0x050000) +#define MX23_SPDIF_BASE_ADDR (MX23_IO_BASE_ADDR + 0x054000) +#define MX23_I2C_BASE_ADDR (MX23_IO_BASE_ADDR + 0x058000) +#define MX23_RTC_BASE_ADDR (MX23_IO_BASE_ADDR + 0x05c000) +#define MX23_PWM_BASE_ADDR (MX23_IO_BASE_ADDR + 0x064000) +#define MX23_TIMROT_BASE_ADDR (MX23_IO_BASE_ADDR + 0x068000) +#define MX23_AUART1_BASE_ADDR (MX23_IO_BASE_ADDR + 0x06c000) +#define MX23_AUART2_BASE_ADDR (MX23_IO_BASE_ADDR + 0x06e000) +#define MX23_DUART_BASE_ADDR (MX23_IO_BASE_ADDR + 0x070000) +#define MX23_USBPHY_BASE_ADDR (MX23_IO_BASE_ADDR + 0x07c000) +#define MX23_USBCTRL_BASE_ADDR (MX23_IO_BASE_ADDR + 0x080000) +#define MX23_DRAM_BASE_ADDR (MX23_IO_BASE_ADDR + 0x0e0000) + +#define MX23_IO_P2V (x) MXS_IO_P2V(x) +#define MX23_IO_ADDRESS (x) IOMEM(MX23_IO_P2V(x)) + +/* +* IRQ +*/ +#define MX23_INT_DUART 0 +#define MX23_INT_COMMS_RX 1 +#define MX23_INT_COMMS_TX 1 +#define MX23_INT_SSP2_ERROR 2 +#define MX23_INT_VDD5V 3 +#define MX23_INT_HEADPHONE_SHORT 4 +#define MX23_INT_DAC_DMA 5 +#define MX23_INT_DAC_ERROR 6 +#define MX23_INT_ADC_DMA 7 +#define MX23_INT_ADC_ERROR 8 +#define MX23_INT_SPDIF_DMA 9 +#define MX23_INT_SAIF2_DMA 9 +#define MX23_INT_SPDIF_ERROR 10 +#define MX23_INT_SAIF1_IRQ 10 +#define MX23_INT_SAIF2_IRQ 10 +#define MX23_INT_USB_CTRL 11 +#define MX23_INT_USB_WAKEUP 12 +#define MX23_INT_GPMI_DMA 13 +#define MX23_INT_SSP1_DMA 14 +#define MX23_INT_SSP1_ERROR 15 +#define MX23_INT_GPIO0 16 +#define MX23_INT_GPIO1 17 +#define MX23_INT_GPIO2 18 +#define MX23_INT_SAIF1_DMA 19 +#define MX23_INT_SSP2_DMA 20 +#define MX23_INT_ECC8_IRQ 21 +#define MX23_INT_RTC_ALARM 22 +#define MX23_INT_AUART1_TX_DMA 23 +#define MX23_INT_AUART1 24 +#define MX23_INT_AUART1_RX_DMA 25 +#define MX23_INT_I2C_DMA 26 +#define MX23_INT_I2C_ERROR 27 +#define MX23_INT_TIMER0 28 +#define MX23_INT_TIMER1 29 +#define MX23_INT_TIMER2 30 +#define MX23_INT_TIMER3 31 +#define MX23_INT_BATT_BRNOUT 32 +#define MX23_INT_VDDD_BRNOUT 33 +#define MX23_INT_VDDIO_BRNOUT 34 +#define MX23_INT_VDD18_BRNOUT 35 +#define MX23_INT_TOUCH_DETECT 36 +#define MX23_INT_LRADC_CH0 37 +#define MX23_INT_LRADC_CH1 38 +#define MX23_INT_LRADC_CH2 39 +#define MX23_INT_LRADC_CH3 40 +#define MX23_INT_LRADC_CH4 41 +#define MX23_INT_LRADC_CH5 42 +#define MX23_INT_LRADC_CH6 43 +#define MX23_INT_LRADC_CH7 44 +#define MX23_INT_LCDIF_DMA 45 +#define MX23_INT_LCDIF_ERROR 46 +#define MX23_INT_DIGCTL_DEBUG_TRAP 47 +#define MX23_INT_RTC_1MSEC 48 +#define MX23_INT_DRI_DMA 49 +#define MX23_INT_DRI_ATTENTION 50 +#define MX23_INT_GPMI_ATTENTION 51 +#define MX23_INT_IR 52 +#define MX23_INT_DCP_VMI 53 +#define MX23_INT_DCP 54 +#define MX23_INT_BCH 56 +#define MX23_INT_PXP 57 +#define MX23_INT_AUART2_TX_DMA 58 +#define MX23_INT_AUART2 59 +#define MX23_INT_AUART2_RX_DMA 60 +#define MX23_INT_VDAC_DETECT 61 +#define MX23_INT_VDD5V_DROOP 64 +#define MX23_INT_DCDC4P2_BO 65 + +/* +* APBH DMA +*/ +#define MX23_DMA_SSP1 1 +#define MX23_DMA_SSP2 2 +#define MX23_DMA_GPMI0 4 +#define MX23_DMA_GPMI1 5 +#define MX23_DMA_GPMI2 6 +#define MX23_DMA_GPMI3 7 + +/* +* APBX DMA +*/ +#define MX23_DMA_ADC 0 +#define MX23_DMA_DAC 1 +#define MX23_DMA_SPDIF 2 +#define MX23_DMA_I2C 3 +#define MX23_DMA_SAIF0 4 +#define MX23_DMA_UART0_RX 6 +#define MX23_DMA_UART0_TX 7 +#define MX23_DMA_UART1_RX 8 +#define MX23_DMA_UART1_TX 9 +#define MX23_DMA_SAIF1 10 + +/* +* This is a generic function that handles write to IO register adresses +* This method of writing to peripherals IOs is shared by all the specific +* mxs IO blocks, thus this shared inline helper. +*/ +static inline uint32_t mxs_write ( +uint32_t * dst,hwaddr offset, +uint32_t value,unsigned size) +{ +if (!dst) { +return 0 ; + } +uint32_t oldvalue = *dst; +switch (offset &0xf ) { +case 0 : + *dst = value; +break ; +case 4 : + *dst |= value; +break ; +case 8 : + *dst &= ~value; +break ; +case 0xc : + *dst ^= value; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } +return oldvalue; +} + +#endif /* MXS_H_ */
Signature · 1 line
1.8.5.1
PATCH 4/13 mxs/imx23: Add DMA driver
In reply to Michel PolletThis driver works sufficiently well that linux can use it to access the SD card using the SD->DMA->SSI->SD. It hasn't been tested for much else.
--- hw/dma/Makefile.objs | 1 + hw/dma/mxs_dma.c | 347 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 hw/dma/mxs_dma.c
hw/dma/Makefile.objs +1 -0
@@ -8,6 +8,7 @@ common-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o common-obj-$(CONFIG_ETRAXFS) += etraxfs_dma.o common-obj-$(CONFIG_STP2000) += sparc32_dma.o common-obj-$(CONFIG_SUN4M) += sun4m_iommu.o +common-obj-$(CONFIG_MXS) += mxs_dma.o obj-$(CONFIG_OMAP) += omap_dma.o soc_dma.o obj-$(CONFIG_PXA2XX) += pxa2xx_dma.o
hw/dma/mxs_dma.c new file +347 -0
347 lines not on this page · raw message
Signature · 1 line
1.8.5.1
PATCH 6/13 mxs/imx23: Add digctl driver
In reply to Michel PolletThis implements just enough of the digctl IO block to allow linux to believe it's running on (currently only) an imx23.
--- hw/arm/Makefile.objs | 1 + hw/arm/imx23_digctl.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 hw/arm/imx23_digctl.c
hw/arm/Makefile.objs +1 -0
@@ -5,3 +5,4 @@ obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o +obj-$(CONFIG_MXS) += imx23_digctl.o
hw/arm/imx23_digctl.c new file +110 -0
110 lines not on this page · raw message
Signature · 1 line
1.8.5.1
PATCH 7/13 mxs/imx23: Implements the pin mux, GPIOs
In reply to Michel PolletImplements the pinctrl and GPIO block for the imx23 It handles GPIO output, and GPIO input from qemu translated into pin values and interrupts, if appropriate.
--- hw/arm/Makefile.objs | 2 +- hw/arm/imx23_pinctrl.c | 293 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 hw/arm/imx23_pinctrl.c
hw/arm/Makefile.objs +1 -1
@@ -5,4 +5,4 @@ obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o -obj-$(CONFIG_MXS) += imx23_digctl.o +obj-$(CONFIG_MXS) += imx23_digctl.o imx23_pinctrl.o
hw/arm/imx23_pinctrl.c new file +293 -0
293 lines not on this page · raw message
Signature · 1 line
1.8.5.1
PATCH 8/13 mxs/imx23: Add SSP/SPI driver
In reply to Michel PolletThis implements the SSP port(s) of the mxs. Currently hardcoded for the SD card interface, but as TODO it could rather easily be made to be generic and support 'generic' SPI too.
It is geared toward working with DMA, as the linux drivers uses it that way.
--- hw/ssi/Makefile.objs | 1 + hw/ssi/mxs_spi.c | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+) create mode 100644 hw/ssi/mxs_spi.c
hw/ssi/Makefile.objs +1 -0
@@ -4,3 +4,4 @@ common-obj-$(CONFIG_XILINX_SPI) += xilinx_spi.o common-obj-$(CONFIG_XILINX_SPIPS) += xilinx_spips.o obj-$(CONFIG_OMAP) += omap_spi.o +obj-$(CONFIG_MXS) += mxs_spi.o
hw/ssi/mxs_spi.c new file +239 -0
239 lines not on this page · raw message
Signature · 1 line
1.8.5.1
PATCH 5/13 mxs/imx23: Add the interrupt collector
In reply to Michel PolletImplements the interrupt collector IO block
--- hw/intc/Makefile.objs | 1 + hw/intc/mxs_icoll.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 hw/intc/mxs_icoll.c
hw/intc/Makefile.objs +1 -0
@@ -24,3 +24,4 @@ obj-$(CONFIG_OPENPIC_KVM) += openpic_kvm.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_MXS) += mxs_icoll.o
hw/intc/mxs_icoll.c new file +200 -0
200 lines not on this page · raw message
Signature · 1 line
1.8.5.1
PATCH 9/13 mxs/imx23: Add the RTC block
In reply to Michel PolletSupport for the RTC IO block on the imx23, enough to return a valid date and make guest linux happy.
--- hw/timer/Makefile.objs | 1 + hw/timer/mxs_rtc.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 hw/timer/mxs_rtc.c
hw/timer/Makefile.objs +1 -0
@@ -26,5 +26,6 @@ obj-$(CONFIG_OMAP) += omap_synctimer.o obj-$(CONFIG_PXA2XX) += pxa2xx_timer.o obj-$(CONFIG_SH4) += sh_timer.o obj-$(CONFIG_TUSB6010) += tusb6010.o +obj-$(CONFIG_MXS) += mxs_rtc.o obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
hw/timer/mxs_rtc.c new file +147 -0
147 lines not on this page · raw message
Signature · 1 line
1.8.5.1
PATCH 2/13 mxs: Add CONFIG_MXS to the arm-softmmu config
In reply to Michel PolletAllows selective compilation of the MXS bits
--- default-configs/arm-softmmu.mak | 1 + 1 file changed, 1 insertion(+)
default-configs/arm-softmmu.mak +1 -0
@@ -71,6 +71,7 @@ CONFIG_BLIZZARD=y CONFIG_ONENAND=y CONFIG_TUSB6010=y CONFIG_IMX=y +CONFIG_MXS=y CONFIG_MAINSTONE=y CONFIG_NSERIES=y CONFIG_REALVIEW=y
Signature · 1 line
1.8.5.1
PATCH 13/13 mxs/imx23: Adds support for an Olinuxino board
In reply to Michel PolletAdds support for creating a basic imx23 dev board from Olimex, with a few peripherals, a bitbang i2c bus with a RTC attached, a DS18S20 thermal sensor, and a rather crude 'relay' that increases/decreases the thermal sensor temperature.
Basicaly, it's a complete emulation of the hardware used for my real life boiler controller system; but it's a nice starting point for any other imx233 board prototyping.
https://plus.google.com/111387094029238541867/posts/Smwc7yFK3Vk
--- hw/arm/Makefile.objs | 1 + hw/arm/imx233-olinuxino.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 hw/arm/imx233-olinuxino.c
hw/arm/Makefile.objs +1 -0
@@ -6,3 +6,4 @@ obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o obj-$(CONFIG_MXS) += imx23_digctl.o imx23_pinctrl.o mxs.o +obj-$(CONFIG_MXS) += imx233-olinuxino.o
hw/arm/imx233-olinuxino.c new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
1.8.5.1
PATCH 12/13 mxs/imx23: Main core instantiation and minor IO blocks
In reply to Michel PolletThis adds support for creating an imx23 instance. This also contains some of the more minor IO blocks, and a 'catchall' driver that helps debugging access to undocumented IO registers.
Currently the instance can boot a linux kernel, but does not support booting from the 'special' signed Freescale binary blobs.
--- hw/arm/Makefile.objs | 2 +- hw/arm/mxs.c | 388 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 389 insertions(+), 1 deletion(-) create mode 100644 hw/arm/mxs.c
hw/arm/Makefile.objs +1 -1
@@ -5,4 +5,4 @@ obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o -obj-$(CONFIG_MXS) += imx23_digctl.o imx23_pinctrl.o +obj-$(CONFIG_MXS) += imx23_digctl.o imx23_pinctrl.o mxs.o
hw/arm/mxs.c new file +388 -0
388 lines not on this page · raw message
Signature · 1 line
1.8.5.1
PATCH 11/13 mxs/imx23: Add the USB driver
In reply to Michel PolletAdd the USB IO block, and the USB PHY IO block. This just wraps an ehci instance, and support some of the 'extra' mxs registers
--- hw/usb/Makefile.objs | 1 + hw/usb/mxs_usb.c | 254 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 255 insertions(+) create mode 100644 hw/usb/mxs_usb.c
hw/usb/Makefile.objs +1 -0
@@ -8,6 +8,7 @@ common-obj-$(CONFIG_USB_OHCI) += hcd-ohci.o common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o hcd-ehci-pci.o hcd-ehci-sysbus.o common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o +common-obj-$(CONFIG_MXS) += mxs_usb.o # emulated usb devices common-obj-y += dev-hub.o
hw/usb/mxs_usb.c new file +254 -0
254 lines not on this page · raw message
Signature · 1 line
1.8.5.1
PATCH 10/13 mxs/imx23: Add the timers
In reply to Michel PolletSupport for the timer IO block of the mxs/imx23. Does not support any of the fancy function, just the 32khz based timers used by linux.
--- hw/timer/Makefile.objs | 2 +- hw/timer/mxs_timrot.c | 271 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 272 insertions(+), 1 deletion(-) create mode 100644 hw/timer/mxs_timrot.c
hw/timer/Makefile.objs +1 -1
@@ -26,6 +26,6 @@ obj-$(CONFIG_OMAP) += omap_synctimer.o obj-$(CONFIG_PXA2XX) += pxa2xx_timer.o obj-$(CONFIG_SH4) += sh_timer.o obj-$(CONFIG_TUSB6010) += tusb6010.o -obj-$(CONFIG_MXS) += mxs_rtc.o +obj-$(CONFIG_MXS) += mxs_rtc.o mxs_timrot.o obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
hw/timer/mxs_timrot.c new file +271 -0
271 lines not on this page · raw message
Signature · 1 line
1.8.5.1
Can someone give me a pointer on how the review (if any) is done for these patches? I have to say I'm rather amazed at the rate of submission on the mailing list, and I worried to see these patches buried further and further down in such a short timescale :-)
Michael
Quoted 77 lines · Michel Pollet
This series adds support for the imx233 SoC, and also adds support for emulating
an Olinux Olinuxino board with a few peripherals, as a test harness. The emulation works pretty well, boots linux 3.12 vanilla from an emulated SD card,
has USB bridge support (but no support for USB 1.1 devices like mouse+keyboard), RTC
and quite a few other bits (some of them fairly skeletal)This series has been in used for quite a few months; it was posted here a few month
back and one of the question was to wether I would stick around to support it.
Perhaps the fact that I reworked it all on trunk and reposted it will help answer
this question.This patch series is also available on this github branch, in case its' more
convenient to use the inline comment function there.
https://github.com/buserror-uk/qemu-buserror/commits/dev-imx233Michel Pollet (13):
mxs/imx23: Add main header file
mxs: AddCONFIG_MXSto the arm-softmmu config mxs/imx23: Add uart driver
mxs/imx23: Add DMA driver
mxs/imx23: Add the interrupt collector mxs/imx23: Add digctl driver
mxs/imx23: Implements the pin mux, GPIOs mxs/imx23: Add SSP/SPI driver
mxs/imx23: Add the RTC block
mxs/imx23: Add the timers
mxs/imx23: Add the USB driver
mxs/imx23: Main core instantiation and minor IO blocks mxs/imx23: Adds support for an Olinuxino boarddefault-configs/arm-softmmu.mak | 1 + hw/arm/Makefile.objs | 2 + hw/arm/imx233-olinuxino.c | 169 +++++++++++++++++ hw/arm/imx23_digctl.c | 110 ++++++++++++ hw/arm/imx23_pinctrl.c | 293 ++++++++++++++++++++++++++++++ hw/arm/mxs.c | 388 ++++++++++++++++++++++++++++++++++++++++ hw/arm/mxs.h | 208 +++++++++++++++++++++ hw/char/Makefile.objs | 1 + hw/char/mxs_uart.c | 146 +++++++++++++++ hw/dma/Makefile.objs | 1 + hw/dma/mxs_dma.c | 347 +++++++++++++++++++++++++++++++++++ hw/intc/Makefile.objs | 1 + hw/intc/mxs_icoll.c | 200 +++++++++++++++++++++ hw/ssi/Makefile.objs | 1 + hw/ssi/mxs_spi.c | 239 +++++++++++++++++++++++++ hw/timer/Makefile.objs | 1 + hw/timer/mxs_rtc.c | 147 +++++++++++++++ hw/timer/mxs_timrot.c | 271 ++++++++++++++++++++++++++++ hw/usb/Makefile.objs | 1 + hw/usb/mxs_usb.c | 254 ++++++++++++++++++++++++++ 20 files changed, 2781 insertions(+) create mode 100644 hw/arm/imx233-olinuxino.c create mode 100644 hw/arm/imx23_digctl.c create mode 100644 hw/arm/imx23_pinctrl.c create mode 100644 hw/arm/mxs.c create mode 100644 hw/arm/mxs.h create mode 100644 hw/char/mxs_uart.c create mode 100644 hw/dma/mxs_dma.c create mode 100644 hw/intc/mxs_icoll.c create mode 100644 hw/ssi/mxs_spi.c create mode 100644 hw/timer/mxs_rtc.c create mode 100644 hw/timer/mxs_timrot.c create mode 100644 hw/usb/mxs_usb.c--
1.8.5.1
Quoted 4 lines · M P
Can someone give me a pointer on how the review (if any) is done for these patches? I have to say I'm rather amazed at the rate of submission on the mailing list, and I worried to see these patches buried further and further down in such a short timescale :-)
The rough process is:
* people reply to your email with review comments; when you've accumulated enough you send out a fixed set of patches for further review
* if nobody replies at all within say 2 weeks you can send out a 'ping' followup to this coverletter to bring the set back to peoples' attention
http://wiki.qemu.org/Contribute/SubmitAPatch is where we try to describe how the process works.
In this particular case, I have tagged your mail in my mail client as 'must-review'; however since my review queue is currently pretty full (you're one of four new ARM board/soc support patchsets, the others being Allwinner A10, Canon DIGIC and RaspberryPi; then there's the TrustZone support patchset and all the 64 bit support work) I'm afraid I can't currently promise a particularly rapid turnaround time.
If you can find the mail threads relating to the other recent board/soc support patchsets I listed above and look through review comments to see if any of them would apply to your board that would probably help.
thanks
-- PMM
Thanks Peter, very helpful -- and err, sorry to land you more work than you already had :-)
Would I contribute anything by also reviewing and/or testing the sus mentioned patches? I can at least test the A10 and raspi if this helps...
M
Quoted 35 lines · Peter Maydell
Quoted 1 line · M P
Can someone give me a pointer on how the review (if any) is done for
these
Quoted 2 lines
patches? I have to say I'm rather amazed at the rate of submission on the mailing list, and I worried to see these patches buried further and
further
Quoted 1 line
down in such a short timescale :-)
The rough process is:
* people reply to your email with review comments; when you've accumulated enough you send out a fixed set of patches for further review
* if nobody replies at all within say 2 weeks you can send out a 'ping' followup to this coverletter to bring the set back to peoples' attentionhttp://wiki.qemu.org/Contribute/SubmitAPatch is where we try to describe how the process works.
In this particular case, I have tagged your mail in my mail client as 'must-review'; however since my review queue is currently pretty full (you're one of four new ARM board/soc support patchsets, the others being Allwinner A10, Canon DIGIC and RaspberryPi; then there's the TrustZone support patchset and all the 64 bit support work) I'm afraid I can't currently promise a particularly rapid turnaround time.
If you can find the mail threads relating to the other recent board/soc support patchsets I listed above and look through review comments to see if any of them would apply to your board that would probably help.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 02/13] mxs: Add CONFIG_MXS to the arm-softmmu config
In reply to Michel PolletQuoted 12 lines · Michel Pollet
Allows selective compilation of the MXS bits
Signed-off-by Michel Pollet <[email protected]>--- default-configs/arm-softmmu.mak | 1 + 1 file changed, 1 insertion(+)default-configs/arm-softmmu.mak +0
-0
default-configs/arm-softmmu.mak CONFIG_BLIZZARD=y · line 77
Quoted 7 lines
default-configs/arm-softmmu.mak +1
-0@@ -71,6 +71,7 @@ CONFIG_BLIZZARD=y CONFIG_ONENAND=y CONFIG_TUSB6010=y CONFIG_IMX=y +CONFIG_MXS=y CONFIG_MAINSTONE=y CONFIG_NSERIES=y CONFIG_REALVIEW=y
In general we prefer to have a CONFIG_ switch for each device (and then one for the board as well); see for example the CONFIG_ALLWINNER_ switches just added. So I think it would be better to add those in the patches which add each device, rather than just having this one here.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 03/13] mxs/imx23: Add uart driver
In reply to Michel PolletQuoted 5 lines · Michel Pollet
Prototype driver for the mxs/imx23 uart IO block. This has no real 'uart' functional code, apart from letting itself be initialized by linux without generating a timeout error.
Signed-off-by Michel Pollet <[email protected]>
Hi; there are some minor code style/formatting errors with this patch. You can catch these by running the scripts/checkpatch.pl script on your patches. (It doesn't catch everything, and sometimes it gets confused and gives bogus results, but it's a good sanity check.)
Quoted 11 lines
--- hw/char/Makefile.objs | 1 + hw/char/mxs_uart.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 hw/char/mxs_uart.chw/char/Makefile.objs +0
-0
hw/char/Makefile.objs common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o · line 22
Quoted 4 lines
hw/char/Makefile.objs +1
-0@@ -19,6 +19,7 @@ common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o common-obj-$(CONFIG_ISA_DEBUG) += debugcon.o common-obj-$(CONFIG_GRLIB) += grlib_apbuart.o common-obj-$(CONFIG_IMX) += imx_serial.o +common-obj-$(CONFIG_MXS) += mxs_uart.o
This should be a CONFIG_MXS_UART (see remark on earlier patch).
Quoted 9 lines
hw/char/Makefile.objs +0
-0common-obj-$(CONFIG_LM32) += lm32_juart.o common-obj-$(CONFIG_LM32) += lm32_uart.o common-obj-$(CONFIG_MILKYMIST) += milkymist-uart.ohw/char/mxs_uart.c new file +0
-0
hw/char/mxs_uart.c line 6
Quoted 6 lines
hw/char/mxs_uart.c new file +6
-0@@ -0,0 +1,146 @@ +/* +* mxs_uart.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence
This is too vague. If you mean GPLv2 please say so.
hw/char/mxs_uart.c line 16
Quoted 10 lines
hw/char/mxs_uart.c new file +10
-0+*/ + +/* +* Work in progress ! Right now there's just enough so that linux driver +* will instantiate after a probe, there is no functional code. +*/ +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +#define D (w) w
Please get rid of this. You can use a similar DPRINTF type macro as other devices do, or no debug tracing at all, as you wish.
Quoted 19 lines
hw/char/mxs_uart.c new file +19
-0+ +enum { +UART_CTRL =0x0 , +UART_CTRL1 =0x1 , +UART_CTRL2 =0x2 , +UART_LINECTRL =0x3 , +UART_LINECTRL2 =0x4 , +UART_INTR =0x5 , +UART_APP_DATA =0x6 , +UART_APP_STAT =0x7 , +UART_APP_DEBUG =0x8 , +UART_APP_VERSION =0x9 , +UART_APP_AUTOBAUD =0xa , + +UART_MAX , +}; +typedef struct mxs_uart_state { + SysBusDevice busdev; + MemoryRegion iomem;
hw/char/mxs_uart.c line 45
Quoted 10 lines
hw/char/mxs_uart.c new file +10
-0+ +uint32_t r[UART_MAX ]; + +struct { +uint16_t b[16 ]; +int w, r; + } fifo[2 ]; +qemu_irq irq; +CharDriverState *chr; +} mxs_uart_state;
Structured type names should be in CamelCase; see CODING_STYLE.
hw/char/mxs_uart.c line 55
Quoted 9 lines
hw/char/mxs_uart.c new file +9
-0+static uint64_t mxs_uart_read ( +void *opaque,hwaddr offset,unsigned size) +{ +mxs_uart_state *s = (mxs_uart_state *) opaque; +uint32_t res =0 ; + + D(printf("%s %04x (%d) = ", __func__, (int)offset, size);) +switch (offset >>4 ) { + case 0 ... UART_MAX:
This indent is wrong, as checkpatch.pl will tell you.
Quoted 23 lines
hw/char/mxs_uart.c new file +23
-0+ res = s->r[offset >>4 ]; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } + D(printf("%08x\n", res);) + +return res; +} + +static void mxs_uart_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +mxs_uart_state *s = (mxs_uart_state *) opaque; +uint32_t oldvalue =0 ; + + D(printf("%s %04x %08x(%d)\n", __func__, (int)offset, (int)value, size);) +switch (offset >>4 ) { + case 0 ... UART_MAX: +mxs_write (&s->r[offset >>4 ], offset, value, size); +break ;
hw/char/mxs_uart.c line 88
Quoted 10 lines
hw/char/mxs_uart.c new file +10
-0+default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } +switch (offset >>4 ) { +case UART_CTRL : +if ((oldvalue ^ s->r[UART_CTRL ]) ==0x80000000 + && !(oldvalue &0x80000000 )) { +printf ("%s reseting, anding clockgate\n" , __func__);
Stray debug printout.
hw/char/mxs_uart.c line 97
Quoted 9 lines
hw/char/mxs_uart.c new file +9
-0+ s->r[UART_CTRL ] |=0x40000000 ; + } +break ; + } +} + +static void mxs_uart_set_irq (void *opaque,int irq,int level) +{ +// mxs_uart_state *s = (mxs_uart_state *)opaque;
Don't leave commented out code in your patches, please.
Quoted 6 lines
hw/char/mxs_uart.c new file +6
-0+printf ("%s %3d = %d\n" , __func__, irq, level); +} + +static const MemoryRegionOps mxs_uart_ops = { + .read = mxs_uart_read, + .write = mxs_uart_write,
hw/char/mxs_uart.c line 113
Quoted 10 lines
hw/char/mxs_uart.c new file +10
-0+ .endianness = DEVICE_NATIVE_ENDIAN, +}; + + +static int mxs_uart_init (SysBusDevice *dev) +{ +mxs_uart_state *s =OBJECT_CHECK (mxs_uart_state, dev,"mxs_uart" ); +DeviceState *qdev =DEVICE (dev); + +qdev_init_gpio_in (qdev, mxs_uart_set_irq,32 *3 );
Why has a UART got so many inbound GPIO signals? At minimum, there should be a comment here describing what they are.
hw/char/mxs_uart.c line 121
Quoted 8 lines
hw/char/mxs_uart.c new file +8
-0+sysbus_init_irq (dev, &s->irq); +memory_region_init_io (&s->iomem,OBJECT (s), &mxs_uart_ops, s,"mxs_uart" ,0x2000 ); +sysbus_init_mmio (dev, &s->iomem); + + s->r[UART_CTRL ] =0xc0030000 ; + s->r[UART_CTRL2 ] =0x00220180 ; + s->r[UART_APP_STAT ] =0x89f00000 ; + s->r[UART_APP_VERSION ] =0x03000000 ;
Don't do reset here, do it in a reset function (which you set up by setting the DeviceClass reset function pointer in the class init function). Reset is called for you after init, so you don't need to do any reset in init.
hw/char/mxs_uart.c line 130
Quoted 9 lines
hw/char/mxs_uart.c new file +9
-0+return 0 ; +} + + +static void mxs_uart_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_uart_init;
You need a vmstate structure to support save/load and VM migration, and then to set the DeviceClass vmsd field to point to it here.
Quoted 6 lines
hw/char/mxs_uart.c new file +6
-0+} + +static TypeInfo uart_info = { + .name ="mxs_uart" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_uart_state),
hw/char/mxs_uart.c line 146
Quoted 10 lines
hw/char/mxs_uart.c new file +10
-0+ .class_init = mxs_uart_class_init, +}; + +static void mxs_uart_register (void ) +{ +type_register_static (&uart_info); +} + +type_init (mxs_uart_register) +
thanks
-- PMM
Re: [Qemu-devel] [PATCH 04/13] mxs/imx23: Add DMA driver
In reply to Michel PolletQuoted 81 lines · Michel Pollet
This driver works sufficiently well that linux can use it to access the SD card using the
SD->DMA->SSI->SD. It hasn't been tested for much else.Signed-off-by Michel Pollet <[email protected]>--- hw/dma/Makefile.objs | 1 + hw/dma/mxs_dma.c | 347 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 hw/dma/mxs_dma.chw/dma/Makefile.objs +1
-0@@ -8,6 +8,7 @@ common-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o common-obj-$(CONFIG_ETRAXFS) += etraxfs_dma.o common-obj-$(CONFIG_STP2000) += sparc32_dma.o common-obj-$(CONFIG_SUN4M) += sun4m_iommu.o +common-obj-$(CONFIG_MXS) += mxs_dma.o obj-$(CONFIG_OMAP) += omap_dma.o soc_dma.o obj-$(CONFIG_PXA2XX) += pxa2xx_dma.ohw/dma/mxs_dma.c new file +52
-0@@ -0,0 +1,347 @@ +/* +* mxs_dma.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ + +/* +* Implements the DMA block of the mxs. +* The current implementation can run chains of commands etc, however it's only +* been tested with SSP for SD/MMC card access. It ought to work with normal SPI +* too, and possibly other peripherals, however it's entirely untested +*/ +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +/* +* DMA IO block register numbers +*/ +enum { +DMA_CTRL0 =0x0 , +DMA_CTRL1 =0x1 , +DMA_CTRL2 =0x2 , +DMA_DEVSEL1 =0x3 , +DMA_DEVSEL2 =0x4 , +DMA_MAX , + +/* +* The DMA block for APBH and APBX have a different base address, +* but they share a 7 words stride between channels. +*/ +DMA_STRIDE =0x70 , +/* +* Neither blocks uses that many, but there is space for them... +*/ +DMA_MAX_CHANNELS =16 , +}; + +/* +* DMA channel register numbers +*/ +enum { +CH_CURCMD =0 , +CH_NEXTCMD =1 , +CH_CMD =2 , +CH_BUFFER_ADDR =3 , +CH_SEMA =4 , +CH_DEBUG1 =5 , +CH_DEBUG2 =6 , +}; +
hw/dma/mxs_dma.c line 62
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+/* +* Channel command bit numbers +*/ +enum { +CH_CMD_IRQ_COMPLETE =3 , +CH_CMD_SEMAPHORE =6 , +}; + +/* +* nicked from linux
You don't need to say that, it doesn't really add any information to the reader.
hw/dma/mxs_dma.c line 69
Quoted 7 lines
hw/dma/mxs_dma.c new file +7
-0+* this is the memory representation of a DMA request +*/ +struct mxs_dma_ccw { +uint32_t next; +uint16_t bits; +uint16_t xfer_bytes; +#define MAX_XFER_BYTES 0xff00
I'd rather have the #defines before the struct than interleaved, personally.
hw/dma/mxs_dma.c line 73
Quoted 4 lines
hw/dma/mxs_dma.c new file +4
-0+uint32_t bufaddr; +#define MXS_PIO_WORDS 16 +uint32_t pio_words[MXS_PIO_WORDS ]; +}__attribute__((packed));
If you need to use packed then always use the QEMU_PACKED macro; this ensures the same layout on all host platforms (Windows behaviour of plain attribute packed is different).
hw/dma/mxs_dma.c line 83
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+ +/* +* Per channel DMA description +*/ +typedef struct mxs_dma_channel { + QEMUTimer *timer; + struct mxs_dma_state *dma; + int channel; // channel index + hwaddr base; // base of peripheral + hwaddr dataoffset; // offset of the true in/out data latch register
No C++-style comments, please.
Quoted 15 lines
hw/dma/mxs_dma.c new file +15
-0+uint32_t r[10 ]; +qemu_irq irq; +} mxs_dma_channel; + + +typedef struct mxs_dma_state { + SysBusDevice busdev; + MemoryRegion iomem; + const char * name; + + struct soc_dma_s * dma; + uint32_t r[DMA_MAX]; + + hwaddr base; // base of peripheral + mxs_dma_channel channel[DMA_MAX_CHANNELS];
hw/dma/mxs_dma.c line 108
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+} mxs_dma_state; + +static void mxs_dma_ch_update (mxs_dma_channel *s) +{ +struct mxs_dma_ccw req; +int i; + +/* increment the semaphore, if needed */ + s->r[CH_SEMA ] = (((s->r[CH_SEMA ] >>16 ) &0xff ) + + (s->r[CH_SEMA ] &0xff )) <<16 ;
This is confusing -- what's it actually doing?
hw/dma/mxs_dma.c line 113
Quoted 5 lines
hw/dma/mxs_dma.c new file +5
-0+if (!((s->r[CH_SEMA ] >>16 ) &0xff )) { +return ; + } +/* read the request from memory */ +cpu_physical_memory_read (s->r[CH_NEXTCMD ], &req,sizeof (req));
This will not work if your host and target have opposite endianness. If you're going to read the whole struct in at once like this you need to use the cpu_to_le* functions to swap all its members to the host endianness. Similarly anywhere you write a block of memory back. Alternatively you can use the ld*_le_phys and st*_le_phys to read and write specifically sized bytes/shorts/words to little-endian guest order.
hw/dma/mxs_dma.c line 123
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+/* update the latch registers accordingly */ + s->r[CH_CURCMD ] = s->r[CH_NEXTCMD ]; + s->r[CH_NEXTCMD ] = req.next; + s->r[CH_CMD ] = (req.xfer_bytes <<16 ) | req.bits; + s->r[CH_BUFFER_ADDR ] = req.bufaddr; + +/* write PIO registers first, if any */ +for (i =0 ; i < (req.bits >>12 ); i++) { +cpu_physical_memory_rw (s->base + (i <<4 ), + (uint8_t *) &req.pio_words[i],4 ,1 );
...for instance this is probably best done via stl_le_phys() to write each word to the guest memory.
Quoted 31 lines
hw/dma/mxs_dma.c new file +31
-0+ } +/* next handle any "data" requests */ +switch (req.bits &0x3 ) { +case 0 : +break ;// PIO only +case 0x1 : {// WRITE (from periph to memory) +uint32_t buf = req.bufaddr; +uint8_t b =0 ; +while (req.xfer_bytes--) { +cpu_physical_memory_rw (s->base + s->dataoffset, &b,1 ,0 ); +cpu_physical_memory_rw (buf, &b,1 ,1 ); + buf++; + } + }break ; +case 0x2 : {// READ (from memory to periph) +uint32_t buf = req.bufaddr; +uint8_t b =0 ; +while (req.xfer_bytes--) { +cpu_physical_memory_rw (buf, &b,1 ,0 ); +cpu_physical_memory_rw (s->base + s->dataoffset, &b,1 ,1 ); + buf++; + } + }break ; + } + + s->dma->r[DMA_CTRL1 ] |=1 << s->channel; +/* trigger IRQ if requested */ +if ((s->dma->r[DMA_CTRL1 ] >>16 ) & (1 << s->channel)) { +if (req.bits & (1 <<CH_CMD_IRQ_COMPLETE )) { +qemu_set_irq (s->irq,1 ); + }
hw/dma/mxs_dma.c line 164
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+ } + +/* decrement semaphore if requested */ +if (s->r[CH_CMD ] & (1 <<CH_CMD_SEMAPHORE )) { + s->r[CH_SEMA ] = (((s->r[CH_SEMA ] >>16 ) &0xff ) -1 ) <<16 ; + } +/* If the semaphore is still on, try to trigger a chained request */ +if ((s->r[CH_SEMA ] >>16 ) &0xff ) { +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +timer_mod (s->timer, now +10 );
This stuff involving the timer looks a bit fishy, but I'm not really up on current best practice with DMA, timers, etc. Peter Crosthwaite may have a more informed opinion.
Quoted 48 lines
hw/dma/mxs_dma.c new file +48
-0+ } +} + +/* called on one shot timer activation */ +static void mxs_dma_ch_run (void *opaque) +{ +mxs_dma_channel *s = opaque; +mxs_dma_ch_update (s); +} + +static uint64_t mxs_dma_read (void *opaque,hwaddr offset,unsigned size) +{ +mxs_dma_state *s = (mxs_dma_state *) opaque; +uint32_t res =0 ; + +switch (offset >>4 ) { + case 0 ... DMA_MAX - 1: + res = s->r[offset >>4 ]; +break ; +default : +if (offset >= s->base) { + offset -= s->base; +int channel = offset /DMA_STRIDE ; +int word = (offset %DMA_STRIDE ) >>4 ; + res = s->channel[channel].r[word]; + }else +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } + +return res; +} + +static void mxs_dma_write (void *opaque,hwaddr offset,uint64_t value, +unsigned size) +{ +mxs_dma_state *s = (mxs_dma_state *) opaque; +uint32_t oldvalue =0 ; +int channel, word, i; + +switch (offset >>4 ) { + case 0 ... DMA_MAX - 1: + oldvalue =mxs_write (&s->r[offset >>4 ], offset, value, size); +break ; +default : +if (offset >= s->base) { + channel = (offset - s->base) /DMA_STRIDE ;
hw/dma/mxs_dma.c line 222
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+ word = (offset - s->base) %DMA_STRIDE ; + oldvalue =mxs_write ( + &s->channel[channel].r[word >>4 ], word, + value, size); +switch (word >>4 ) { +case CH_SEMA : +// mask the new semaphore value, as only the lowest 8 bits are RW + s->channel[channel].r[CH_SEMA ] = + (oldvalue & ~0xff ) | + (s->channel[channel].r[CH_SEMA ] &0xff );
You can do this with
s->channel[channel].r[CH_SEMA] = deposit32(oldvalue, 0, 8,
s->channel[channel].r[CH_SEMA]);Quoted 94 lines
hw/dma/mxs_dma.c new file +94
-0+mxs_dma_ch_update (&s->channel[channel]); +break ; + } + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); + } +break ; + } +switch (offset >>4 ) { +case DMA_CTRL0 : +if ((oldvalue ^ s->r[DMA_CTRL0 ]) ==0x80000000 + && !(oldvalue &0x80000000 )) { +// printf("%s write reseting, anding clockgate\n", s->name); + s->r[DMA_CTRL0 ] |=0x40000000 ; + } +break ; +case DMA_CTRL1 : +for (i =0 ; i <DMA_MAX_CHANNELS ; i++) +if (s->channel[i].r[CH_NEXTCMD ] && + !(s->r[DMA_CTRL1 ] & (1 << i))) { +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +/* add a bit of latency to the timer. Ideally would +* do some calculation proportional to the transfer +* size. TODO ? +*/ +timer_mod (s->channel[i].timer, now +100000 ); + } +break ; + } +} + + +static const MemoryRegionOps mxs_dma_ops = { + .read = mxs_dma_read, + .write = mxs_dma_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static void mxs_dma_common_init (mxs_dma_state *s) +{ +int i; +memory_region_init_io (&s->iomem,OBJECT (s), &mxs_dma_ops, s,"mxs_dma" ,0x2000 ); +sysbus_init_mmio (&s->busdev, &s->iomem); +for (i =0 ; i <DMA_MAX_CHANNELS ; i++) { + s->channel[i].dma = s; + s->channel[i].channel = i; + s->channel[i].timer = +timer_new_ns (QEMU_CLOCK_VIRTUAL , mxs_dma_ch_run, &s->channel[i]); + } +} + +static int mxs_apbh_dma_init (SysBusDevice *dev) +{ +mxs_dma_state *s =OBJECT_CHECK (mxs_dma_state, dev,"mxs_apbh_dma" ); + +mxs_dma_common_init (s); + s->name ="dma_apbh" ; + s->base =0x40 ; +sysbus_init_irq (dev, &s->channel[MX23_DMA_SSP1 ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_SSP2 ].irq); + s->channel[MX23_DMA_SSP1 ].base =MX23_SSP1_BASE_ADDR ; + s->channel[MX23_DMA_SSP1 ].dataoffset =0x70 ; + s->channel[MX23_DMA_SSP2 ].base =MX23_SSP2_BASE_ADDR ; + s->channel[MX23_DMA_SSP2 ].dataoffset =0x70 ; + +return 0 ; +} + +static int mxs_apbx_dma_init (SysBusDevice *dev) +{ +// mxs_dma_state *s = FROM_SYSBUS(mxs_dma_state, dev); +mxs_dma_state *s =OBJECT_CHECK (mxs_dma_state, dev,"mxs_apbx_dma" ); + +mxs_dma_common_init (s); + s->name ="dma_apbx" ; + s->base =0x100 ; +sysbus_init_irq (dev, &s->channel[MX23_DMA_ADC ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_DAC ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_SPDIF ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_I2C ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_SAIF0 ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART0_RX ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART0_TX ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART1_RX ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART1_TX ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_SAIF1 ].irq); + +return 0 ; +} + +static void mxs_apbh_dma_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass);
hw/dma/mxs_dma.c line 326
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+ + sdc->init = mxs_apbh_dma_init; +} + +static void mxs_apbx_dma_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_apbx_dma_init; +}
Needs reset and vmstate.
Quoted 22 lines
hw/dma/mxs_dma.c new file +21
-1+ +static TypeInfo apbh_dma_info = { + .name ="mxs_apbh_dma" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_dma_state), + .class_init = mxs_apbh_dma_class_init, +}; +static TypeInfo apbx_dma_info = { + .name ="mxs_apbx_dma" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_dma_state), + .class_init = mxs_apbx_dma_class_init, +}; + +static void mxs_dma_register (void ) +{ +type_register_static (&apbh_dma_info); +type_register_static (&apbx_dma_info); +} + +type_init (mxs_dma_register) --
Quoted 1 line
1.8.5.1
thanks
-- PMM
Re: [Qemu-devel] [PATCH 05/13] mxs/imx23: Add the interrupt collector
In reply to Michel PolletQuoted 24 lines · Michel Pollet
Implements the interrupt collector IO block
Signed-off-by Michel Pollet <[email protected]>--- hw/intc/Makefile.objs | 1 + hw/intc/mxs_icoll.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 hw/intc/mxs_icoll.chw/intc/Makefile.objs +1
-0@@ -24,3 +24,4 @@ obj-$(CONFIG_OPENPIC_KVM) += openpic_kvm.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_MXS) += mxs_icoll.ohw/intc/mxs_icoll.c new file +0
-0
hw/intc/mxs_icoll.c line 7
Quoted 7 lines
hw/intc/mxs_icoll.c new file +7
-0@@ -0,0 +1,200 @@ +/* +* mxs_icoll.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/
I'm not going to keep making the same remarks about reset, licence header, coding style, vmstate, but you can assume they apply to all these patches.
Quoted 63 lines
hw/intc/mxs_icoll.c new file +63
-0+ +/* +* This block implements the interrupt collector of the mxs +* Currently no priority is handled, as linux doesn't use them anyway +*/ + +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +enum { +ICOLL_VECTOR =0 , +ICOLL_LEVELACK =1 , +ICOLL_CTRL =2 , +// 3, reserved? +ICOLL_VBASE =4 , +ICOLL_STAT =7 , + +ICOLL_REG_MAX , + +ICOLL_RAW0 =0xa , +ICOLL_RAW1 , +ICOLL_RAW2 , +ICOLL_RAW3 , + +ICOLL_INT0 =0x12 , +ICOLL_INT127 =0x91 , +}; + +typedef struct mxs_icoll_state { +SysBusDevice busdev; +MemoryRegion iomem; +uint32_t reg[ICOLL_REG_MAX ]; + +uint32_t raised[4 ]; +uint32_t fiq[4 ]; +uint32_t irq[4 ]; + +uint8_t r[128 ]; + +qemu_irq parent_irq; +qemu_irq parent_fiq; +}mxs_icoll_state ; + +static void mxs_icoll_update (mxs_icoll_state *s) +{ +int fiq =0 , irq =0 ; +int i; + +for (i =0 ; i <4 ; i++) { +int id =ffs (s->raised[i]); +int vector = (i *32 ) + id -1 ; +if (s->raised[i] & s->fiq[i]) { + fiq++; + s->reg[ICOLL_STAT ] = vector; +break ; + } +if (s->raised[i] & s->irq[i]) { + irq++; + s->reg[ICOLL_STAT ] = vector; +break ; + } + } +qemu_set_irq (s->parent_irq, irq !=0 );
hw/intc/mxs_icoll.c line 80
Quoted 10 lines
hw/intc/mxs_icoll.c new file +10
-0+qemu_set_irq (s->parent_fiq, fiq !=0 ); +} + +static void mxs_icoll_set_irq (void *opaque,int irq,int level) +{ +mxs_icoll_state *s = (mxs_icoll_state *) opaque; +if (level) + s->raised[(irq /32 )] |=1 << (irq %32 ); +else + s->raised[(irq /32 )] &= ~(1 << (irq %32 ));
This if needs braces around both arms.
Quoted 46 lines
hw/intc/mxs_icoll.c new file +46
-0+mxs_icoll_update (s); +} + +static uint64_t mxs_icoll_read (void *opaque,hwaddr offset,unsigned size) +{ +mxs_icoll_state *s = (mxs_icoll_state *) opaque; + +switch (offset >>4 ) { + case 0 ... ICOLL_REG_MAX: +return s->reg[offset >>4 ]; + case ICOLL_RAW0 ... ICOLL_RAW3: +return s->raised[(offset >>4 ) -ICOLL_RAW0 ]; + case ICOLL_INT0 ... ICOLL_INT127: +return s->r[(offset >>4 ) -ICOLL_INT0 ]; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } +return 0 ; +} + +static void mxs_icoll_write ( +void *opaque,hwaddr offset,uint64_t value,unsigned size) +{ +mxs_icoll_state *s = (mxs_icoll_state *) opaque; +uint32_t irqval, irqi =0 ; +uint32_t * dst =NULL ; +uint32_t oldvalue =0 ; + +switch (offset >>4 ) { + case 0 ... ICOLL_REG_MAX: + dst = s->reg + (offset >>4 ); +break ; + case ICOLL_INT0 ... ICOLL_INT127: + irqi = (offset >>4 ) -ICOLL_INT0 ; + irqval = s->r[irqi]; + dst = &irqval; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } +if (!dst) { +return ;
hw/intc/mxs_icoll.c line 136
Quoted 10 lines
hw/intc/mxs_icoll.c new file +10
-0+ } + oldvalue =mxs_write (dst, offset, value, size); + +switch (offset >>4 ) { +case ICOLL_CTRL : +if ((oldvalue ^ s->r[ICOLL_CTRL ]) ==0x80000000 + && !(oldvalue &0x80000000 )) { +// printf("%s reseting, anding clockgate\n", __func__); + s->r[ICOLL_CTRL ] |=0x40000000 ; + }
I've seen this bit of magic in several patches now. It could use explanation and maybe being factored out somehow?
Quoted 65 lines
hw/intc/mxs_icoll.c new file +64
-1+break ; +case ICOLL_LEVELACK : + irqi = s->reg[ICOLL_STAT ] &0x7f ; + s->raised[(irqi /32 )] &= ~(1 << (irqi %32 )); + s->reg[ICOLL_STAT ] =0x7f ; +break ; + case ICOLL_INT0 ... ICOLL_INT127: + s->r[irqi] = irqval & ~(0x40 );// dont' set softirq bit +if (irqval &0x4 )// ENABLE + s->irq[irqi /32 ] |= (1 << (irqi %32 )); +else + s->irq[irqi /32 ] &= ~(1 << (irqi %32 )); +if (irqval &0x10 )// ENFIQ + s->fiq[irqi /32 ] |= (1 << (irqi %32 )); +else + s->fiq[irqi /32 ] &= ~(1 << (irqi %32 )); +if (irqval &0x8 )// SOFTIRQ +mxs_icoll_set_irq (s, irqi,1 ); +break ; + } + +mxs_icoll_update (s); +} + +static const MemoryRegionOps mxs_icoll_ops = { + .read = mxs_icoll_read, + .write = mxs_icoll_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static int mxs_icoll_init (SysBusDevice *dev) +{ +mxs_icoll_state *s =OBJECT_CHECK (mxs_icoll_state, dev,"mxs_icoll" ); +DeviceState *qdev =DEVICE (dev); + +qdev_init_gpio_in (qdev, mxs_icoll_set_irq,128 ); +sysbus_init_irq (dev, &s->parent_irq); +sysbus_init_irq (dev, &s->parent_fiq); +memory_region_init_io (&s->iomem,OBJECT (s), &mxs_icoll_ops, s, +"mxs_icoll" ,0x2000 ); +sysbus_init_mmio (dev, &s->iomem); +return 0 ; +} + +static void mxs_icoll_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_icoll_init; +} + +static TypeInfo icoll_info = { + .name ="mxs_icoll" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_icoll_state), + .class_init = mxs_icoll_class_init, +}; + +static void mxs_icoll_register (void ) +{ +type_register_static (&icoll_info); +} + +type_init (mxs_icoll_register) --
Quoted 3 lines
1.8.5.1
-- PMM
Re: [Qemu-devel] [PATCH 06/13] mxs/imx23: Add digctl driver
In reply to Michel PolletQuoted 47 lines · Michel Pollet
This implements just enough of the digctl IO block to allow linux to believe it's running on (currently only) an imx23.
Signed-off-by Michel Pollet <[email protected]>--- hw/arm/Makefile.objs | 1 + hw/arm/imx23_digctl.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 hw/arm/imx23_digctl.chw/arm/Makefile.objs +1
-0@@ -5,3 +5,4 @@ obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o +obj-$(CONFIG_MXS) += imx23_digctl.ohw/arm/imx23_digctl.c new file +22
-0@@ -0,0 +1,110 @@ +/* +* imx23_digctl.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ + +/* +* This module implements a very basic IO block for the digctl of the imx23 +* Basically there is no real logic, just constant registers return, the most +* used one bing the "chip id" that is used by the various linux drivers +* to differentiate between imx23 and 28. +* +* The module consists mostly of read/write registers that the bootloader and +* kernel are quite happy to 'set' to whatever value they believe they set... +*/ + +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +enum {
hw/arm/imx23_digctl.c line 32
Quoted 10 lines
hw/arm/imx23_digctl.c new file +10
-0+HW_DIGCTL_RAMCTL =0x3 , + HW_DIGCTL_CHIPID = 0x31, +}; + +typedef struct imx23_digctl_state { +SysBusDevice busdev; +MemoryRegion iomem; + +uint32_t reg[0x2000 /4 ]; +}imx23_digctl_state ;
I'm not generally a fan of "big reg[] array" like this. In real hardware are these typically constant read/only registers, or do they actually do something? Does the hardware really have a full set of 2048 registers here, or are there gaps?
I'd rather have us implement just the minimal set required for things to boot, with LOG_UNIMP (and read-zero/write-ignored) for the rest. That makes it easier to add actual implementations later (and your migration state is not 0x2000 bytes of random undifferentiated stuff).
thanks
-- PMM
Re: [Qemu-devel] [PATCH 07/13] mxs/imx23: Implements the pin mux, GPIOs
In reply to Michel PolletQuoted 121 lines · Michel Pollet
Implements the pinctrl and GPIO block for the imx23 It handles GPIO output, and GPIO input from qemu translated into pin values and interrupts, if appropriate.
Signed-off-by Michel Pollet <[email protected]>--- hw/arm/Makefile.objs | 2 +- hw/arm/imx23_pinctrl.c | 293 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 hw/arm/imx23_pinctrl.chw/arm/Makefile.objs +1
-1@@ -5,4 +5,4 @@ obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o -obj-$(CONFIG_MXS) += imx23_digctl.o +obj-$(CONFIG_MXS) += imx23_digctl.o imx23_pinctrl.ohw/arm/imx23_pinctrl.c new file +94
-0@@ -0,0 +1,293 @@ +/* +* imx23_pinctrl.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ + +/* +* Implements the pinctrl and GPIO block for the imx23 +* It handles GPIO output, and GPIO input from qemu translated +* into pin values and interrupts, if appropriate. +*/ +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +#define D (w) + +enum { +PINCTRL_BANK_COUNT =3 , + +PINCTRL_CTRL =0 , +PINCTRL_BANK_MUXSEL =0x10 , +PINCTRL_BANK_BASE =0x40 , + +/* these are not << 4 register numbers, these are << 8 register numbers */ +PINCTRL_BANK_PULL =0x4 , +PINCTRL_BANK_OUT =0x5 , +PINCTRL_BANK_DIN =0x6 , +PINCTRL_BANK_DOE =0x7 , +PINCTRL_BANK_PIN2IRQ =0x8 , +PINCTRL_BANK_IRQEN =0x9 , +PINCTRL_BANK_IRQLEVEL =0xa , +PINCTRL_BANK_IRQPOL =0xb , +PINCTRL_BANK_IRQSTAT =0xc , + +PINCTRL_BANK_INTERNAL_STATE =0xd , +PINCTRL_MAX =0xe0 , +}; + +#define PINCTRL_BANK_REG (_bank, _reg) ((_reg << 8) | (_bank << 4)) + +enum { +MUX_GPIO =0x3 , +}; + + +typedef struct imx23_pinctrl_state { +SysBusDevice busdev; +MemoryRegion iomem; + +uint32_t r[PINCTRL_MAX ]; +qemu_irq irq_in[3 ]; +qemu_irq irq_out[PINCTRL_BANK_COUNT *32 ]; + +uint32_t state[PINCTRL_BANK_COUNT ]; +}imx23_pinctrl_state ; + +static uint64_t imx23_pinctrl_read ( +void *opaque,hwaddr offset,unsigned size) +{ +imx23_pinctrl_state *s = (imx23_pinctrl_state *) opaque; +uint32_t res =0 ; + +switch (offset >>4 ) { + case 0 ... PINCTRL_MAX: + res = s->r[offset >>4 ]; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } + +return res; +} + +static uint8_t imx23_pinctrl_getmux ( +imx23_pinctrl_state *s,int pin) +{ +int base = pin /16 , offset = pin %16 ; +return (s->r[PINCTRL_BANK_MUXSEL + base] >> (offset *2 )) &0x3 ; +} + +/* +* usage imx23_pinctrl_getbit(s, PINCTRL_BANK_IRQEN, 48)... +*/ +static uint8_t imx23_pinctrl_getbit ( +imx23_pinctrl_state *s,uint16_t reg,int pin) +{ +int bank = pin /32 , offset = pin %32 ; +uint32_t * latch = &s->r[PINCTRL_BANK_REG (bank, reg) >>4 ]; +// printf("%s bank %d offset %d reg %d : %04x=%08x\n", __func__, bank, offset, reg, +// PINCTRL_BANK_REG(bank, reg),
hw/arm/imx23_pinctrl.c line 104
Quoted 10 lines
hw/arm/imx23_pinctrl.c new file +10
-0+// *latch); +return (*latch >> offset) &0x1 ; +} + +static void imx23_pinctrl_setbit ( +imx23_pinctrl_state *s,uint16_t reg,int pin,int value) +{ +int bank = pin /32 , offset = pin %32 ; +uint32_t * latch = &s->r[PINCTRL_BANK_REG (bank, reg) >>4 ]; + *latch = (*latch & ~(1 << offset)) | (!!value << offset);
deposit32() will make this clearer to read.
hw/arm/imx23_pinctrl.c line 116
Quoted 12 lines
hw/arm/imx23_pinctrl.c new file +12
-0+} + +static void imx23_pinctrl_write_bank ( +imx23_pinctrl_state *s,int bank, +int reg,uint32_t value, +uint32_t mask) +{ +int set, pin; +switch (reg) { +/* +* Linux has a way of using the DOE&PULL register to toggle the pin +*/
Why is this comment here? We should ideally not care what guest OS we run, we should just implement the h/w correctly.
Quoted 5 lines
hw/arm/imx23_pinctrl.c new file +5
-0+case PINCTRL_BANK_PULL : +case PINCTRL_BANK_DOE : +/* +* Writing to the Data OUT register just triggers the +* output qemu IRQ for any further peripherals
hw/arm/imx23_pinctrl.c line 131
Quoted 10 lines
hw/arm/imx23_pinctrl.c new file +10
-0+*/ +case PINCTRL_BANK_OUT : { +while ((set =ffs (mask)) >0 ) { + set--; + mask &= ~(1 << set); + pin = (bank *32 ) + set; +/* +* For a reason that is not clear, the pullup bit appears +* inverted (!) ignoring for now, assume hardware pullup +*/
You should figure out what's actually happening here...
Quoted 52 lines
hw/arm/imx23_pinctrl.c new file +52
-0+// imx23_pinctrl_getbit(s, PINCTRL_BANK_PULL, pin) +int val = +imx23_pinctrl_getbit (s,PINCTRL_BANK_DOE , pin) ? +imx23_pinctrl_getbit (s,PINCTRL_BANK_OUT , pin) : +1 ; +D (printf ("%s set %2d to OUT:%d DOE:%d (PULL:%d) = %d\n" , __func__, + pin, +imx23_pinctrl_getbit (s,PINCTRL_BANK_OUT , pin), +imx23_pinctrl_getbit (s,PINCTRL_BANK_DOE , pin), +imx23_pinctrl_getbit (s,PINCTRL_BANK_PULL , pin), + val);) + +if (imx23_pinctrl_getbit (s,PINCTRL_BANK_INTERNAL_STATE , pin) != val) { +qemu_set_irq (s->irq_out[pin], val); +imx23_pinctrl_setbit (s,PINCTRL_BANK_INTERNAL_STATE , pin, val); + } + } + }break ; +/* +* This happends when we receive a qemu IRQ on the input ones, +* the register gets updated by the code executed until now, +* and all we need to do here is to trigger the imx233 IRQ +* if appropriate. +* Doing a write to these registers from guest code will acts as +* a software interrupt, not entirely sure this is appropriate +*/ +case PINCTRL_BANK_DIN : { +while ((set =ffs (mask)) >0 ) { + set--; + mask &= ~(1 << set); + pin = (bank *32 ) + set; +D (printf ("%s input %2d set to %d\n" , __func__, + pin, !!(value & (1 << set)));) + // its it a GPIO ? +if (imx23_pinctrl_getmux (s, pin) !=MUX_GPIO ) { +break ; + } +// if the new value matches the polarity bit, it's the +// edge the guy wanted. +int valid_irq = ((value >> set) &1 ) == +imx23_pinctrl_getbit (s,PINCTRL_BANK_IRQPOL , pin); +if (valid_irq) { +if (imx23_pinctrl_getbit (s,PINCTRL_BANK_PIN2IRQ , pin)) { +imx23_pinctrl_setbit (s,PINCTRL_BANK_IRQSTAT , pin,1 ); + } +// is the interrupt enabled? +if (imx23_pinctrl_getbit (s,PINCTRL_BANK_IRQEN , pin)) { +qemu_irq_raise (s->irq_in[bank]); + } + } + } + }break ;
hw/arm/imx23_pinctrl.c line 193
Quoted 10 lines
hw/arm/imx23_pinctrl.c new file +10
-0+ } +} + +static void imx23_pinctrl_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +imx23_pinctrl_state *s = (imx23_pinctrl_state *) opaque; +uint32_t oldvalue =0 ; + +// printf("%s offset %04x value %08x\n", __func__, (int)offset, (int)value);
All this commented out debug code needs to go.
Quoted 49 lines
hw/arm/imx23_pinctrl.c new file +49
-0+switch (offset >>4 ) { + case 0 ... PINCTRL_MAX: + oldvalue =mxs_write (&s->r[offset >>4 ], offset, value, size); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } +switch (offset >>4 ) { +case PINCTRL_CTRL : +if ((oldvalue ^ s->r[PINCTRL_CTRL ]) ==0x80000000 + && !(oldvalue &0x80000000 )) { +// printf("%s reseting, anding clockgate\n", __func__); + s->r[PINCTRL_CTRL ] |=0x40000000 ; + } +break ; + case PINCTRL_BANK_BASE ... PINCTRL_MAX: { +int bank = (offset >>4 ) &0xf ; +int reg = (offset >>8 ); +uint32_t mask = oldvalue ^ s->r[offset >>4 ]; +// printf("%s b %d r %x input %08x mask %08x value %08x\n", +// __func__, bank, reg, (int)value, mask, s->r[offset >> 4]); +imx23_pinctrl_write_bank (s, bank, reg, + s->r[offset >>4 ], mask); + }break ; + } +} + +/* +* This will interfaces qemu other components back to the guest input pins +*/ +static void imx23_pinctrl_set_irq (void *opaque,int irq,int level) +{ +// simulate a write to the data IN address +int bank = irq /32 ; +hwaddr offset = +PINCTRL_BANK_REG (bank,PINCTRL_BANK_DIN ); +uint64_t value = (1 << (irq %32 )); + D(printf("%s %d = %d\n", __func__, irq, level);) +imx23_pinctrl_write (opaque, + offset + (level ?0x4 :0x8 ), + value,4 ); +} + +static const MemoryRegionOps imx23_pinctrl_ops = { + .read = imx23_pinctrl_read, + .write = imx23_pinctrl_write, + .endianness =DEVICE_NATIVE_ENDIAN ,
hw/arm/imx23_pinctrl.c line 252
Quoted 10 lines
hw/arm/imx23_pinctrl.c new file +10
-0+}; + +static int imx23_pinctrl_init (SysBusDevice *dev) +{ +imx23_pinctrl_state *s =OBJECT_CHECK (imx23_pinctrl_state, dev,"imx23_pinctrl" ); +int i; +DeviceState *qdev =DEVICE (dev); + +// NEEDED for qdev_find_recursive to work + qdev->id ="imx23_pinctrl" ;
This looks suspicious. Nobody else needs to set qdev->id, why is your device special?
Quoted 42 lines
hw/arm/imx23_pinctrl.c new file +41
-1+qdev_init_gpio_in (qdev, imx23_pinctrl_set_irq,32 *PINCTRL_BANK_COUNT ); +qdev_init_gpio_out (qdev, s->irq_out,ARRAY_SIZE (s->irq_out)); +memory_region_init_io (&s->iomem,OBJECT (s), &imx23_pinctrl_ops, s, +"imx23_pinctrl" ,0x2000 ); +sysbus_init_mmio (dev, &s->iomem); + +for (i =0 ; i <PINCTRL_BANK_COUNT ; i++) { +sysbus_init_irq (dev, &s->irq_in[i]); + s->r[PINCTRL_BANK_REG (i,PINCTRL_BANK_DIN ) >>4 ] =0 ; + s->r[PINCTRL_BANK_REG (i,PINCTRL_BANK_PULL ) >>4 ] =0xffffffff ; + } +/* set default mux values */ +for (i =0 ; i <8 ; i++) + s->r[(0x100 >>4 ) + i] =0x33333333 ; + + s->r[PINCTRL_CTRL ] =0xcf000000 ; + +return 0 ; +} + + +static void imx23_pinctrl_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = imx23_pinctrl_init; +} + +static TypeInfo pinctrl_info = { + .name ="imx23_pinctrl" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (imx23_pinctrl_state), + .class_init = imx23_pinctrl_class_init, +}; + +static void imx23_pinctrl_register (void ) +{ +type_register_static (&pinctrl_info); +} + +type_init (imx23_pinctrl_register) --
Quoted 1 line
1.8.5.1
I stopped reviewing at this patch; you should probably start by fixing the points I mentioned for all your patches, and then post a v2 series.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 07/13] mxs/imx23: Implements the pin mux, GPIOs
All noted, and thanks for all the bits you reviewed so far, I'll do the changes and resubmit.
M
Quoted 368 lines · Peter Maydell
Quoted 8 lines · Michel Pollet
Implements the pinctrl and GPIO block for the imx23 It handles GPIO output, and GPIO input from qemu translated into pin values and interrupts, if appropriate.
Signed-off-by Michel Pollet <[email protected]>--- hw/arm/Makefile.objs | 2 +- hw/arm/imx23_pinctrl.c | 293+++++++++++++++++++++++++++++++++++++++++++++++++
hw/arm/Makefile.objs obj-y += tosa.o versatilepb.o vexpress.o virt.o
Quoted 8 lines
2 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 hw/arm/imx23_pinctrl.chw/arm/Makefile.objs +0
-0@@ -5,4 +5,4 @@ obj-y += tosa.o versatilepb.o vexpress.o virt.oxilinx_zynq.o z2.o
Quoted 27 lines
hw/arm/Makefile.objs +1
-1obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o -obj-$(CONFIG_MXS) += imx23_digctl.o +obj-$(CONFIG_MXS) += imx23_digctl.o imx23_pinctrl.ohw/arm/imx23_pinctrl.c new file +16
-0@@ -0,0 +1,293 @@ +/* +* imx23_pinctrl.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ + +/* +* Implements the pinctrl and GPIO block for the imx23 +* It handles GPIO output, and GPIO input from qemu translated +* into pin values and interrupts, if appropriate. +*/ +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" +hw/arm/imx23_pinctrl.c line 26
Quoted 10 lines
hw/arm/imx23_pinctrl.c new file +10
-0+#define D (w) + +enum { +PINCTRL_BANK_COUNT =3 , + +PINCTRL_CTRL =0 , +PINCTRL_BANK_MUXSEL =0x10 , +PINCTRL_BANK_BASE =0x40 , + +/* these are not << 4 register numbers, these are << 8 register numbers */
Quoted 57 lines
hw/arm/imx23_pinctrl.c new file +57
-0+PINCTRL_BANK_PULL =0x4 , +PINCTRL_BANK_OUT =0x5 , +PINCTRL_BANK_DIN =0x6 , +PINCTRL_BANK_DOE =0x7 , +PINCTRL_BANK_PIN2IRQ =0x8 , +PINCTRL_BANK_IRQEN =0x9 , +PINCTRL_BANK_IRQLEVEL =0xa , +PINCTRL_BANK_IRQPOL =0xb , +PINCTRL_BANK_IRQSTAT =0xc , + +PINCTRL_BANK_INTERNAL_STATE =0xd , + PINCTRL_MAX = 0xe0, +}; + +#define PINCTRL_BANK_REG (_bank, _reg) ((_reg << 8) | (_bank << 4)) + +enum { +MUX_GPIO =0x3 , +}; + + +typedef struct imx23_pinctrl_state { +SysBusDevice busdev; +MemoryRegion iomem; + +uint32_t r[PINCTRL_MAX ]; +qemu_irq irq_in[3 ]; +qemu_irq irq_out[PINCTRL_BANK_COUNT *32 ]; + +uint32_t state[PINCTRL_BANK_COUNT ]; +}imx23_pinctrl_state ; + +static uint64_t imx23_pinctrl_read ( +void *opaque,hwaddr offset,unsigned size) +{ +imx23_pinctrl_state *s = (imx23_pinctrl_state *) opaque; +uint32_t res =0 ; + +switch (offset >>4 ) { + case 0 ... PINCTRL_MAX: + res = s->r[offset >>4 ]; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } + +return res; +} + +static uint8_t imx23_pinctrl_getmux ( +imx23_pinctrl_state *s,int pin) +{ +int base = pin /16 , offset = pin %16 ; +return (s->r[PINCTRL_BANK_MUXSEL + base] >> (offset *2 )) &0x3 ; +}hw/arm/imx23_pinctrl.c
Quoted 10 lines
hw/arm/imx23_pinctrl.c new file +10
-0+ +/* +* usage imx23_pinctrl_getbit(s, PINCTRL_BANK_IRQEN, 48)... +*/ +static uint8_t imx23_pinctrl_getbit ( +imx23_pinctrl_state *s,uint16_t reg,int pin) +{ +int bank = pin /32 , offset = pin %32 ; +uint32_t * latch = &s->r[PINCTRL_BANK_REG (bank, reg) >>4 ]; +// printf("%s bank %d offset %d reg %d : %04x=%08x\n", __func__, bank, offset, reg,
hw/arm/imx23_pinctrl.c line 104
Quoted 11 lines
hw/arm/imx23_pinctrl.c new file +11
-0+// PINCTRL_BANK_REG(bank, reg), +// *latch); +return (*latch >> offset) &0x1 ; +} + +static void imx23_pinctrl_setbit ( +imx23_pinctrl_state *s,uint16_t reg,int pin,int value) +{ +int bank = pin /32 , offset = pin %32 ; +uint32_t * latch = &s->r[PINCTRL_BANK_REG (bank, reg) >>4 ]; + *latch = (*latch & ~(1 << offset)) | (!!value << offset);
deposit32()will make this clearer to read.hw/arm/imx23_pinctrl.c
Quoted 11 lines
hw/arm/imx23_pinctrl.c new file +11
-0+} + +static void imx23_pinctrl_write_bank ( +imx23_pinctrl_state *s,int bank, +int reg,uint32_t value, +uint32_t mask) +{ +int set, pin; +switch (reg) { +/* +* Linux has a way of using the DOE&PULL register to toggle the pin
hw/arm/imx23_pinctrl.c line 116
Quoted 1 line
hw/arm/imx23_pinctrl.c new file +1
-0+*/ Why is this comment here? We should ideally not care what guest OS we run, we should just implement the h/w correctly.
hw/arm/imx23_pinctrl.c
Quoted 13 lines
hw/arm/imx23_pinctrl.c new file +13
-0+case PINCTRL_BANK_PULL : +case PINCTRL_BANK_DOE : +/* +* Writing to the Data OUT register just triggers the +* output qemu IRQ for any further peripherals +*/ +case PINCTRL_BANK_OUT : { +while ((set =ffs (mask)) >0 ) { + set--; + mask &= ~(1 << set); + pin = (bank *32 ) + set; +/* +* For a reason that is not clear, the pullup bit appears
hw/arm/imx23_pinctrl.c line 131
Quoted 2 lines
hw/arm/imx23_pinctrl.c new file +2
-0+* inverted (!) ignoring for now, assume hardware pullup +*/ You should figure out what's actually happening here...
hw/arm/imx23_pinctrl.c
Quoted 4 lines
hw/arm/imx23_pinctrl.c new file +4
-0+// imx23_pinctrl_getbit(s, PINCTRL_BANK_PULL, pin) +int val = + imx23_pinctrl_getbit(s, PINCTRL_BANK_DOE, pin) ? + imx23_pinctrl_getbit(s,
PINCTRL_BANK_OUT, pin) :hw/arm/imx23_pinctrl.c line 137
Quoted 2 lines
hw/arm/imx23_pinctrl.c new file +2
-0+1 ; + D(printf("%s set %2d to OUT:%d DOE:%d (PULL:%d) =%d\n",
__func__,hw/arm/imx23_pinctrl.c
Quoted 7 lines
hw/arm/imx23_pinctrl.c new file +7
-0+ pin, +imx23_pinctrl_getbit (s,PINCTRL_BANK_OUT , pin), +imx23_pinctrl_getbit (s,PINCTRL_BANK_DOE , pin), +imx23_pinctrl_getbit (s,PINCTRL_BANK_PULL , pin), + val);) + + if (imx23_pinctrl_getbit(s,
PINCTRL_BANK_INTERNAL_STATE, pin) != val) {hw/arm/imx23_pinctrl.c line 146
Quoted 2 lines
hw/arm/imx23_pinctrl.c new file +2
-0+qemu_set_irq (s->irq_out[pin], val); + imx23_pinctrl_setbit(s,
PINCTRL_BANK_INTERNAL_STATE, pin, val);Quoted 16 lines
hw/arm/imx23_pinctrl.c new file +16
-0+ } + } + }break ; +/* +* This happends when we receive a qemu IRQ on the input ones, +* the register gets updated by the code executed until now, +* and all we need to do here is to trigger the imx233 IRQ +* if appropriate. +* Doing a write to these registers from guest code will acts as +* a software interrupt, not entirely sure this is appropriate +*/ +case PINCTRL_BANK_DIN : { +while ((set =ffs (mask)) >0 ) { + set--; + mask &= ~(1 << set); + pin = (bank *32 ) + set;hw/arm/imx23_pinctrl.c
Quoted 10 lines
hw/arm/imx23_pinctrl.c new file +10
-0+D (printf ("%s input %2d set to %d\n" , __func__, + pin, !!(value & (1 << set)));) + // its it a GPIO ? +if (imx23_pinctrl_getmux (s, pin) !=MUX_GPIO ) { +break ; + } +// if the new value matches the polarity bit, it's the +// edge the guy wanted. +int valid_irq = ((value >> set) &1 ) == + imx23_pinctrl_getbit(s, PINCTRL_BANK_IRQPOL,pin);
hw/arm/imx23_pinctrl.c line 174
Quoted 2 lines
hw/arm/imx23_pinctrl.c new file +2
-0+if (valid_irq) { + if (imx23_pinctrl_getbit(s, PINCTRL_BANK_PIN2IRQ,pin)) {
hw/arm/imx23_pinctrl.c line 175
Quoted 1 line
hw/arm/imx23_pinctrl.c new file +1
-0+ imx23_pinctrl_setbit(s, PINCTRL_BANK_IRQSTAT,pin, 1);
hw/arm/imx23_pinctrl.c
Quoted 3 lines
hw/arm/imx23_pinctrl.c new file +3
-0+ } +// is the interrupt enabled? + if (imx23_pinctrl_getbit(s, PINCTRL_BANK_IRQEN,pin)) {
Quoted 5 lines
hw/arm/imx23_pinctrl.c new file +5
-0+qemu_irq_raise (s->irq_in[bank]); + } + } + } + }break ;hw/arm/imx23_pinctrl.c
Quoted 10 lines
hw/arm/imx23_pinctrl.c new file +10
-0+ } +} + +static void imx23_pinctrl_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +imx23_pinctrl_state *s = (imx23_pinctrl_state *) opaque; +uint32_t oldvalue =0 ; + +// printf("%s offset %04x value %08x\n", __func__, (int)offset, (int)value);
All this commented out debug code needs to go.
hw/arm/imx23_pinctrl.c
Quoted 3 lines
hw/arm/imx23_pinctrl.c new file +3
-0+switch (offset >>4 ) { + case 0 ... PINCTRL_MAX: + oldvalue = mxs_write(&s->r[offset >> 4], offset, value,size);
Quoted 10 lines
hw/arm/imx23_pinctrl.c new file +10
-0+break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } +switch (offset >>4 ) { +case PINCTRL_CTRL : +if ((oldvalue ^ s->r[PINCTRL_CTRL ]) ==0x80000000 + && !(oldvalue &0x80000000 )) {hw/arm/imx23_pinctrl.c
Quoted 10 lines
hw/arm/imx23_pinctrl.c new file +10
-0+// printf("%s reseting, anding clockgate\n", __func__); + s->r[PINCTRL_CTRL ] |=0x40000000 ; + } +break ; + case PINCTRL_BANK_BASE ... PINCTRL_MAX: { +int bank = (offset >>4 ) &0xf ; +int reg = (offset >>8 ); +uint32_t mask = oldvalue ^ s->r[offset >>4 ]; +// printf("%s b %d r %x input %08x mask %08x value %08x\n", +// __func__, bank, reg, (int)value, mask, s->r[offset >> 4]);
hw/arm/imx23_pinctrl.c
Quoted 8 lines
hw/arm/imx23_pinctrl.c new file +8
-0+imx23_pinctrl_write_bank (s, bank, reg, + s->r[offset >>4 ], mask); + }break ; + } +} + +/* +* This will interfaces qemu other components back to the guest input pins
Quoted 13 lines
hw/arm/imx23_pinctrl.c new file +13
-0+*/ +static void imx23_pinctrl_set_irq (void *opaque,int irq,int level) +{ +// simulate a write to the data IN address +int bank = irq /32 ; +hwaddr offset = +PINCTRL_BANK_REG (bank,PINCTRL_BANK_DIN ); +uint64_t value = (1 << (irq %32 )); + D(printf("%s %d = %d\n", __func__, irq, level);) +imx23_pinctrl_write (opaque, + offset + (level ?0x4 :0x8 ), + value,4 ); +}hw/arm/imx23_pinctrl.c
Quoted 10 lines
hw/arm/imx23_pinctrl.c new file +10
-0+ +static const MemoryRegionOps imx23_pinctrl_ops = { + .read = imx23_pinctrl_read, + .write = imx23_pinctrl_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static int imx23_pinctrl_init (SysBusDevice *dev) +{ + imx23_pinctrl_state *s = OBJECT_CHECK(imx23_pinctrl_state, dev,"
imx23_pinctrl");hw/arm/imx23_pinctrl.c line 252
Quoted 5 lines
hw/arm/imx23_pinctrl.c new file +5
-0+int i; +DeviceState *qdev =DEVICE (dev); + +// NEEDED for qdev_find_recursive to work + qdev->id ="imx23_pinctrl" ;This looks suspicious. Nobody else needs to set
qdev->id, why is your device special?hw/arm/imx23_pinctrl.c line 253
Quoted 1 line
hw/arm/imx23_pinctrl.c new file +1
-0+ qdev_init_gpio_in(qdev, imx23_pinctrl_set_irq, 32 *
PINCTRL_BANK_COUNT);Quoted 41 lines
hw/arm/imx23_pinctrl.c new file +40
-1+qdev_init_gpio_out (qdev, s->irq_out,ARRAY_SIZE (s->irq_out)); +memory_region_init_io (&s->iomem,OBJECT (s), &imx23_pinctrl_ops, s, +"imx23_pinctrl" ,0x2000 ); +sysbus_init_mmio (dev, &s->iomem); + +for (i =0 ; i <PINCTRL_BANK_COUNT ; i++) { +sysbus_init_irq (dev, &s->irq_in[i]); + s->r[PINCTRL_BANK_REG (i,PINCTRL_BANK_DIN ) >>4 ] =0 ; + s->r[PINCTRL_BANK_REG (i,PINCTRL_BANK_PULL ) >>4 ] =0xffffffff ; + } +/* set default mux values */ +for (i =0 ; i <8 ; i++) + s->r[(0x100 >>4 ) + i] =0x33333333 ; + + s->r[PINCTRL_CTRL ] =0xcf000000 ; + +return 0 ; +} + + +static void imx23_pinctrl_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = imx23_pinctrl_init; +} + +static TypeInfo pinctrl_info = { + .name ="imx23_pinctrl" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (imx23_pinctrl_state), + .class_init = imx23_pinctrl_class_init, +}; + +static void imx23_pinctrl_register (void ) +{ +type_register_static (&pinctrl_info); +} + +type_init (imx23_pinctrl_register) --Quoted 1 line
1.8.5.1
I stopped reviewing at this patch; you should probably start by fixing the points I mentioned for all your patches, and then post a v2 series.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 06/13] mxs/imx23: Add digctl driver
In reply to Peter MaydellQuoted 63 lines · Peter Maydell
On 11 December 2013 13:56, Michel Pollet <[email protected]> wrote:
This implements just enough of the digctl IO block to allow
Quoted 6 lines
linux to believe it's running on (currently only) an imx23.
Signed-off-by Michel Pollet <[email protected]>--- hw/arm/Makefile.objs | 1 + hw/arm/imx23_digctl.c | 110++++++++++++++++++++++++++++++++++++++++++++++++++
hw/arm/Makefile.objs obj-y += tosa.o versatilepb.o vexpress.o virt.o
Quoted 8 lines
2 files changed, 111 insertions(+) create mode 100644 hw/arm/imx23_digctl.chw/arm/Makefile.objs +0
-0@@ -5,3 +5,4 @@ obj-y += tosa.o versatilepb.o vexpress.o virt.oxilinx_zynq.o z2.o
Quoted 10 lines
hw/arm/Makefile.objs +1
-0obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o +obj-$(CONFIG_MXS) += imx23_digctl.ohw/arm/imx23_digctl.c new file +0
-0hw/arm/imx23_digctl.c line 10
Quoted 10 lines
hw/arm/imx23_digctl.c new file +10
-0@@ -0,0 +1,110 @@ +/* +* imx23_digctl.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ + +/* +* This module implements a very basic IO block for the digctl of the imx23
hw/arm/imx23_digctl.c line 11
Quoted 1 line
hw/arm/imx23_digctl.c new file +1
-0+* Basically there is no real logic, just constant registers return, the most
hw/arm/imx23_digctl.c
Quoted 4 lines
hw/arm/imx23_digctl.c new file +4
-0+* used one bing the "chip id" that is used by the various linux drivers +* to differentiate between imx23 and 28. +* +* The module consists mostly of read/write registers that the bootloader and
hw/arm/imx23_digctl.c line 16
Quoted 1 line
hw/arm/imx23_digctl.c new file +1
-0+* kernel are quite happy to 'set' to whatever value they believe they set...
Quoted 14 lines
hw/arm/imx23_digctl.c new file +14
-0+*/ + +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +enum { +HW_DIGCTL_RAMCTL =0x3 , +HW_DIGCTL_CHIPID =0x31 , +}; + +typedef struct imx23_digctl_state { + SysBusDevice busdev; + MemoryRegion iomem; +
Quoted 9 lines
hw/arm/imx23_digctl.c line 32
Quoted 2 lines
hw/arm/imx23_digctl.c new file +2
-0+uint32_t reg[0x2000 /4 ]; +} imx23_digctl_state;I'm not generally a fan of "big reg[] array" like this. In real hardware are these typically constant read/only registers, or do they actually do something? Does the hardware really have a full set of 2048 registers here, or are there gaps?
This block contains most of the 'general purpose' registers, ram timing and all that jazz; there are a lot of write to it at init time, but it's otherwise mostly ignored. Also, there's very little to do about it functionally for qemu's purpose.
Quoted 9 lines
I'd rather have us implement just the minimal set required for things to boot, with
LOG_UNIMP(and read-zero/write-ignored) for the rest. That makes it easier to add actual implementations later (and your migration state is not0x2000bytes of random undifferentiated stuff).
I will re-add the trace for both write and read and see if I can narrow the range down; it will be linux specific, tho, that's why I thought a 'catchall' block was more appropriate.
Quoted 3 lines
thanks
-- PMM
Thanks,
M
Re: [Qemu-devel] [PATCH 06/13] mxs/imx23: Add digctl driver
Quoted 3 lines · M P
I will re-add the trace for both write and read and see if I can narrow the range down; it will be linux specific, tho, that's why I thought a 'catchall' block was more appropriate.
Well, we should be implementing what the hardware does, generally. Misimplementing things as "read as written" isn't really any better than misimplementing them as RAZ/WI, it's just differently wrong.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 04/13] mxs/imx23: Add DMA driver
In reply to Peter MaydellQuoted 96 lines · Peter Maydell
Quoted 81 lines · Michel Pollet
This driver works sufficiently well that linux can use it to access the SD card using the
SD->DMA->SSI->SD. It hasn't been tested for much else.Signed-off-by Michel Pollet <[email protected]>--- hw/dma/Makefile.objs | 1 + hw/dma/mxs_dma.c | 347 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 hw/dma/mxs_dma.chw/dma/Makefile.objs +1
-0@@ -8,6 +8,7 @@ common-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o common-obj-$(CONFIG_ETRAXFS) += etraxfs_dma.o common-obj-$(CONFIG_STP2000) += sparc32_dma.o common-obj-$(CONFIG_SUN4M) += sun4m_iommu.o +common-obj-$(CONFIG_MXS) += mxs_dma.o obj-$(CONFIG_OMAP) += omap_dma.o soc_dma.o obj-$(CONFIG_PXA2XX) += pxa2xx_dma.ohw/dma/mxs_dma.c new file +52
-0@@ -0,0 +1,347 @@ +/* +* mxs_dma.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ + +/* +* Implements the DMA block of the mxs. +* The current implementation can run chains of commands etc, however it's only +* been tested with SSP for SD/MMC card access. It ought to work with normal SPI +* too, and possibly other peripherals, however it's entirely untested +*/ +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +/* +* DMA IO block register numbers +*/ +enum { +DMA_CTRL0 =0x0 , +DMA_CTRL1 =0x1 , +DMA_CTRL2 =0x2 , +DMA_DEVSEL1 =0x3 , +DMA_DEVSEL2 =0x4 , +DMA_MAX , + +/* +* The DMA block for APBH and APBX have a different base address, +* but they share a 7 words stride between channels. +*/ +DMA_STRIDE =0x70 , +/* +* Neither blocks uses that many, but there is space for them... +*/ +DMA_MAX_CHANNELS =16 , +}; + +/* +* DMA channel register numbers +*/ +enum { +CH_CURCMD =0 , +CH_NEXTCMD =1 , +CH_CMD =2 , +CH_BUFFER_ADDR =3 , +CH_SEMA =4 , +CH_DEBUG1 =5 , +CH_DEBUG2 =6 , +}; +hw/dma/mxs_dma.c line 62
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+/* +* Channel command bit numbers +*/ +enum { +CH_CMD_IRQ_COMPLETE =3 , +CH_CMD_SEMAPHORE =6 , +}; + +/* +* nicked from linux You don't need to say that, it doesn't really add any information to the reader.
Quoted 11 lines
hw/dma/mxs_dma.c line 69
Quoted 7 lines
hw/dma/mxs_dma.c new file +7
-0+* this is the memory representation of a DMA request +*/ +struct mxs_dma_ccw { +uint32_t next; +uint16_t bits; +uint16_t xfer_bytes; +#define MAX_XFER_BYTES 0xff00I'd rather have the #defines before the struct than interleaved, personally.
TBH, this is the same as my own preferred personal coding style (and I refactor on upstreaming due to it's contention). I'd like to push for it's general acceptance. #defining at the point of relevance is a well adopted concept and makes code much more readable.
Quoted 23 lines
hw/dma/mxs_dma.c line 73
Quoted 4 lines
hw/dma/mxs_dma.c new file +4
-0+uint32_t bufaddr; +#define MXS_PIO_WORDS 16 +uint32_t pio_words[MXS_PIO_WORDS ]; +}__attribute__((packed));If you need to use packed then always use the
QEMU_PACKEDmacro; this ensures the same layout on all host platforms (Windows behaviour of plain attribute packed is different).hw/dma/mxs_dma.c line 83
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+ +/* +* Per channel DMA description +*/ +typedef struct mxs_dma_channel { + QEMUTimer *timer; + struct mxs_dma_state *dma; + int channel; // channel index + hwaddr base; // base of peripheral + hwaddr dataoffset; // offset of the true in/out data latch registerNo C++-style comments, please.
Quoted 7 lines
hw/dma/mxs_dma.c line 90
Quoted 7 lines
hw/dma/mxs_dma.c new file +7
-0+uint32_t r[10 ]; +qemu_irq irq; +} mxs_dma_channel; + + +typedef struct mxs_dma_state { + SysBusDevice busdev;
parent_obj. Check your QOM style.
http://lists.gnu.org/archive/html/qemu-devel/2013-02/msg05045.html
Quoted 47 lines
Quoted 8 lines
hw/dma/mxs_dma.c new file +8
-0+MemoryRegion iomem; +const char * name; + +struct soc_dma_s * dma; +uint32_t r[DMA_MAX ]; + +hwaddr base;// base of peripheral +mxs_dma_channel channel[DMA_MAX_CHANNELS ];hw/dma/mxs_dma.c line 108
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+} mxs_dma_state; + +static void mxs_dma_ch_update (mxs_dma_channel *s) +{ +struct mxs_dma_ccw req; +int i; + +/* increment the semaphore, if needed */ + s->r[CH_SEMA ] = (((s->r[CH_SEMA ] >>16 ) &0xff ) + + (s->r[CH_SEMA ] &0xff )) <<16 ;This is confusing -- what's it actually doing?
hw/dma/mxs_dma.c line 113
Quoted 5 lines
hw/dma/mxs_dma.c new file +5
-0+if (!((s->r[CH_SEMA ] >>16 ) &0xff )) { +return ; + } +/* read the request from memory */ +cpu_physical_memory_read (s->r[CH_NEXTCMD ], &req,sizeof (req));This will not work if your host and target have opposite endianness. If you're going to read the whole struct in at once like this you need to use the cpu_to_le* functions to swap all its members to the host endianness. Similarly anywhere you write a block of memory back. Alternatively you can use the ld*_le_phys and st*_le_phys to read and write specifically sized bytes/shorts/words to little-endian guest order.
hw/dma/mxs_dma.c line 123
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+/* update the latch registers accordingly */ + s->r[CH_CURCMD ] = s->r[CH_NEXTCMD ]; + s->r[CH_NEXTCMD ] = req.next; + s->r[CH_CMD ] = (req.xfer_bytes <<16 ) | req.bits; + s->r[CH_BUFFER_ADDR ] = req.bufaddr; + +/* write PIO registers first, if any */ +for (i =0 ; i < (req.bits >>12 ); i++) { +cpu_physical_memory_rw (s->base + (i <<4 ), + (uint8_t *) &req.pio_words[i],4 ,1 );
Quoted 3 lines
...for instance this is probably best done via
stl_le_phys()to write each word to the guest memory.
Last I knew, dma_memory_read|write is the correct way to do DMA from device land. cpu_physical_memory and stl_ are more CPU concepts. dma_memory_read|write has the added advantage of accepting and address_space which allows for DMA in machines with non-flat bus/memory layouts.
Quoted 37 lines
Quoted 37 lines
hw/dma/mxs_dma.c new file +37
-0+ } +/* next handle any "data" requests */ +switch (req.bits &0x3 ) { +case 0 : +break ;// PIO only +case 0x1 : {// WRITE (from periph to memory) +uint32_t buf = req.bufaddr; +uint8_t b =0 ; +while (req.xfer_bytes--) { +cpu_physical_memory_rw (s->base + s->dataoffset, &b,1 ,0 ); +cpu_physical_memory_rw (buf, &b,1 ,1 ); + buf++; + } + }break ; +case 0x2 : {// READ (from memory to periph) +uint32_t buf = req.bufaddr; +uint8_t b =0 ; +while (req.xfer_bytes--) { +cpu_physical_memory_rw (buf, &b,1 ,0 ); +cpu_physical_memory_rw (s->base + s->dataoffset, &b,1 ,1 ); + buf++; + } + }break ; + } + + s->dma->r[DMA_CTRL1 ] |=1 << s->channel; +/* trigger IRQ if requested */ +if ((s->dma->r[DMA_CTRL1 ] >>16 ) & (1 << s->channel)) { +if (req.bits & (1 <<CH_CMD_IRQ_COMPLETE )) { +qemu_set_irq (s->irq,1 ); + } + } + +/* decrement semaphore if requested */ +if (s->r[CH_CMD ] & (1 <<CH_CMD_SEMAPHORE )) { + s->r[CH_SEMA ] = (((s->r[CH_SEMA ] >>16 ) &0xff ) -1 ) <<16 ; + }
Quoted 9 lines
hw/dma/mxs_dma.c line 164
Quoted 4 lines
hw/dma/mxs_dma.c new file +4
-0+/* If the semaphore is still on, try to trigger a chained request */ +if ((s->r[CH_SEMA ] >>16 ) &0xff ) { +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +timer_mod (s->timer, now +10 );This stuff involving the timer looks a bit fishy, but I'm not really up on current best practice with DMA, timers, etc. Peter Crosthwaite may have a more informed opinion.
I'll take a step back and do a full series review. As of this mail all i've done is a quick style scan, so ill go more in-depth on either this V2 or this if Michel respins. Give me a few days. Don't wait for me, I'd prefer to look at v2 as PMM has already asked a good number of changes. cc me for a speedy review.
Quoted 60 lines
Quoted 48 lines
hw/dma/mxs_dma.c new file +48
-0+ } +} + +/* called on one shot timer activation */ +static void mxs_dma_ch_run (void *opaque) +{ +mxs_dma_channel *s = opaque; +mxs_dma_ch_update (s); +} + +static uint64_t mxs_dma_read (void *opaque,hwaddr offset,unsigned size) +{ +mxs_dma_state *s = (mxs_dma_state *) opaque; +uint32_t res =0 ; + +switch (offset >>4 ) { + case 0 ... DMA_MAX - 1: + res = s->r[offset >>4 ]; +break ; +default : +if (offset >= s->base) { + offset -= s->base; +int channel = offset /DMA_STRIDE ; +int word = (offset %DMA_STRIDE ) >>4 ; + res = s->channel[channel].r[word]; + }else +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } + +return res; +} + +static void mxs_dma_write (void *opaque,hwaddr offset,uint64_t value, +unsigned size) +{ +mxs_dma_state *s = (mxs_dma_state *) opaque; +uint32_t oldvalue =0 ; +int channel, word, i; + +switch (offset >>4 ) { + case 0 ... DMA_MAX - 1: + oldvalue =mxs_write (&s->r[offset >>4 ], offset, value, size); +break ; +default : +if (offset >= s->base) { + channel = (offset - s->base) /DMA_STRIDE ;hw/dma/mxs_dma.c line 222
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+ word = (offset - s->base) %DMA_STRIDE ; + oldvalue =mxs_write ( + &s->channel[channel].r[word >>4 ], word, + value, size); +switch (word >>4 ) { +case CH_SEMA : +// mask the new semaphore value, as only the lowest 8 bits are RW + s->channel[channel].r[CH_SEMA ] = + (oldvalue & ~0xff ) | + (s->channel[channel].r[CH_SEMA ] &0xff );You can do this with
Quoted 3 lines
s->channel[channel].r[CH_SEMA] = deposit32(oldvalue, 0, 8,
s->channel[channel].r[CH_SEMA]);And more generally speaking, favor the extract32/deposit32 macros rather than shift/mask.
Quoted 34 lines
Quoted 34 lines
hw/dma/mxs_dma.c new file +34
-0+mxs_dma_ch_update (&s->channel[channel]); +break ; + } + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); + } +break ; + } +switch (offset >>4 ) { +case DMA_CTRL0 : +if ((oldvalue ^ s->r[DMA_CTRL0 ]) ==0x80000000 + && !(oldvalue &0x80000000 )) { +// printf("%s write reseting, anding clockgate\n", s->name); + s->r[DMA_CTRL0 ] |=0x40000000 ; + } +break ; +case DMA_CTRL1 : +for (i =0 ; i <DMA_MAX_CHANNELS ; i++) +if (s->channel[i].r[CH_NEXTCMD ] && + !(s->r[DMA_CTRL1 ] & (1 << i))) { +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +/* add a bit of latency to the timer. Ideally would +* do some calculation proportional to the transfer +* size. TODO ? +*/ +timer_mod (s->channel[i].timer, now +100000 ); + } +break ; + } +} + + +static const MemoryRegionOps mxs_dma_ops = {
Quoted 8 lines
hw/dma/mxs_dma.c line 264
Quoted 8 lines
hw/dma/mxs_dma.c new file +8
-0+ .read = mxs_dma_read, + .write = mxs_dma_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void mxs_dma_common_init (mxs_dma_state *s) +{ +int i;
blank line here.
Quoted 24 lines
Quoted 24 lines
hw/dma/mxs_dma.c new file +24
-0+memory_region_init_io (&s->iomem,OBJECT (s), &mxs_dma_ops, s,"mxs_dma" ,0x2000 ); +sysbus_init_mmio (&s->busdev, &s->iomem); +for (i =0 ; i <DMA_MAX_CHANNELS ; i++) { + s->channel[i].dma = s; + s->channel[i].channel = i; + s->channel[i].timer = +timer_new_ns (QEMU_CLOCK_VIRTUAL , mxs_dma_ch_run, &s->channel[i]); + } +} + +static int mxs_apbh_dma_init (SysBusDevice *dev) +{ +mxs_dma_state *s =OBJECT_CHECK (mxs_dma_state, dev,"mxs_apbh_dma" ); + +mxs_dma_common_init (s); + s->name ="dma_apbh" ; + s->base =0x40 ; +sysbus_init_irq (dev, &s->channel[MX23_DMA_SSP1 ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_SSP2 ].irq); + s->channel[MX23_DMA_SSP1 ].base =MX23_SSP1_BASE_ADDR ; + s->channel[MX23_DMA_SSP1 ].dataoffset =0x70 ; + s->channel[MX23_DMA_SSP2 ].base =MX23_SSP2_BASE_ADDR ; + s->channel[MX23_DMA_SSP2 ].dataoffset =0x70 ; +
Quoted 8 lines
hw/dma/mxs_dma.c line 296
Quoted 8 lines
hw/dma/mxs_dma.c new file +8
-0+return 0 ; +} + +static int mxs_apbx_dma_init (SysBusDevice *dev) +{ +// mxs_dma_state *s = FROM_SYSBUS(mxs_dma_state, dev); +mxs_dma_state *s =OBJECT_CHECK (mxs_dma_state, dev,"mxs_apbx_dma" ); +
Define your own proper QOM cast macro rather than an inplace OBJECT_CHECK.
Quoted 4 lines
Quoted 4 lines
hw/dma/mxs_dma.c new file +4
-0+mxs_dma_common_init (s); + s->name ="dma_apbx" ; + s->base =0x100 ; +sysbus_init_irq (dev, &s->channel[MX23_DMA_ADC ].irq);
Quoted 8 lines
hw/dma/mxs_dma.c line 308
Quoted 8 lines
hw/dma/mxs_dma.c new file +8
-0+sysbus_init_irq (dev, &s->channel[MX23_DMA_DAC ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_SPDIF ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_I2C ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_SAIF0 ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART0_RX ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART0_TX ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART1_RX ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART1_TX ].irq);
So this is a little suspicious. It looks to me like your device is system aware. A self contained DMA controller should not really know what its DMAing for. Are the connections to I2C, UART and friends actually specified in the DMA core documentation or is this SoC/Board level connectivity?
Quoted 10 lines
hw/dma/mxs_dma.c line 318
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+sysbus_init_irq (dev, &s->channel[MX23_DMA_SAIF1 ].irq); + +return 0 ; +} + +static void mxs_apbh_dma_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_apbh_dma_init;
use of SysBusDevice::init is depracted. Please use object::init or Device::realize instead. Check the more recently committed device models (Allwinner and Digic are two series that went in recently) for examples of init styling.
Quoted 11 lines
hw/dma/mxs_dma.c line 326
Quoted 8 lines
hw/dma/mxs_dma.c new file +8
-0+} + +static void mxs_apbx_dma_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_apbx_dma_init; +}Needs reset and vmstate.
Quoted 7 lines
hw/dma/mxs_dma.c line 333
Quoted 7 lines
hw/dma/mxs_dma.c new file +7
-0+ +static TypeInfo apbh_dma_info = { + .name ="mxs_apbh_dma" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_dma_state), + .class_init = mxs_apbh_dma_class_init, +};
Blank line.
Quoted 7 lines
hw/dma/mxs_dma.c line 340
Quoted 7 lines
hw/dma/mxs_dma.c new file +7
-0+static TypeInfo apbx_dma_info = { + .name ="mxs_apbx_dma" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_dma_state), + .class_init = mxs_apbx_dma_class_init, +}; +
As a general rule, you should have a QOM class for the common base device. You then have two derived classes that add their little bit. One functional reason for this, is without a common base it's impossible to create a QOM cast macro for the shared functionality (without an actual class to tie it to).
Regards,
Peter
Quoted 13 lines
Quoted 9 lines
hw/dma/mxs_dma.c new file +7
-1+static void mxs_dma_register (void ) +{ +type_register_static (&apbh_dma_info); +type_register_static (&apbx_dma_info); +} + +type_init (mxs_dma_register) --1.8.5.1
thanks
-- PMM
Re: [Qemu-devel] [PATCH 04/13] mxs/imx23: Add DMA driver
Quoted 147 lines · Peter Crosthwaite
Quoted 96 lines · Peter Maydell
Quoted 81 lines · Michel Pollet
This driver works sufficiently well that linux can use it to access the SD card using the
SD->DMA->SSI->SD. It hasn't been tested for much else.Signed-off-by Michel Pollet <[email protected]>--- hw/dma/Makefile.objs | 1 + hw/dma/mxs_dma.c | 347 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 hw/dma/mxs_dma.chw/dma/Makefile.objs +1
-0@@ -8,6 +8,7 @@ common-obj-$(CONFIG_XILINX_AXI) += xilinx_axidma.o common-obj-$(CONFIG_ETRAXFS) += etraxfs_dma.o common-obj-$(CONFIG_STP2000) += sparc32_dma.o common-obj-$(CONFIG_SUN4M) += sun4m_iommu.o +common-obj-$(CONFIG_MXS) += mxs_dma.o obj-$(CONFIG_OMAP) += omap_dma.o soc_dma.o obj-$(CONFIG_PXA2XX) += pxa2xx_dma.ohw/dma/mxs_dma.c new file +52
-0@@ -0,0 +1,347 @@ +/* +* mxs_dma.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ + +/* +* Implements the DMA block of the mxs. +* The current implementation can run chains of commands etc, however it's only +* been tested with SSP for SD/MMC card access. It ought to work with normal SPI +* too, and possibly other peripherals, however it's entirely untested +*/ +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +/* +* DMA IO block register numbers +*/ +enum { +DMA_CTRL0 =0x0 , +DMA_CTRL1 =0x1 , +DMA_CTRL2 =0x2 , +DMA_DEVSEL1 =0x3 , +DMA_DEVSEL2 =0x4 , +DMA_MAX , + +/* +* The DMA block for APBH and APBX have a different base address, +* but they share a 7 words stride between channels. +*/ +DMA_STRIDE =0x70 , +/* +* Neither blocks uses that many, but there is space for them... +*/ +DMA_MAX_CHANNELS =16 , +}; + +/* +* DMA channel register numbers +*/ +enum { +CH_CURCMD =0 , +CH_NEXTCMD =1 , +CH_CMD =2 , +CH_BUFFER_ADDR =3 , +CH_SEMA =4 , +CH_DEBUG1 =5 , +CH_DEBUG2 =6 , +}; +hw/dma/mxs_dma.c line 62
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+/* +* Channel command bit numbers +*/ +enum { +CH_CMD_IRQ_COMPLETE =3 , +CH_CMD_SEMAPHORE =6 , +}; + +/* +* nicked from linux You don't need to say that, it doesn't really add any information to the reader.
Quoted 11 lines
hw/dma/mxs_dma.c line 69
Quoted 7 lines
hw/dma/mxs_dma.c new file +7
-0+* this is the memory representation of a DMA request +*/ +struct mxs_dma_ccw { +uint32_t next; +uint16_t bits; +uint16_t xfer_bytes; +#define MAX_XFER_BYTES 0xff00I'd rather have the #defines before the struct than interleaved, personally.
TBH, this is the same as my own preferred personal coding style (and I refactor on upstreaming due to it's contention). I'd like to push for it's general acceptance. #defining at the point of relevance is a well adopted concept and makes code much more readable.
Quoted 23 lines
hw/dma/mxs_dma.c line 73
Quoted 4 lines
hw/dma/mxs_dma.c new file +4
-0+uint32_t bufaddr; +#define MXS_PIO_WORDS 16 +uint32_t pio_words[MXS_PIO_WORDS ]; +}__attribute__((packed));If you need to use packed then always use the
QEMU_PACKEDmacro; this ensures the same layout on all host platforms (Windows behaviour of plain attribute packed is different).hw/dma/mxs_dma.c line 83
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+ +/* +* Per channel DMA description +*/ +typedef struct mxs_dma_channel { + QEMUTimer *timer; + struct mxs_dma_state *dma; + int channel; // channel index + hwaddr base; // base of peripheral + hwaddr dataoffset; // offset of the true in/out data latch registerNo C++-style comments, please.
Quoted 7 lines
hw/dma/mxs_dma.c line 90
Quoted 7 lines
hw/dma/mxs_dma.c new file +7
-0+uint32_t r[10 ]; +qemu_irq irq; +} mxs_dma_channel; + + +typedef struct mxs_dma_state { + SysBusDevice busdev;
parent_obj. Check your QOM style.
Sry bad link, try this:
http://wiki.qemu.org/QOMConventions
Regards,
Peter
Quoted 343 lines
Quoted 47 lines
Quoted 8 lines
hw/dma/mxs_dma.c new file +8
-0+MemoryRegion iomem; +const char * name; + +struct soc_dma_s * dma; +uint32_t r[DMA_MAX ]; + +hwaddr base;// base of peripheral +mxs_dma_channel channel[DMA_MAX_CHANNELS ];hw/dma/mxs_dma.c line 108
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+} mxs_dma_state; + +static void mxs_dma_ch_update (mxs_dma_channel *s) +{ +struct mxs_dma_ccw req; +int i; + +/* increment the semaphore, if needed */ + s->r[CH_SEMA ] = (((s->r[CH_SEMA ] >>16 ) &0xff ) + + (s->r[CH_SEMA ] &0xff )) <<16 ;This is confusing -- what's it actually doing?
hw/dma/mxs_dma.c line 113
Quoted 5 lines
hw/dma/mxs_dma.c new file +5
-0+if (!((s->r[CH_SEMA ] >>16 ) &0xff )) { +return ; + } +/* read the request from memory */ +cpu_physical_memory_read (s->r[CH_NEXTCMD ], &req,sizeof (req));This will not work if your host and target have opposite endianness. If you're going to read the whole struct in at once like this you need to use the cpu_to_le* functions to swap all its members to the host endianness. Similarly anywhere you write a block of memory back. Alternatively you can use the ld*_le_phys and st*_le_phys to read and write specifically sized bytes/shorts/words to little-endian guest order.
hw/dma/mxs_dma.c line 123
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+/* update the latch registers accordingly */ + s->r[CH_CURCMD ] = s->r[CH_NEXTCMD ]; + s->r[CH_NEXTCMD ] = req.next; + s->r[CH_CMD ] = (req.xfer_bytes <<16 ) | req.bits; + s->r[CH_BUFFER_ADDR ] = req.bufaddr; + +/* write PIO registers first, if any */ +for (i =0 ; i < (req.bits >>12 ); i++) { +cpu_physical_memory_rw (s->base + (i <<4 ), + (uint8_t *) &req.pio_words[i],4 ,1 );Quoted 3 lines
...for instance this is probably best done via
stl_le_phys()to write each word to the guest memory.Last I knew, dma_memory_read|write is the correct way to do DMA from device land.
cpu_physical_memoryandstl_are more CPU concepts. dma_memory_read|write has the added advantage of accepting andaddress_spacewhich allows for DMA in machines with non-flat bus/memory layouts.Quoted 37 lines
Quoted 37 lines
hw/dma/mxs_dma.c new file +37
-0+ } +/* next handle any "data" requests */ +switch (req.bits &0x3 ) { +case 0 : +break ;// PIO only +case 0x1 : {// WRITE (from periph to memory) +uint32_t buf = req.bufaddr; +uint8_t b =0 ; +while (req.xfer_bytes--) { +cpu_physical_memory_rw (s->base + s->dataoffset, &b,1 ,0 ); +cpu_physical_memory_rw (buf, &b,1 ,1 ); + buf++; + } + }break ; +case 0x2 : {// READ (from memory to periph) +uint32_t buf = req.bufaddr; +uint8_t b =0 ; +while (req.xfer_bytes--) { +cpu_physical_memory_rw (buf, &b,1 ,0 ); +cpu_physical_memory_rw (s->base + s->dataoffset, &b,1 ,1 ); + buf++; + } + }break ; + } + + s->dma->r[DMA_CTRL1 ] |=1 << s->channel; +/* trigger IRQ if requested */ +if ((s->dma->r[DMA_CTRL1 ] >>16 ) & (1 << s->channel)) { +if (req.bits & (1 <<CH_CMD_IRQ_COMPLETE )) { +qemu_set_irq (s->irq,1 ); + } + } + +/* decrement semaphore if requested */ +if (s->r[CH_CMD ] & (1 <<CH_CMD_SEMAPHORE )) { + s->r[CH_SEMA ] = (((s->r[CH_SEMA ] >>16 ) &0xff ) -1 ) <<16 ; + }Quoted 9 lines
hw/dma/mxs_dma.c line 164
Quoted 4 lines
hw/dma/mxs_dma.c new file +4
-0+/* If the semaphore is still on, try to trigger a chained request */ +if ((s->r[CH_SEMA ] >>16 ) &0xff ) { +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +timer_mod (s->timer, now +10 );This stuff involving the timer looks a bit fishy, but I'm not really up on current best practice with DMA, timers, etc. Peter Crosthwaite may have a more informed opinion.
I'll take a step back and do a full series review. As of this mail all i've done is a quick style scan, so ill go more in-depth on either this V2 or this if Michel respins. Give me a few days. Don't wait for me, I'd prefer to look at v2 as PMM has already asked a good number of changes. cc me for a speedy review.
Quoted 60 lines
Quoted 48 lines
hw/dma/mxs_dma.c new file +48
-0+ } +} + +/* called on one shot timer activation */ +static void mxs_dma_ch_run (void *opaque) +{ +mxs_dma_channel *s = opaque; +mxs_dma_ch_update (s); +} + +static uint64_t mxs_dma_read (void *opaque,hwaddr offset,unsigned size) +{ +mxs_dma_state *s = (mxs_dma_state *) opaque; +uint32_t res =0 ; + +switch (offset >>4 ) { + case 0 ... DMA_MAX - 1: + res = s->r[offset >>4 ]; +break ; +default : +if (offset >= s->base) { + offset -= s->base; +int channel = offset /DMA_STRIDE ; +int word = (offset %DMA_STRIDE ) >>4 ; + res = s->channel[channel].r[word]; + }else +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } + +return res; +} + +static void mxs_dma_write (void *opaque,hwaddr offset,uint64_t value, +unsigned size) +{ +mxs_dma_state *s = (mxs_dma_state *) opaque; +uint32_t oldvalue =0 ; +int channel, word, i; + +switch (offset >>4 ) { + case 0 ... DMA_MAX - 1: + oldvalue =mxs_write (&s->r[offset >>4 ], offset, value, size); +break ; +default : +if (offset >= s->base) { + channel = (offset - s->base) /DMA_STRIDE ;hw/dma/mxs_dma.c line 222
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+ word = (offset - s->base) %DMA_STRIDE ; + oldvalue =mxs_write ( + &s->channel[channel].r[word >>4 ], word, + value, size); +switch (word >>4 ) { +case CH_SEMA : +// mask the new semaphore value, as only the lowest 8 bits are RW + s->channel[channel].r[CH_SEMA ] = + (oldvalue & ~0xff ) | + (s->channel[channel].r[CH_SEMA ] &0xff );You can do this with
Quoted 3 lines
s->channel[channel].r[CH_SEMA] = deposit32(oldvalue, 0, 8, s->channel[channel].r[CH_SEMA]);And more generally speaking, favor the extract32/deposit32 macros rather than shift/mask.
Quoted 34 lines
Quoted 34 lines
hw/dma/mxs_dma.c new file +34
-0+mxs_dma_ch_update (&s->channel[channel]); +break ; + } + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); + } +break ; + } +switch (offset >>4 ) { +case DMA_CTRL0 : +if ((oldvalue ^ s->r[DMA_CTRL0 ]) ==0x80000000 + && !(oldvalue &0x80000000 )) { +// printf("%s write reseting, anding clockgate\n", s->name); + s->r[DMA_CTRL0 ] |=0x40000000 ; + } +break ; +case DMA_CTRL1 : +for (i =0 ; i <DMA_MAX_CHANNELS ; i++) +if (s->channel[i].r[CH_NEXTCMD ] && + !(s->r[DMA_CTRL1 ] & (1 << i))) { +int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +/* add a bit of latency to the timer. Ideally would +* do some calculation proportional to the transfer +* size. TODO ? +*/ +timer_mod (s->channel[i].timer, now +100000 ); + } +break ; + } +} + + +static const MemoryRegionOps mxs_dma_ops = {Quoted 8 lines
hw/dma/mxs_dma.c line 264
Quoted 8 lines
hw/dma/mxs_dma.c new file +8
-0+ .read = mxs_dma_read, + .write = mxs_dma_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void mxs_dma_common_init (mxs_dma_state *s) +{ +int i;blank line here.
Quoted 24 lines
Quoted 24 lines
hw/dma/mxs_dma.c new file +24
-0+memory_region_init_io (&s->iomem,OBJECT (s), &mxs_dma_ops, s,"mxs_dma" ,0x2000 ); +sysbus_init_mmio (&s->busdev, &s->iomem); +for (i =0 ; i <DMA_MAX_CHANNELS ; i++) { + s->channel[i].dma = s; + s->channel[i].channel = i; + s->channel[i].timer = +timer_new_ns (QEMU_CLOCK_VIRTUAL , mxs_dma_ch_run, &s->channel[i]); + } +} + +static int mxs_apbh_dma_init (SysBusDevice *dev) +{ +mxs_dma_state *s =OBJECT_CHECK (mxs_dma_state, dev,"mxs_apbh_dma" ); + +mxs_dma_common_init (s); + s->name ="dma_apbh" ; + s->base =0x40 ; +sysbus_init_irq (dev, &s->channel[MX23_DMA_SSP1 ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_SSP2 ].irq); + s->channel[MX23_DMA_SSP1 ].base =MX23_SSP1_BASE_ADDR ; + s->channel[MX23_DMA_SSP1 ].dataoffset =0x70 ; + s->channel[MX23_DMA_SSP2 ].base =MX23_SSP2_BASE_ADDR ; + s->channel[MX23_DMA_SSP2 ].dataoffset =0x70 ; +Quoted 8 lines
hw/dma/mxs_dma.c line 296
Quoted 8 lines
hw/dma/mxs_dma.c new file +8
-0+return 0 ; +} + +static int mxs_apbx_dma_init (SysBusDevice *dev) +{ +// mxs_dma_state *s = FROM_SYSBUS(mxs_dma_state, dev); +mxs_dma_state *s =OBJECT_CHECK (mxs_dma_state, dev,"mxs_apbx_dma" ); +Define your own proper QOM cast macro rather than an inplace
OBJECT_CHECK.Quoted 4 lines
Quoted 4 lines
hw/dma/mxs_dma.c new file +4
-0+mxs_dma_common_init (s); + s->name ="dma_apbx" ; + s->base =0x100 ; +sysbus_init_irq (dev, &s->channel[MX23_DMA_ADC ].irq);Quoted 8 lines
hw/dma/mxs_dma.c line 308
Quoted 8 lines
hw/dma/mxs_dma.c new file +8
-0+sysbus_init_irq (dev, &s->channel[MX23_DMA_DAC ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_SPDIF ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_I2C ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_SAIF0 ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART0_RX ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART0_TX ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART1_RX ].irq); +sysbus_init_irq (dev, &s->channel[MX23_DMA_UART1_TX ].irq);So this is a little suspicious. It looks to me like your device is system aware. A self contained DMA controller should not really know what its DMAing for. Are the connections to I2C, UART and friends actually specified in the DMA core documentation or is this SoC/Board level connectivity?
Quoted 10 lines
hw/dma/mxs_dma.c line 318
Quoted 10 lines
hw/dma/mxs_dma.c new file +10
-0+sysbus_init_irq (dev, &s->channel[MX23_DMA_SAIF1 ].irq); + +return 0 ; +} + +static void mxs_apbh_dma_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_apbh_dma_init;use of
SysBusDevice::initis depracted. Please useobject::initorDevice::realizeinstead. Check the more recently committed device models (Allwinner and Digic are two series that went in recently) for examples of init styling.Quoted 11 lines
hw/dma/mxs_dma.c line 326
Quoted 8 lines
hw/dma/mxs_dma.c new file +8
-0+} + +static void mxs_apbx_dma_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_apbx_dma_init; +}Needs reset and vmstate.
Quoted 7 lines
hw/dma/mxs_dma.c line 333
Quoted 7 lines
hw/dma/mxs_dma.c new file +7
-0+ +static TypeInfo apbh_dma_info = { + .name ="mxs_apbh_dma" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_dma_state), + .class_init = mxs_apbh_dma_class_init, +};Blank line.
Quoted 7 lines
hw/dma/mxs_dma.c line 340
Quoted 7 lines
hw/dma/mxs_dma.c new file +7
-0+static TypeInfo apbx_dma_info = { + .name ="mxs_apbx_dma" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_dma_state), + .class_init = mxs_apbx_dma_class_init, +}; +As a general rule, you should have a QOM class for the common base device. You then have two derived classes that add their little bit. One functional reason for this, is without a common base it's impossible to create a QOM cast macro for the shared functionality (without an actual class to tie it to).
Regards,
PeterQuoted 13 lines
Quoted 9 lines
hw/dma/mxs_dma.c new file +7
-1+static void mxs_dma_register (void ) +{ +type_register_static (&apbh_dma_info); +type_register_static (&apbx_dma_info); +} + +type_init (mxs_dma_register) --1.8.5.1
thanks
-- PMM
Re: [Qemu-devel] [PATCH 04/13] mxs/imx23: Add DMA driver
In reply to Peter CrosthwaiteQuoted 10 lines · Peter Crosthwaite
Quoted 3 lines · Peter Maydell
I'd rather have the #defines before the struct than interleaved, personally.
TBH, this is the same as my own preferred personal coding style (and I refactor on upstreaming due to it's contention). I'd like to push for it's general acceptance. #defining at the point of relevance is a well adopted concept and makes code much more readable.
I find it kind of weird because it is making use of the fact that the preprocessor really is a separate textual step, when it doesn't actually need to. If we were using enum or 'const int' here you wouldn't be able to interleave like this and I don't think you'd be complaining that the language wasn't flexible enough.
That said, this is really a very minor point as far as I'm concerned so if people think it's reasonable to do I'm happy to let it pass.
Quoted 9 lines
Quoted 3 lines
...for instance this is probably best done via
stl_le_phys()to write each word to the guest memory.Last I knew, dma_memory_read|write is the correct way to do DMA from device land.
cpu_physical_memoryandstl_are more CPU concepts. dma_memory_read|write has the added advantage of accepting andaddress_spacewhich allows for DMA in machines with non-flat bus/memory layouts.
You're probably right, yes. I said I wasn't particularly up on our current practices for DMA :-)
thanks
-- PMM
Re: [Qemu-devel] [PATCH 03/13] mxs/imx23: Add uart driver
In reply to Peter MaydellQuoted 50 lines · Peter Maydell
Quoted 5 lines · Michel Pollet
Prototype driver for the mxs/imx23 uart IO block. This has no real 'uart' functional code, apart from letting itself be initialized by linux without generating a timeout error.
Signed-off-by Michel Pollet <[email protected]>Hi; there are some minor code style/formatting errors with this patch. You can catch these by running the
scripts/checkpatch.plscript on your patches. (It doesn't catch everything, and sometimes it gets confused and gives bogus results, but it's a good sanity check.)Quoted 11 lines
--- hw/char/Makefile.objs | 1 + hw/char/mxs_uart.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 hw/char/mxs_uart.chw/char/Makefile.objs +0
-0hw/char/Makefile.objs common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o · line 22
Quoted 4 lines
hw/char/Makefile.objs +1
-0@@ -19,6 +19,7 @@ common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o common-obj-$(CONFIG_ISA_DEBUG) += debugcon.o common-obj-$(CONFIG_GRLIB) += grlib_apbuart.o common-obj-$(CONFIG_IMX) += imx_serial.o +common-obj-$(CONFIG_MXS) += mxs_uart.oThis should be a
CONFIG_MXS_UART(see remark on earlier patch).Quoted 9 lines
hw/char/Makefile.objs +0
-0common-obj-$(CONFIG_LM32) += lm32_juart.o common-obj-$(CONFIG_LM32) += lm32_uart.o common-obj-$(CONFIG_MILKYMIST) += milkymist-uart.ohw/char/mxs_uart.c new file +0
-0hw/char/mxs_uart.c line 6
Quoted 6 lines
hw/char/mxs_uart.c new file +6
-0@@ -0,0 +1,146 @@ +/* +* mxs_uart.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence This is too vague. If you mean GPLv2 please say so.
Quoted 15 lines
hw/char/mxs_uart.c line 16
Quoted 10 lines
hw/char/mxs_uart.c new file +10
-0+*/ + +/* +* Work in progress ! Right now there's just enough so that linux driver +* will instantiate after a probe, there is no functional code. +*/ +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +#define D (w) wPlease get rid of this. You can use a similar DPRINTF type macro as other devices do, or no debug tracing at all, as you wish.
To clarify further, make DPRINTF use a regular c-code if, rather than conditional compilation. The reason being your debug printfery should always be compile tested.
Quoted 11 lines
Quoted 11 lines
hw/char/mxs_uart.c new file +11
-0+ +enum { +UART_CTRL =0x0 , +UART_CTRL1 =0x1 , +UART_CTRL2 =0x2 , +UART_LINECTRL =0x3 , +UART_LINECTRL2 =0x4 , +UART_INTR =0x5 , +UART_APP_DATA =0x6 , +UART_APP_STAT =0x7 , +UART_APP_DEBUG =0x8 ,
Quoted 8 lines
hw/char/mxs_uart.c line 35
Quoted 8 lines
hw/char/mxs_uart.c new file +8
-0+UART_APP_VERSION =0x9 , +UART_APP_AUTOBAUD =0xa , + + UART_MAX, +}; +typedef struct mxs_uart_state { + SysBusDevice busdev; + MemoryRegion iomem;
Check QOM conventions (I commented in other patch - see for details).
Quoted 9 lines
hw/char/mxs_uart.c line 44
Quoted 9 lines
hw/char/mxs_uart.c new file +9
-0+ +uint32_t r[UART_MAX ]; + +struct { +uint16_t b[16 ]; +int w, r; + } fifo[2 ]; +qemu_irq irq; +CharDriverState *chr;
Dead variable. Just add it along with your functionality. Although the functionality would help a lot. Its a bit of a trap, advertisiting a UART which is just a NOP. Some qemu_log_mask(LOG_UNIMP, at various places migt be in order, although depending on complexity it may not be much harder to get basic txrx going.
Quoted 114 lines
hw/char/mxs_uart.c line 45
Quoted 1 line
hw/char/mxs_uart.c new file +1
-0+} mxs_uart_state;Structured type names should be in CamelCase; see
CODING_STYLE.hw/char/mxs_uart.c line 55
Quoted 9 lines
hw/char/mxs_uart.c new file +9
-0+static uint64_t mxs_uart_read ( +void *opaque,hwaddr offset,unsigned size) +{ +mxs_uart_state *s = (mxs_uart_state *) opaque; +uint32_t res =0 ; + + D(printf("%s %04x (%d) = ", __func__, (int)offset, size);) +switch (offset >>4 ) { + case 0 ... UART_MAX:This indent is wrong, as checkpatch.pl will tell you.
Quoted 23 lines
hw/char/mxs_uart.c new file +23
-0+ res = s->r[offset >>4 ]; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } + D(printf("%08x\n", res);) + +return res; +} + +static void mxs_uart_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +mxs_uart_state *s = (mxs_uart_state *) opaque; +uint32_t oldvalue =0 ; + + D(printf("%s %04x %08x(%d)\n", __func__, (int)offset, (int)value, size);) +switch (offset >>4 ) { + case 0 ... UART_MAX: +mxs_write (&s->r[offset >>4 ], offset, value, size); +break ;hw/char/mxs_uart.c line 88
Quoted 10 lines
hw/char/mxs_uart.c new file +10
-0+default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } +switch (offset >>4 ) { +case UART_CTRL : +if ((oldvalue ^ s->r[UART_CTRL ]) ==0x80000000 + && !(oldvalue &0x80000000 )) { +printf ("%s reseting, anding clockgate\n" , __func__);Stray debug printout.
hw/char/mxs_uart.c line 97
Quoted 9 lines
hw/char/mxs_uart.c new file +9
-0+ s->r[UART_CTRL ] |=0x40000000 ; + } +break ; + } +} + +static void mxs_uart_set_irq (void *opaque,int irq,int level) +{ +// mxs_uart_state *s = (mxs_uart_state *)opaque; Don't leave commented out code in your patches, please.
Quoted 6 lines
hw/char/mxs_uart.c new file +6
-0+printf ("%s %3d = %d\n" , __func__, irq, level); +} + +static const MemoryRegionOps mxs_uart_ops = { + .read = mxs_uart_read, + .write = mxs_uart_write,hw/char/mxs_uart.c line 113
Quoted 10 lines
hw/char/mxs_uart.c new file +10
-0+ .endianness = DEVICE_NATIVE_ENDIAN, +}; + + +static int mxs_uart_init (SysBusDevice *dev) +{ +mxs_uart_state *s =OBJECT_CHECK (mxs_uart_state, dev,"mxs_uart" ); +DeviceState *qdev =DEVICE (dev); + +qdev_init_gpio_in (qdev, mxs_uart_set_irq,32 *3 );Why has a UART got so many inbound GPIO signals? At minimum, there should be a comment here describing what they are.
hw/char/mxs_uart.c line 121
Quoted 8 lines
hw/char/mxs_uart.c new file +8
-0+sysbus_init_irq (dev, &s->irq); +memory_region_init_io (&s->iomem,OBJECT (s), &mxs_uart_ops, s,"mxs_uart" ,0x2000 ); +sysbus_init_mmio (dev, &s->iomem); + + s->r[UART_CTRL ] =0xc0030000 ; + s->r[UART_CTRL2 ] =0x00220180 ; + s->r[UART_APP_STAT ] =0x89f00000 ; + s->r[UART_APP_VERSION ] =0x03000000 ;Don't do reset here, do it in a reset function (which you set up by setting the DeviceClass reset function pointer in the class init function). Reset is called for you after init, so you don't need to do any reset in init.
hw/char/mxs_uart.c line 130
Quoted 9 lines
hw/char/mxs_uart.c new file +9
-0+return 0 ; +} + + +static void mxs_uart_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_uart_init;You need a vmstate structure to support save/load and VM migration, and then to set the DeviceClass vmsd field to point to it here.
Quoted 16 lines
Quoted 6 lines
hw/char/mxs_uart.c new file +6
-0+} + +static TypeInfo uart_info = { + .name ="mxs_uart" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_uart_state),hw/char/mxs_uart.c line 146
Quoted 10 lines
hw/char/mxs_uart.c new file +10
-0+ .class_init = mxs_uart_class_init, +}; + +static void mxs_uart_register (void ) +{ +type_register_static (&uart_info); +} + +type_init (mxs_uart_register) +
Stray blank line at EOF.
Regards,
Peter
Quoted 4 lines
thanks
-- PMM
Re: [Qemu-devel] [PATCH 05/13] mxs/imx23: Add the interrupt collector
In reply to Michel Pollet---------- Forwarded message ----------
From: Michel Pollet <[email protected]>
Date: Wed, Dec 11, 2013 at 11:56 PM
Subject: [Qemu-devel] [PATCH 05/13] mxs/imx23: Add the interrupt collector
To: [email protected]
Cc: Michel Pollet <[email protected]>
Implements the interrupt collector IO block
--- hw/intc/Makefile.objs | 1 + hw/intc/mxs_icoll.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 hw/intc/mxs_icoll.c
hw/intc/Makefile.objs +1 -0
@@ -24,3 +24,4 @@ obj-$(CONFIG_OPENPIC_KVM) += openpic_kvm.o obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_MXS) += mxs_icoll.o
hw/intc/mxs_icoll.c new file +21 -0
@@ -0,0 +1,200 @@ +/* +* mxs_icoll.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ + +/* +* This block implements the interrupt collector of the mxs +* Currently no priority is handled, as linux doesn't use them anyway +*/ + +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +enum { +ICOLL_VECTOR =0 , +ICOLL_LEVELACK =1 , +ICOLL_CTRL =2 , +// 3, reserved?
Any documentation with an answer? I'd just drop the comment TBH,
+ ICOLL_VBASE = 4,
+ ICOLL_STAT = 7,
+
+ ICOLL_REG_MAX,
+
+ ICOLL_RAW0 = 0xa, + ICOLL_RAW1, + ICOLL_RAW2, + ICOLL_RAW3,
+
+ ICOLL_INT0 = 0x12,
+ ICOLL_INT127 = 0x91,
Calculate ICOLL_INT127 arithmetically to be self documenting.
+};
+
+typedef struct mxs_icoll_state {
+ SysBusDevice busdev; + MemoryRegion iomem; + uint32_t reg[ICOLL_REG_MAX]; + + uint32_t raised[4]; + uint32_t fiq[4]; + uint32_t irq[4];
+
+ uint8_t r[128];
Magic numbers "128" and "4" could use macro definition.
+
+ qemu_irq parent_irq;
+ qemu_irq parent_fiq;
+} mxs_icoll_state;
+
+static void mxs_icoll_update(mxs_icoll_state *s)
+{
+ int fiq = 0, irq = 0;
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ int id = ffs(s->raised[i]);
+ int vector = (i * 32) + id - 1;
ffs will set id to correspond to the first raised interrupt whether its enabled on not. So in the case where a higher priority interrupt is masked and both it and a lower priority interrupt occurs, the vector logic below will be calcalated for the masked higher priority. Do you really intend to take the vector for a disabled interrupt?
+ if (s->raised[i] & s->fiq[i]) {
+ fiq++; + s->reg[ICOLL_STAT] = vector; + break;
+ }
+ if (s->raised[i] & s->irq[i]) {
+ irq++;
+ s->reg[ICOLL_STAT] = vector;
So this feels strange. A set IRQ always takes priority over FIQ WRT the vector.
+ break;
+ }
+ } + qemu_set_irq(s->parent_irq, irq != 0); + qemu_set_irq(s->parent_fiq, fiq != 0);
+}
+
+static void mxs_icoll_set_irq(void *opaque, int irq, int level) +{
+ mxs_icoll_state *s = (mxs_icoll_state *) opaque;
+ if (level)
+ s->raised[(irq / 32)] |= 1 << (irq % 32);
+ else
+ s->raised[(irq / 32)] &= ~(1 << (irq % 32));
deposit32:
s->raised[irq / 32] = deposit32(s->raised[irq / 32], irq % 32, 1, !!level);
or something like that.
Although looking at this, your s->raised variables are double-edge sensitive. If the original interrupt goes down so does the raised bit. Does this really not have any latching behavior (esp for edge interrupts)?
The other problem with this is level sens. interrupts. If a level sensitive interrupt occurs from a device and stays high, your controller can ack it, yet it shouldn't de-assert the interrupt as the (level sens.) pin is still high. The code here wont retrigger until the pin strobes from the originating device.
You may need to separate out the raw input pin state from the pending interrupt state. Originally I was operating under the assumption that s->raised is simply the raw pin state [1] ....
+ mxs_icoll_update(s);
+}
+
+static uint64_t mxs_icoll_read(void *opaque, hwaddr offset, unsigned size) +{
+ mxs_icoll_state *s = (mxs_icoll_state *) opaque;
+
+ switch (offset >> 4) {
+ case 0 ... ICOLL_REG_MAX:
+ return s->reg[offset >> 4];
+ case ICOLL_RAW0 ... ICOLL_RAW3:
+ return s->raised[(offset >> 4) - ICOLL_RAW0];
+ case ICOLL_INT0 ... ICOLL_INT127:
+ return s->r[(offset >> 4) - ICOLL_INT0];
+ default:
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: bad offset 0x%x\n", __func__, (int) offset);
+ break;
+ }
+ return 0;
+}
+
+static void mxs_icoll_write(
+ void *opaque, hwaddr offset, uint64_t value, unsigned size)
+{
+ mxs_icoll_state *s = (mxs_icoll_state *) opaque; + uint32_t irqval, irqi = 0; + uint32_t * dst = NULL; + uint32_t oldvalue = 0;
+
+ switch (offset >> 4) {
+ case 0 ... ICOLL_REG_MAX:
+ dst = s->reg + (offset >> 4);
+ break;
+ case ICOLL_INT0 ... ICOLL_INT127:
+ irqi = (offset >> 4) - ICOLL_INT0; + irqval = s->r[irqi]; + dst = &irqval; + break;
+ default:
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: bad offset 0x%x\n", __func__, (int) offset);
+ break;
+ }
+ if (!dst) {
+ return;
+ }
+ oldvalue = mxs_write(dst, offset, value, size);
+
+ switch (offset >> 4) {
+ case ICOLL_CTRL:
+ if ((oldvalue ^ s->r[ICOLL_CTRL]) == 0x80000000
+ && !(oldvalue & 0x80000000)) {
+ // printf("%s reseting, anding clockgate\n", __func__);
"resetting"
+ s->r[ICOLL_CTRL] |= 0x40000000;
+ }
+ break;
+ case ICOLL_LEVELACK:
+ irqi = s->reg[ICOLL_STAT] & 0x7f;
+ s->raised[(irqi / 32)] &= ~(1 << (irqi % 32));
[1] ... but this code here is clearing s->raised on software command. So s->raised seems to have a mixed definition between "raw pin state" and "interrupt is pending". Perhaps you can clarify what is the intended meaning of raised?
+ s->reg[ICOLL_STAT] = 0x7f;
+ break;
+ case ICOLL_INT0 ... ICOLL_INT127:
+ s->r[irqi] = irqval & ~(0x40); // dont' set softirq bit
+ if (irqval & 0x4) // ENABLE
+ s->irq[irqi / 32] |= (1 << (irqi % 32));
+ else
+ s->irq[irqi / 32] &= ~(1 << (irqi % 32));
deposit32 can make short work of this.
Regards,
Peter
+ if (irqval & 0x10) // ENFIQ
+ s->fiq[irqi / 32] |= (1 << (irqi % 32));
+ else
+ s->fiq[irqi / 32] &= ~(1 << (irqi % 32));
+ if (irqval & 0x8) // SOFTIRQ
+ mxs_icoll_set_irq(s, irqi, 1);
+ break;
+ }
+
+ mxs_icoll_update(s);
+}
+
+static const MemoryRegionOps mxs_icoll_ops = {
+ .read = mxs_icoll_read, + .write = mxs_icoll_write, + .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+static int mxs_icoll_init(SysBusDevice *dev)
+{
+ mxs_icoll_state *s = OBJECT_CHECK(mxs_icoll_state, dev, "mxs_icoll");
+ DeviceState *qdev = DEVICE(dev);
+
+ qdev_init_gpio_in(qdev, mxs_icoll_set_irq, 128); + sysbus_init_irq(dev, &s->parent_irq); + sysbus_init_irq(dev, &s->parent_fiq); + memory_region_init_io(&s->iomem, OBJECT(s), &mxs_icoll_ops, s,
+ "mxs_icoll", 0x2000);
+ sysbus_init_mmio(dev, &s->iomem);
+ return 0;
+}
+
+static void mxs_icoll_class_init(ObjectClass *klass, void *data) +{
+ SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+ sdc->init = mxs_icoll_init;
+}
+
+static TypeInfo icoll_info = {
+ .name = "mxs_icoll", + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(mxs_icoll_state), + .class_init = mxs_icoll_class_init,
+};
+
+static void mxs_icoll_register(void)
+{
+ type_register_static(&icoll_info);
+}
+
+type_init(mxs_icoll_register)
--
1.8.5.1
Re: [Qemu-devel] [PATCH 06/13] mxs/imx23: Add digctl driver
In reply to Michel PolletQuoted 27 lines · Michel Pollet
This implements just enough of the digctl IO block to allow linux to believe it's running on (currently only) an imx23.
Signed-off-by Michel Pollet <[email protected]>--- hw/arm/Makefile.objs | 1 + hw/arm/imx23_digctl.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 hw/arm/imx23_digctl.chw/arm/Makefile.objs +1
-0@@ -5,3 +5,4 @@ obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o +obj-$(CONFIG_MXS) += imx23_digctl.ohw/arm/imx23_digctl.c new file +2
-0@@ -0,0 +1,110 @@ +/* +* imx23_digctl.c
hw/arm/imx23_digctl.c line 12
Quoted 10 lines
hw/arm/imx23_digctl.c new file +10
-0+* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ + +/* +* This module implements a very basic IO block for the digctl of the imx23 +* Basically there is no real logic, just constant registers return, the most +* used one bing the "chip id" that is used by the various linux drivers
"being", "Linux".
Regards,
Peter
Quoted 65 lines
hw/arm/imx23_digctl.c new file +65
-0+* to differentiate between imx23 and 28. +* +* The module consists mostly of read/write registers that the bootloader and +* kernel are quite happy to 'set' to whatever value they believe they set... +*/ + +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +enum { +HW_DIGCTL_RAMCTL =0x3 , +HW_DIGCTL_CHIPID =0x31 , +}; + +typedef struct imx23_digctl_state { +SysBusDevice busdev; +MemoryRegion iomem; + +uint32_t reg[0x2000 /4 ]; +}imx23_digctl_state ; + +static uint64_t imx23_digctl_read ( +void *opaque,hwaddr offset,unsigned size) +{ +imx23_digctl_state *s = (imx23_digctl_state *)opaque; +uint32_t res =0 ; + +switch (offset >>4 ) { + case 0 ... 0x2000/4: + res = s->reg[offset >>4 ]; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int )offset); +return 0 ; + } +return res; +} + +static void imx23_digctl_write ( +void *opaque,hwaddr offset,uint64_t value,unsigned size) +{ +imx23_digctl_state *s = (imx23_digctl_state *) opaque; +uint32_t * dst =NULL ; + +switch (offset >>4 ) { + case 0 ... 0x2000 / 4: + dst = &s->reg[(offset >>4 )]; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +return ; + } +if (!dst) { +return ; + } +mxs_write (dst, offset, value, size); +} + +static const MemoryRegionOps imx23_digctl_ops = { + .read = imx23_digctl_read, + .write = imx23_digctl_write, + .endianness =DEVICE_NATIVE_ENDIAN , +};
hw/arm/imx23_digctl.c line 87
Quoted 10 lines
hw/arm/imx23_digctl.c new file +10
-0+ +static int imx23_digctl_init (SysBusDevice *dev) +{ +imx23_digctl_state *s =OBJECT_CHECK (imx23_digctl_state, dev,"imx23_digctl" ); + +memory_region_init_io (&s->iomem,OBJECT (s), &imx23_digctl_ops, s, +"imx23_digctl" ,0x2000 ); +sysbus_init_mmio (dev, &s->iomem); + s->reg[HW_DIGCTL_RAMCTL ] =0x6d676953 ;/* default reset value */ + s->reg[HW_DIGCTL_CHIPID ] =0x37800000 ;/* i.mX233 */
Move to rst function.
Quoted 27 lines
hw/arm/imx23_digctl.c new file +23
-1+return 0 ; +} + +static void imx23_digctl_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = imx23_digctl_init; +} + +static TypeInfo digctl_info = { + .name ="imx23_digctl" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (imx23_digctl_state), + .class_init = imx23_digctl_class_init, +}; + +static void imx23_digctl_register (void ) +{ +type_register_static (&digctl_info); +} + +type_init (imx23_digctl_register) --1.8.5.1
Re: [Qemu-devel] [PATCH 06/13] mxs/imx23: Add digctl driver
In reply to Peter MaydellQuoted 4 lines · Peter Maydell
Quoted 3 lines · M P
I will re-add the trace for both write and read and see if I can narrow the range down; it will be linux specific, tho, that's why I thought a 'catchall' block was more appropriate.
I would suggest you do the ones you care about properly, and RAZ/WI+qemu_log_mask(LOG_UNIMP, the rest. When it comes to the unimplemented, hard obvious failure from a totally unresponsive register is preferrable to subtle infidelities (like being able to write to RO register).
Regards,
Peter
Quoted 9 lines
Well, we should be implementing what the hardware does, generally. Misimplementing things as "read as written" isn't really any better than misimplementing them as RAZ/WI, it's just differently wrong.
thanks
-- PMM
Re: [Qemu-devel] [PATCH 08/13] mxs/imx23: Add SSP/SPI driver
In reply to Michel PolletQuoted 10 lines · Michel Pollet
This implements the SSP port(s) of the mxs. Currently hardcoded for the SD card interface, but as TODO it could rather easily be made to be generic and support 'generic' SPI too.
It is geared toward working with DMA, as the linux drivers uses it that way.Signed-off-by Michel Pollet <[email protected]>--- hw/ssi/Makefile.objs | 1 + hw/ssi/mxs_spi.c | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++
I'd call it an SD controller for the moment, or put it in misc with a comment about how you intend to make this work with multiple interfaces. Paolo may be able to better comment on /hw/ org. A SD device shouldn't live in ssi.
Quoted 95 lines
2 files changed, 240 insertions(+) create mode 100644 hw/ssi/mxs_spi.chw/ssi/Makefile.objs +1
-0@@ -4,3 +4,4 @@ common-obj-$(CONFIG_XILINX_SPI) += xilinx_spi.o common-obj-$(CONFIG_XILINX_SPIPS) += xilinx_spips.o obj-$(CONFIG_OMAP) += omap_spi.o +obj-$(CONFIG_MXS) += mxs_spi.ohw/ssi/mxs_spi.c new file +77
-0@@ -0,0 +1,239 @@ +/* +* mxs_ssp.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ + +/* +* This implements the SSP port(s) of the mxs. Currently hardcoded for the +* SD card interface, but as TODO it could rather easily be made to be generic +* and support 'generic' SPI too. +* It is geared toward working with DMA, as the linux drivers uses it that way. +*/ +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" +#include "sysemu/blockdev.h" +#include "hw/sd.h" + +/* +* SSP register indexes, most of the useful ones +*/ +enum { +SSP_CTRL =0x0 , +SSP_SD_CMD0 =0x1 , +SSP_SD_CMD1 =0x2 , +SSP_COMPREF =0x3 , +SSP_COMPMASK =0x4 , +SSP_TIMING =0x5 , +SSP_CTRL1 =0x6 , +SSP_DATA =0x7 , +SSP_SDRESP0 =0x8 , +SSP_SDRESP1 =0x9 , +SSP_SDRESP2 =0xa , +SSP_SDRESP3 =0xb , +SSP_STATUS =0xc , + +SSP_VERSION =0x11 , +SSP_MAX , +}; + +/* +* SSP_CTRL bit numbers +*/ +enum { +CTRL_READ =25 , +CTRL_DATA_XFER =24 , +CTRL_ENABLE =16 , +CTRL_LONG_REST =19 , +}; +/* +* SSP_STAT bit numbers +*/ +enum { +STAT_BUSY =0 , +STAT_DATA_BUSY =2 , +STAT_CMD_BUSY =3 , +STAT_CARD_DETECT =28 , +}; + +typedef struct mxs_ssp_state { +SysBusDevice busdev; +MemoryRegion iomem; + +uint32_t r[SSP_MAX ]; +qemu_irq irq_dma, irq_error; +SDState *sd; +}mxs_ssp_state ; + +static uint64_t mxs_ssp_read ( +void *opaque,hwaddr offset,unsigned size) +{ +mxs_ssp_state *s = (mxs_ssp_state *) opaque; +uint32_t res =0 ; + +switch (offset >>4 ) { + case 0 ... SSP_MAX:
hw/ssi/mxs_spi.c line 87
Quoted 10 lines
hw/ssi/mxs_spi.c new file +10
-0+ res = s->r[offset >>4 ]; +switch (offset >>4 ) { +case SSP_STATUS : + s->r[SSP_STATUS ] &= ~((1 <<STAT_BUSY ) | + (1 <<STAT_DATA_BUSY ) | (1 <<STAT_CMD_BUSY )); +break ; +/* dma polls this register to read the data from the card +* this is not very efficient, perhaps a better data conduit +* is available. It does work as the real hardware tho... +*/
If thats what real hw does then this is fine. I wouldn't invest in an app specific side channel or anything like that.
Quoted 9 lines
hw/ssi/mxs_spi.c new file +9
-0+case SSP_DATA : + res =sd_read_data (s->sd); +break ; + } +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ;
hw/ssi/mxs_spi.c line 106
Quoted 10 lines
hw/ssi/mxs_spi.c new file +10
-0+ } + +return res; +} + +static uint32_t __swap (uint32_t w) +{ +return (w >>24 ) | ((w &0x00ff0000 ) >>8 ) | + ((w &0x0000ff00 ) <<8 ) | (w <<24 ); +}
bswap32?
hw/ssi/mxs_spi.c line 116
Quoted 10 lines
hw/ssi/mxs_spi.c new file +10
-0+ +/* +* processes one SD/MMC command train. It always have a 'command' but +* can also have datas attached, this case is not handled here, it's +* handled by the SD layer. +* The command can either be short or long, wierdly, the mxs returns +* the bytes in some funky order that needs to be restored. +* TODO: Make big endian compatible +*/ +static void mxs_process_cmd (mxs_ssp_state *s)
mxs_process_sd_cmd.
hw/ssi/mxs_spi.c line 120
Quoted 4 lines
hw/ssi/mxs_spi.c new file +4
-0+{ +if (!(s->r[SSP_CTRL ] & (1 <<CTRL_ENABLE ))) +return ; +uint32_t r[4 ];// temporary buffer
Don't do declarations after code.
Quoted 48 lines
hw/ssi/mxs_spi.c new file +48
-0+ + s->r[SSP_SDRESP0 ] = s->r[SSP_SDRESP1 ] = + s->r[SSP_SDRESP2 ] = s->r[SSP_SDRESP3 ] =0 ; + +SDRequest cmd = { + .cmd = s->r[SSP_SD_CMD0 ] &0xff , + .arg = s->r[SSP_SD_CMD1 ], + .crc =0 , + }; +sd_enable (s->sd,1 ); +sd_do_command (s->sd, &cmd, (uint8_t *) r); +if (s->r[SSP_CTRL ] & (1 <<CTRL_LONG_REST )) { + s->r[SSP_SDRESP0 ] =__swap (r[3 ]); + s->r[SSP_SDRESP1 ] =__swap (r[2 ]); + s->r[SSP_SDRESP2 ] =__swap (r[1 ]); + s->r[SSP_SDRESP3 ] =__swap (r[0 ]); + }else + s->r[SSP_SDRESP0 ] =__swap (r[0 ]); + +/* mark these flags as busy, they will be read once +* as 'busy' before being cleared by a read. */ + s->r[SSP_STATUS ] |= (1 <<STAT_CMD_BUSY ); + s->r[SSP_STATUS ] |= (1 <<STAT_BUSY ); +if (s->r[SSP_CTRL ] & (1 <<CTRL_DATA_XFER )) + s->r[SSP_STATUS ] |= (1 <<STAT_DATA_BUSY ); +} + +static void mxs_ssp_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +mxs_ssp_state *s = (mxs_ssp_state *) opaque; +uint32_t oldvalue =0 ; + +switch (offset >>4 ) { + case 0 ... SSP_MAX: + oldvalue =mxs_write (&s->r[offset >>4 ], offset, value, size); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } +switch (offset >>4 ) { +case SSP_CTRL : +if ((oldvalue ^ s->r[SSP_CTRL ]) ==0x80000000 + && !(oldvalue &0x80000000 )) { +// printf("%s reseting, anding clockgate\n", __func__); +// TODO: Implement a reset function?
hw/ssi/mxs_spi.c line 178
Quoted 10 lines
hw/ssi/mxs_spi.c new file +10
-0+ s->r[SSP_CTRL ] |=0x40000000 ; + } +break ; +case SSP_SD_CMD1 : +mxs_process_cmd (s); +break ; +/* +* Write from DMA +* TODO: Handle case were it's not a SD/MMC but a normal SPI +*/
A well placed qemu_log_mask(LOG_UNIMP, could make this user friendly. I dont see functionality with modes here though. Are there any bit fields that should be set to explicitly put the controller in SD mode>?
Regards,
Peter
Quoted 65 lines
hw/ssi/mxs_spi.c new file +61
-1+case SSP_DATA : +sd_write_data (s->sd, s->r[SSP_DATA ]); +break ; +case SSP_STATUS : + s->r[SSP_STATUS ] = oldvalue; +qemu_log_mask (LOG_GUEST_ERROR , +"%s: invalid write to SSP_STATUS\n" , __func__); +break ; + } +} + + +static const MemoryRegionOps mxs_ssp_ops = { + .read = mxs_ssp_read, + .write = mxs_ssp_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static int mxs_ssp_init (SysBusDevice *dev) +{ +mxs_ssp_state *s =OBJECT_CHECK (mxs_ssp_state, dev,"mxs_ssp" ); + +sysbus_init_irq (dev, &s->irq_dma); +sysbus_init_irq (dev, &s->irq_error); +memory_region_init_io (&s->iomem,OBJECT (s), &mxs_ssp_ops, s, +"mxs_ssp" ,0x2000 ); +sysbus_init_mmio (dev, &s->iomem); + + s->r[SSP_CTRL ] =0xc0000000 ; + s->r[SSP_STATUS ] =0xe0000000 ; + s->r[SSP_VERSION ] =0x03000000 ; + +DriveInfo *dinfo =drive_get_next (IF_SD ); + + s->sd =sd_init (dinfo ? dinfo->bdrv :NULL ,0 ); + +return 0 ; +} + + +static void mxs_ssp_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_ssp_init; +} + +static TypeInfo ssp_info = { + .name ="mxs_ssp" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_ssp_state), + .class_init = mxs_ssp_class_init, +}; + +static void mxs_ssp_register (void ) +{ +type_register_static (&ssp_info); +} + +type_init (mxs_ssp_register) + --1.8.5.1
Re: [Qemu-devel] [PATCH 09/13] mxs/imx23: Add the RTC block
In reply to Michel PolletQuoted 82 lines · Michel Pollet
Support for the RTC IO block on the imx23, enough to return a valid date and make guest linux happy.
Signed-off-by Michel Pollet <[email protected]>--- hw/timer/Makefile.objs | 1 + hw/timer/mxs_rtc.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 hw/timer/mxs_rtc.chw/timer/Makefile.objs +1
-0@@ -26,5 +26,6 @@ obj-$(CONFIG_OMAP) += omap_synctimer.o obj-$(CONFIG_PXA2XX) += pxa2xx_timer.o obj-$(CONFIG_SH4) += sh_timer.o obj-$(CONFIG_TUSB6010) += tusb6010.o +obj-$(CONFIG_MXS) += mxs_rtc.o obj-$(CONFIG_MC146818RTC) += mc146818rtc.ohw/timer/mxs_rtc.c new file +55
-0@@ -0,0 +1,147 @@ +/* +* mxs_rtc.c +* +* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ +/* +* Implement the RTC block of the mxs. At least, the real time stuff. +* TODO Alarm, and watchdog ? +*/ + +#include "hw/sysbus.h" +#include "hw/arm/mxs.h" + +#define D (w) + +enum { +RTC_CTRL =0x0 , +RTC_STAT =0x1 , +RTC_MS =0x2 , +RTC_SECONDS =0x3 , +RTC_ALARM =0x4 , +RTC_WATCHDOG =0x5 , +RTC_PERSISTENT0 =0x6 , +RTC_PERSISTENT1 =0x7 , +RTC_PERSISTENT2 =0x8 , +RTC_PERSISTENT3 =0x9 , +RTC_PERSISTENT4 =0xa , +RTC_PERSISTENT5 =0xa , +RTC_DEBUG =0xc , +RTC_VERSION =0xd , + +RTC_MAX , +}; +typedef struct mxs_rtc_state { +SysBusDevice busdev; +MemoryRegion iomem; +uint32_t base_ms, base_s; +uint32_t r[RTC_MAX ]; +qemu_irq alarm_irq; +CharDriverState *chr; +}mxs_rtc_state ; + +static uint64_t mxs_rtc_read ( +void *opaque,hwaddr offset,unsigned size) +{ +mxs_rtc_state *s = (mxs_rtc_state *) opaque; +uint32_t res =0 ; + + D(printf("%s %04x (%d) = ", __func__, (int)offset, size);) +switch (offset >>4 ) { + case 0 ... RTC_MAX: +if ((offset >>4 ) ==RTC_MS || (offset >>4 ) ==RTC_SECONDS ) { +struct timeval tv;
hw/timer/mxs_rtc.c line 65
Quoted 10 lines
hw/timer/mxs_rtc.c new file +10
-0+gettimeofday (&tv,NULL ); + s->r[RTC_MS ] = (tv.tv_usec /1000 ) - s->base_ms; + s->r[RTC_SECONDS ] = tv.tv_sec - s->base_s; + } + res = s->r[offset >>4 ]; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ;
So for these peripherals that are just a straight up register set of R_MAX, can you define the MMIO region as R_MAX*4 rather than 0x2000? Then you can drop these log_guest_errors that are trying to trap accesses outside the peripheral. Whats the architectural significance of 0x2000?
Regards,
Peter
Quoted 86 lines
hw/timer/mxs_rtc.c new file +82
-1+ } + D(printf("%08x\n", res);) + +return res; +} + +static void mxs_rtc_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +mxs_rtc_state *s = (mxs_rtc_state *) opaque; +uint32_t oldvalue =0 ; + + D(printf("%s %04x %08x(%d)\n", __func__, (int)offset, (int)value, size);) +switch (offset >>4 ) { + case 0 ... RTC_MAX: +mxs_write (&s->r[offset >>4 ], offset, value, size); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } +switch (offset >>4 ) { +case RTC_MS : + s->base_ms = s->r[RTC_MS ]; +break ; +case RTC_SECONDS : + s->base_s = s->r[RTC_SECONDS ]; +break ; +case RTC_CTRL : +if ((oldvalue ^ s->r[RTC_CTRL ]) ==0x80000000 + && !(oldvalue &0x80000000 )) { + D(printf("%s reseting, anding clockgate\n", __func__);) + s->r[RTC_CTRL] |= 0x40000000; + } +break ; + } +} + +static const MemoryRegionOps mxs_rtc_ops = { + .read = mxs_rtc_read, + .write = mxs_rtc_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static int mxs_rtc_init (SysBusDevice *dev) +{ +mxs_rtc_state *s =OBJECT_CHECK (mxs_rtc_state, dev,"mxs_rtc" ); + +sysbus_init_irq (dev, &s->alarm_irq); +memory_region_init_io (&s->iomem,OBJECT (s), &mxs_rtc_ops, s, +"mxs_rtc" ,0x2000 ); +sysbus_init_mmio (dev, &s->iomem); + + s->r[RTC_CTRL ] =0xc0000000 ; + s->r[RTC_STAT ] =0xe80f0000 ; + s->r[RTC_VERSION ] =0x02000000 ; +// s->base_s = time(NULL); +return 0 ; +} + + +static void mxs_rtc_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_rtc_init; +} + +static TypeInfo rtc_info = { + .name ="mxs_rtc" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_rtc_state), + .class_init = mxs_rtc_class_init, +}; + +static void mxs_rtc_register (void ) +{ +type_register_static (&rtc_info); +} + +type_init (mxs_rtc_register) --1.8.5.1
Re: [Qemu-devel] [PATCH 11/13] mxs/imx23: Add the USB driver
In reply to Michel PolletQuoted 31 lines · Michel Pollet
Add the USB IO block, and the USB PHY IO block. This just wraps an ehci instance, and support some of the 'extra' mxs registers
Signed-off-by Michel Pollet <[email protected]>--- hw/usb/Makefile.objs | 1 + hw/usb/mxs_usb.c | 254 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 255 insertions(+) create mode 100644 hw/usb/mxs_usb.chw/usb/Makefile.objs +1
-0@@ -8,6 +8,7 @@ common-obj-$(CONFIG_USB_OHCI) += hcd-ohci.o common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o hcd-ehci-pci.o hcd-ehci-sysbus.o common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o +common-obj-$(CONFIG_MXS) += mxs_usb.o # emulated usb devices common-obj-y += dev-hub.ohw/usb/mxs_usb.c new file +3
-0@@ -0,0 +1,254 @@ +/* +* mxs_usb.c +*
hw/usb/mxs_usb.c line 13
Quoted 10 lines
hw/usb/mxs_usb.c new file +10
-0+* Copyright: Michel Pollet <[email protected]> +* +* QEMU Licence +*/ + +/* +* Implements the USB block of the mxs. This is just a case of +* instantiating a ehci block, and have a few read only registers +* for mxs specific bits +*/
Sounds like a subclass of EHCI. There are several EHCI subclasses already for this very purpose. Check the TEGRA2 or EXYNOS_4210 EHCI variations for examples on how to sublcass EHCI.
Regards,
Peter
Quoted 72 lines
hw/usb/mxs_usb.c new file +72
-0+#include "hw/sysbus.h" +#include "hw/arm/mxs.h" +#include "hw/usb/hcd-ehci.h" +#include "hw/qdev.h" + +#define D (w) + +enum { +USB_MAX =256 /4 , +}; + +typedef struct mxs_usb_state { +SysBusDevice busdev; +MemoryRegion iomem; + +uint32_t r[USB_MAX ]; +qemu_irq irq_dma, irq_error; + +EHCIState ehci; +}mxs_usb_state ; + +static uint64_t mxs_usb_read ( +void *opaque,hwaddr offset,unsigned size) +{ +mxs_usb_state *s = (mxs_usb_state *) opaque; +uint32_t res =0 ; + + D(printf("%s %04x (%d) = ", __func__, (int)offset, size);) +switch (offset >>2 ) { + case 0 ... USB_MAX: + res = s->r[offset >>2 ]; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } + D(printf("%08x\n", res);) + +return res; +} + +static void mxs_usb_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +mxs_usb_state *s = (mxs_usb_state *) opaque; + + D(printf("%s %04x %08x(%d)\n", __func__, (int)offset, (int)value, size);) +switch (offset) { + case 0 ... USB_MAX: + s->r[offset] = value; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } +} + +static const MemoryRegionOps mxs_usb_ops = { + .read = mxs_usb_read, + .write = mxs_usb_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static int mxs_usb_init (SysBusDevice *dev) +{ +mxs_usb_state *s =OBJECT_CHECK (mxs_usb_state, dev,"mxs_usb" ); +EHCIState *u = &s->ehci; + +memory_region_init_io (&s->iomem,OBJECT (s), &mxs_usb_ops, s, +"mxs_usb" ,0x100 );
hw/usb/mxs_usb.c line 95
Quoted 10 lines
hw/usb/mxs_usb.c new file +10
-0+ + s->r[0 ] =0xe241fa05 ; + s->r[0x04 >>2 ] =0x00000015 ; + s->r[0x08 >>2 ] =0x10020001 ; + s->r[0x0c >>2 ] =0x0000000b ; + s->r[0x10 >>2 ] =0x40060910 ; + s->r[0x14 >>2 ] =0x00000710 ; + + u->capsbase =0x100 ; + u->opregbase =0x140 ;
This is nice and data driven in the subclassing framwork.
hw/usb/mxs_usb.c line 104
Quoted 9 lines
hw/usb/mxs_usb.c new file +9
-0+// FIXME ?!?!? +// u->dma = &dma_context_memory; + +usb_ehci_init (u,DEVICE (dev)); +sysbus_init_irq (dev, &u->irq); + +memory_region_add_subregion (&u->mem,0x0 , &s->iomem); +sysbus_init_mmio (dev, &u->mem); +
And all you need to do it tack this on in your IMX_EHCI specific instance_init.
Quoted 34 lines
hw/usb/mxs_usb.c new file +34
-0+ D(printf("%s created bus %s\n", __func__, u->bus.qbus.name);) +#if 0 +/* +* This is suposed to make companion ports that will support +* slower speed devices (mouse/keyboard etc). It's inspired +* from ehci/pci however it doesn't work, right now... +*/ +int i; +for (i =0 ; i <NB_PORTS ; i +=2 ) { +DeviceState * d =qdev_create (NULL ,"sysbus-ohci" ); +qdev_prop_set_string (d,"masterbus" , u->bus.qbus.name); +qdev_prop_set_uint32 (d,"firstport" , i); +qdev_prop_set_uint32 (d,"num-ports" ,2 ); +qdev_init_nofail (d); +sysbus_connect_irq (SYS_BUS_DEVICE (d),0 , u->irq); + } +#endif +return 0 ; +} + +static void mxs_usb_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_usb_init; +} + +static TypeInfo mxs_usb_info = { + .name ="mxs_usb" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_usb_state), + .class_init = mxs_usb_class_init, +}; +
hw/usb/mxs_usb.c line 148
Quoted 10 lines
hw/usb/mxs_usb.c new file +10
-0+static void mxs_usb_register (void ) +{ +type_register_static (&mxs_usb_info); +} + +type_init(mxs_usb_register) + +#undef D +#define D (w) +
AFAICT, there is no connectivity between you EHCI and PHY (probably a good thing at this stage), leading me to believe your PHY is just a "keep the guest happy" dummy.
With no interconnectivity, It should be a separate device in a separate file and patch.
Regards,
Peter
Quoted 110 lines
hw/usb/mxs_usb.c new file +106
-1+enum { +USBPHY_PWD =0x0 , +USBPHY_TX =0x1 , +USBPHY_RX =0x2 , +USBPHY_CTRL =0x3 , +USBPHY_MAX =10 , +}; +typedef struct mxs_usbphy_state { +SysBusDevice busdev; +MemoryRegion iomem; + +uint32_t r[USBPHY_MAX ]; +}mxs_usbphy_state ; + +static uint64_t mxs_usbphy_read (void *opaque,hwaddr offset, +unsigned size) +{ +mxs_usbphy_state *s = (mxs_usbphy_state *) opaque; +uint32_t res =0 ; + + D(printf("%s %04x (%d) = ", __func__, (int)offset, size);) +switch (offset >>4 ) { + case 0 ... USBPHY_MAX: + res = s->r[offset >>4 ]; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +break ; + } + D(printf("%08x\n", res);) + +return res; +} + +static void mxs_usbphy_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +mxs_usbphy_state *s = (mxs_usbphy_state *) opaque; +uint32_t oldvalue =0 ; + + D(printf("%s %04x %08x(%d) = ", __func__, (int)offset, (int)value, size);) +switch (offset >>4 ) { + case 0 ... USBPHY_MAX: + oldvalue =mxs_write (&s->r[offset >>4 ], offset, value, size); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bad offset 0x%x\n" , __func__, (int ) offset); +return ; + } +switch (offset >>4 ) { +case USBPHY_CTRL : +if ((oldvalue ^ s->r[USBPHY_CTRL ]) ==0x80000000 + && !(oldvalue &0x80000000 )) { + D(printf("%s reseting, anding clockgate\n", __func__);) + s->r[USBPHY_CTRL] |= 0x40000000; + } +break ; + } + D(printf("%08x\n", s->r[offset >> 4]);) +} + + +static const MemoryRegionOps mxs_usbphy_ops = { + .read = mxs_usbphy_read, + .write = mxs_usbphy_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static int mxs_usbphy_init (SysBusDevice *dev) +{ +mxs_usbphy_state *s =OBJECT_CHECK (mxs_usbphy_state, dev,"mxs_usbphy" ); + +memory_region_init_io (&s->iomem,OBJECT (s), &mxs_usbphy_ops, s, +"mxs_usbphy" ,0x2000 ); +sysbus_init_mmio (dev, &s->iomem); + + s->r[USBPHY_PWD ] =0x00860607 ; + s->r[USBPHY_PWD ] =0x00860607 ; + s->r[USBPHY_CTRL ] =0xc0000000 ; +return 0 ; +} + + +static void mxs_usbphy_class_init (ObjectClass *klass,void *data) +{ +SysBusDeviceClass *sdc =SYS_BUS_DEVICE_CLASS (klass); + + sdc->init = mxs_usbphy_init; +} + +static TypeInfo usbphy_info = { + .name ="mxs_usbphy" , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (mxs_usbphy_state), + .class_init = mxs_usbphy_class_init, +}; + +static void mxs_usbphy_register (void ) +{ +type_register_static (&usbphy_info); +} + +type_init (mxs_usbphy_register) + --1.8.5.1