BestComm : better late than never heh ;)
Subsystems (3)
cover BestComm : better late than never heh ;)
Hi everyone,
Here we go : This series adds support for the BestComm engine found on the 5200 CPUs. This is _long_ overdue, I admit it ... but better late than never ;)
For the little story, Freescale does provide an API that is just ugly. A long time ago, Dale Farnsworth proposed a new API. It was a lot better but some things were still not right, some time after that Andrey Volkov & myself did some rework but still not enough and with the switch to arch/powerpc there was new stuff to be done ... Finally, I decided to give it a last go and here we are ...
A few words about theses patches : The first 3 are just preliminary stuff, then comes the core, followed by 3 tasks and finally two drivers. The drivers are not ready for upstream, they are just here so that people can test that it _does_ work.
About the API itself :
The API divides the work in three layers, trying to keep them as separate as possible :
1) Core : This is the grunt work, setting up tasks and global config. It also provides useful helpers for the other layers and debug help.
This is mainly bestcomm.c bestcomm.h bestcomm_priv.h sram.{c,h}
2) Task support : Each task may have a different way to configure it's buffer ring or other details. We hide the details of it in theses. The code in this "layer" has knowelge of bestcomm internals and can include "bestcomm_priv.h". The microcode files are mostly automatically extracted from the dma_image.hex image provided by freescale.
For the ata task: ata.h ata.c bcom_ata_task.c
For the fec task: fec.h fec.c bcom_fec_rx_task.c bcom_fec_tx_task.c For the genbd task: gen_bd.h gen_bd.c bcom_gen_bd_rx_task.c bcom_gen_bd_tx_task.c
3) Driver: Inside the driver, the knowelge of bestcomm internals is minimal. You just need to call the task support code to get your 'dma object' and then if the task is buffer descriptor based, you cal use the helper function to submit / retrieve bd.
I personnaly like this division because that hides microcode details from the driver and keeps it separate. It also keeps a lot of code common, independant of the _precise_ buffer descriptor format. They all have a status word followed by some address (the exact number depends of the task ...)
About some details of 'form':
- 'bcom_' sounded like a good prefix. sdma_ was used else where for another dma engine.
- arch/powerpc/sysdev/bestcomm sounded like a good place to put this.
Final note :
Is the API perfect ? probably not, but I think it's pretty good. And I hope you'll like it because I don't really feel like starting from scratch again ... ;)
The two things that I know I need to find a solution to are :
- Initiator priority shouldn't be fixed. The user should be able to provide it's own in the DT. (if none is found, just fall back to the default one)
- The link from device -> initiator number is ... not easy to make. Currently it's fixed (only one FEC so if someone wants the fec task that must be the FEC driver ...)
Sylvain
PATCH 1/9 powerpc: exports rheap symbol to modules
Theses can be useful in modules too. So we export them.
--- arch/powerpc/lib/rheap.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)
arch/powerpc/lib/rheap.c +17 -0
@@ -15,6 +15,7 @@#include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h> +#include <linux/module.h> #include <linux/mm.h> #include <linux/slab.h>
@@ -724,3 +725,19 @@ void rh_dump_blk(rh_info_t * info, rh_block_t * blk)"blk @0x%p: 0x%lx-0x%lx (%u)\n" , blk, blk->start, blk->start + blk->size, blk->size); } + + +EXPORT_SYMBOL (rh_create); +EXPORT_SYMBOL (rh_destroy); +EXPORT_SYMBOL (rh_init); +EXPORT_SYMBOL (rh_attach_region); +EXPORT_SYMBOL (rh_detach_region); +EXPORT_SYMBOL (rh_alloc_align); +EXPORT_SYMBOL (rh_alloc); +EXPORT_SYMBOL (rh_alloc_fixed); +EXPORT_SYMBOL (rh_free); +EXPORT_SYMBOL (rh_get_stats); +EXPORT_SYMBOL (rh_set_owner); +EXPORT_SYMBOL (rh_dump); +EXPORT_SYMBOL (rh_dump_blk); +
Signature · 1 line
1.5.1.2
PATCH 2/9 powerpc: Changes the config mechanism for rheap
Instead of having in the makefile all the option that requires rheap, we define a configuration symbol and when needed we make sure it's selected.
--- arch/powerpc/Kconfig | 2 ++ arch/powerpc/lib/Kconfig | 3 +++ arch/powerpc/lib/Makefile | 4 +--- arch/powerpc/platforms/Kconfig | 2 ++ 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/lib/Kconfig
arch/powerpc/Kconfig +2 -0
@@ -193,6 +193,7 @@ config PPC_8xx bool "Freescale 8xx" select FSL_SOC select 8xx + select PPC_LIB_RHEAP config 40x bool "AMCC 40x"
@@ -885,6 +886,7 @@ source "fs/Kconfig" source "arch/powerpc/sysdev/qe_lib/Kconfig" +source "arch/powerpc/lib/Kconfig" source "lib/Kconfig" menu "Instrumentation Support"
arch/powerpc/lib/Kconfig new file +3 -0
@@ -0,0 +1,3 @@ +config PPC_LIB_RHEAP + bool + default n
arch/powerpc/lib/Makefile +1 -3
@@ -13,7 +13,6 @@ endif obj-$(CONFIG_PPC64) += checksum_64.o copypage_64.o copyuser_64.o \ memcpy_64.o usercopy_64.o mem_64.o string.o -obj-$(CONFIG_QUICC_ENGINE) += rheap.o obj-$(CONFIG_XMON) += sstep.o obj-$(CONFIG_KPROBES) += sstep.o obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
@@ -23,5 +22,4 @@ obj-$(CONFIG_SMP) += locks.o endif # Temporary hack until we have migrated to asm-powerpc -obj-$(CONFIG_8xx) += rheap.o -obj-$(CONFIG_CPM2) += rheap.o +obj-$(CONFIG_PPC_LIB_RHEAP) += rheap.o
arch/powerpc/platforms/Kconfig +2 -0
@@ -242,6 +242,7 @@ config TAU_AVERAGE config QUICC_ENGINE bool + select PPC_LIB_RHEAP help The QUICC Engine (QE) is a new generation of communications coprocessors on Freescale embedded CPUs (akin to CPM in older chips).
@@ -251,6 +252,7 @@ config QUICC_ENGINE config CPM2 bool default n + select PPC_LIB_RHEAP help The CPM2 (Communications Processor Module) is a coprocessor on embedded CPUs made by Freescale. Selecting this option means that
Signature · 1 line
1.5.1.2
PATCH 3/9 powerpc/ppc32: Update mpc52xx_psc structure with B revision changes
On the mpc5200b the ccr register is 32 bits wide while on the mpc5200 it's only 16 bits. It's up to the driver to use the correct format depending on the chip it's running on.
The 5200b also offers some more registers & status in AC97 mode. Again, if not running on a 5200b the driver should not use those.
--- include/asm-ppc/mpc52xx_psc.h | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
include/asm-ppc/mpc52xx_psc.h +8 -2
@@ -28,6 +28,10 @@#define MPC52xx_PSC_MAXNUM 6/* Programmable Serial Controller (PSC) status register bits */ +#define MPC52xx_PSC_SR_UNEX_RX 0x0001 +#define MPC52xx_PSC_SR_DATA_VAL 0x0002 +#define MPC52xx_PSC_SR_DATA_OVR 0x0004 +#define MPC52xx_PSC_SR_CMDSEND 0x0008#define MPC52xx_PSC_SR_CDE 0x0080#define MPC52xx_PSC_SR_RXRDY 0x0100#define MPC52xx_PSC_SR_RXFULL 0x0200
@@ -132,8 +136,10 @@ struct mpc52xx_psc {u8 reserved5[3 ];u8 ctlr;/* PSC + 0x1c */ u8 reserved6[3 ]; -u16 ccr;/* PSC + 0x20 */ -u8 reserved7[14 ]; +u32 ccr;/* PSC + 0x20 */ +u32 ac97_slots;/* PSC + 0x24 */ +u32 ac97_cmd;/* PSC + 0x28 */ +u32 ac97_data;/* PSC + 0x2c */ u8 ivr;/* PSC + 0x30 */ u8 reserved8[3 ];u8 ip;/* PSC + 0x34 */
Signature · 1 line
1.5.1.2
PATCH 4/9 powerpc: BestComm core support for Freescale MPC5200
This patch adds support for the core of the BestComm API for the Freescale MPC5200(b). The BestComm engine is a microcode-controlled / tasks-based DMA used by several of the onchip devices.
Setting up the tasks / memory allocation and all common low level functions are handled by this patch. The specifics details of each tasks and their microcode are split-out in separate patches.
This is not the official API, but a much cleaner one.
--- arch/powerpc/platforms/Kconfig | 2 + arch/powerpc/sysdev/Makefile | 1 + arch/powerpc/sysdev/bestcomm/Kconfig | 18 + arch/powerpc/sysdev/bestcomm/Makefile | 8 + arch/powerpc/sysdev/bestcomm/bestcomm.c | 600 ++++++++++++++++++++++++++ arch/powerpc/sysdev/bestcomm/bestcomm.h | 136 ++++++ arch/powerpc/sysdev/bestcomm/bestcomm_priv.h | 325 ++++++++++++++ arch/powerpc/sysdev/bestcomm/sram.c | 180 ++++++++ arch/powerpc/sysdev/bestcomm/sram.h | 54 +++ 9 files changed, 1324 insertions(+), 0 deletions(-) create mode 100644 arch/powerpc/sysdev/bestcomm/Kconfig create mode 100644 arch/powerpc/sysdev/bestcomm/Makefile create mode 100644 arch/powerpc/sysdev/bestcomm/bestcomm.c create mode 100644 arch/powerpc/sysdev/bestcomm/bestcomm.h create mode 100644 arch/powerpc/sysdev/bestcomm/bestcomm_priv.h create mode 100644 arch/powerpc/sysdev/bestcomm/sram.c create mode 100644 arch/powerpc/sysdev/bestcomm/sram.h
arch/powerpc/platforms/Kconfig +2 -0
@@ -259,4 +259,6 @@ config CPM2 you wish to build a kernel for a machine with a CPM2 coprocessor on it (826x, 827x, 8560). +source "arch/powerpc/sysdev/bestcomm/Kconfig" + endmenu
arch/powerpc/sysdev/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_FSL_SOC) += fsl_soc.o obj-$(CONFIG_FSL_PCIE) += fsl_pcie.o obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o obj-$(CONFIG_QUICC_ENGINE) += qe_lib/ +obj-$(CONFIG_PPC_BESTCOMM) += bestcomm/ mv64x60-$(CONFIG_PCI) += mv64x60_pci.o obj-$(CONFIG_MV64X60) += $(mv64x60-y) mv64x60_pic.o mv64x60_dev.o
arch/powerpc/sysdev/bestcomm/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +# +# Kconfig options for Bestcomm +# + +config PPC_BESTCOMM + tristate "Bestcomm DMA engine support" + depends on PPC_MPC52xx + default n + select PPC_LIB_RHEAP + help + BestComm is the name of the communication coprocessor found + on the Freescale MPC5200 family of processor. It's usage is + optionnal for some drivers (like ATA), but required for + others (like FEC). + + If you want to use drivers that require DMA operations, + answer Y or M. Otherwise say N. +
arch/powerpc/sysdev/bestcomm/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# +# Makefile for BestComm & co +# + +bestcomm-core-objs := bestcomm.o sram.o + +obj-$(CONFIG_PPC_BESTCOMM) += bestcomm-core.o +
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +600 -0
600 lines not on this page · raw message
arch/powerpc/sysdev/bestcomm/bestcomm.h new file +136 -0
136 lines not on this page · raw message
arch/powerpc/sysdev/bestcomm/bestcomm_priv.h new file +325 -0
325 lines not on this page · raw message
arch/powerpc/sysdev/bestcomm/sram.c new file +180 -0
180 lines not on this page · raw message
arch/powerpc/sysdev/bestcomm/sram.h new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
1.5.1.2
PATCH 5/9 powerpc: BestcComm ATA task support
This is the microcode for the ATA task and the associated support code.
The microcode itself comes directly from the offical API (v2.2)
--- arch/powerpc/sysdev/bestcomm/Kconfig | 7 + arch/powerpc/sysdev/bestcomm/Makefile | 2 + arch/powerpc/sysdev/bestcomm/ata.c | 155 ++++++++++++++++++++++++++ arch/powerpc/sysdev/bestcomm/ata.h | 37 ++++++ arch/powerpc/sysdev/bestcomm/bcom_ata_task.c | 61 ++++++++++ 5 files changed, 262 insertions(+), 0 deletions(-) create mode 100644 arch/powerpc/sysdev/bestcomm/ata.c create mode 100644 arch/powerpc/sysdev/bestcomm/ata.h create mode 100644 arch/powerpc/sysdev/bestcomm/bcom_ata_task.c
arch/powerpc/sysdev/bestcomm/Kconfig +7 -0
@@ -16,3 +16,10 @@ config PPC_BESTCOMM If you want to use drivers that require DMA operations, answer Y or M. Otherwise say N. +config PPC_BESTCOMM_ATA + tristate "Bestcomm ATA task support" + depends on PPC_BESTCOMM + default n + help + This option enables the support for the ATA task. +
arch/powerpc/sysdev/bestcomm/Makefile +2 -0
@@ -3,6 +3,8 @@ # bestcomm-core-objs := bestcomm.o sram.o +bestcomm-ata-objs := ata.o bcom_ata_task.o obj-$(CONFIG_PPC_BESTCOMM) += bestcomm-core.o +obj-$(CONFIG_PPC_BESTCOMM_ATA) += bestcomm-ata.o
arch/powerpc/sysdev/bestcomm/ata.c new file +155 -0
155 lines not on this page · raw message
arch/powerpc/sysdev/bestcomm/ata.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Header for Bestcomm ATA task driver +* +* +* Copyright (C) 2006 Freescale - John Rigby +* Copyright (C) 2006 Sylvain Munaut <[email protected]> +* +* This file is licensed under the terms of the GNU General Public License +* version 2. This program is licensed "as is" without any warranty of any +* kind, whether express or implied. +*/ + +#ifndef __BESTCOMM_ATA_H__ +#define __BESTCOMM_ATA_H__ + + +struct bcom_ata_bd { +u32 status; +u32 dst_pa; +u32 src_pa; +}; + +extern struct bcom_task * +bcom_ata_init (int queue_len,int maxbufsize); + +extern void +bcom_ata_rx_prepare (struct bcom_task *tsk); + +extern void +bcom_ata_tx_prepare (struct bcom_task *tsk); + +extern void +bcom_ata_reset_bd (struct bcom_task *tsk); + + +#endif /* __BESTCOMM_ATA_H__ */ +
arch/powerpc/sysdev/bestcomm/bcom_ata_task.c new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
1.5.1.2
PATCH 6/9 powerpc: BestcComm FEC task support
This is the microcode for the FEC task and the associated support code.
The microcode itself comes directly from the offical API (v2.2)
--- arch/powerpc/sysdev/bestcomm/Kconfig | 7 + arch/powerpc/sysdev/bestcomm/Makefile | 2 + arch/powerpc/sysdev/bestcomm/bcom_fec_rx_task.c | 72 ++++++ arch/powerpc/sysdev/bestcomm/bcom_fec_tx_task.c | 85 +++++++ arch/powerpc/sysdev/bestcomm/fec.c | 271 +++++++++++++++++++++++ arch/powerpc/sysdev/bestcomm/fec.h | 48 ++++ 6 files changed, 485 insertions(+), 0 deletions(-) create mode 100644 arch/powerpc/sysdev/bestcomm/bcom_fec_rx_task.c create mode 100644 arch/powerpc/sysdev/bestcomm/bcom_fec_tx_task.c create mode 100644 arch/powerpc/sysdev/bestcomm/fec.c create mode 100644 arch/powerpc/sysdev/bestcomm/fec.h
arch/powerpc/sysdev/bestcomm/Kconfig +7 -0
@@ -23,3 +23,10 @@ config PPC_BESTCOMM_ATA help This option enables the support for the ATA task. +config PPC_BESTCOMM_FEC + tristate "Bestcomm FEC tasks support" + depends on PPC_BESTCOMM + default n + help + This option enables the support for the FEC tasks. +
arch/powerpc/sysdev/bestcomm/Makefile +2 -0
@@ -4,7 +4,9 @@ bestcomm-core-objs := bestcomm.o sram.o bestcomm-ata-objs := ata.o bcom_ata_task.o +bestcomm-fec-objs := fec.o bcom_fec_rx_task.o bcom_fec_tx_task.o obj-$(CONFIG_PPC_BESTCOMM) += bestcomm-core.o obj-$(CONFIG_PPC_BESTCOMM_ATA) += bestcomm-ata.o +obj-$(CONFIG_PPC_BESTCOMM_FEC) += bestcomm-fec.o
arch/powerpc/sysdev/bestcomm/bcom_fec_rx_task.c new file +72 -0
72 lines not on this page · raw message
arch/powerpc/sysdev/bestcomm/bcom_fec_tx_task.c new file +85 -0
85 lines not on this page · raw message
arch/powerpc/sysdev/bestcomm/fec.c new file +271 -0
271 lines not on this page · raw message
arch/powerpc/sysdev/bestcomm/fec.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
1.5.1.2
PATCH 7/9 powerpc: BestcComm GenBD task support
This is the microcode for the GenBD task and the associated support code. This is a generic task that copy data to/from a hardware FIFO. This is currently locked to 32bits wide access but could be extended as needed.
The microcode itself comes directly from the offical API (v2.2)
--- arch/powerpc/sysdev/bestcomm/Kconfig | 7 + arch/powerpc/sysdev/bestcomm/Makefile | 2 + arch/powerpc/sysdev/bestcomm/bcom_gen_bd_rx_task.c | 62 +++++ arch/powerpc/sysdev/bestcomm/bcom_gen_bd_tx_task.c | 68 +++++ arch/powerpc/sysdev/bestcomm/gen_bd.c | 261 ++++++++++++++++++++ arch/powerpc/sysdev/bestcomm/gen_bd.h | 48 ++++ 6 files changed, 448 insertions(+), 0 deletions(-) create mode 100644 arch/powerpc/sysdev/bestcomm/bcom_gen_bd_rx_task.c create mode 100644 arch/powerpc/sysdev/bestcomm/bcom_gen_bd_tx_task.c create mode 100644 arch/powerpc/sysdev/bestcomm/gen_bd.c create mode 100644 arch/powerpc/sysdev/bestcomm/gen_bd.h
arch/powerpc/sysdev/bestcomm/Kconfig +7 -0
@@ -30,3 +30,10 @@ config PPC_BESTCOMM_FEC help This option enables the support for the FEC tasks. +config PPC_BESTCOMM_GEN_BD + tristate "Bestcomm GenBD tasks support" + depends on PPC_BESTCOMM + default n + help + This option enables the support for the GenBD tasks. +
arch/powerpc/sysdev/bestcomm/Makefile +2 -0
@@ -5,8 +5,10 @@ bestcomm-core-objs := bestcomm.o sram.o bestcomm-ata-objs := ata.o bcom_ata_task.o bestcomm-fec-objs := fec.o bcom_fec_rx_task.o bcom_fec_tx_task.o +bestcomm-gen-bd-objs := gen_bd.o bcom_gen_bd_rx_task.o bcom_gen_bd_tx_task.o obj-$(CONFIG_PPC_BESTCOMM) += bestcomm-core.o obj-$(CONFIG_PPC_BESTCOMM_ATA) += bestcomm-ata.o obj-$(CONFIG_PPC_BESTCOMM_FEC) += bestcomm-fec.o +obj-$(CONFIG_PPC_BESTCOMM_GEN_BD) += bestcomm-gen-bd.o
arch/powerpc/sysdev/bestcomm/bcom_gen_bd_rx_task.c new file +62 -0
62 lines not on this page · raw message
arch/powerpc/sysdev/bestcomm/bcom_gen_bd_tx_task.c new file +68 -0
68 lines not on this page · raw message
arch/powerpc/sysdev/bestcomm/gen_bd.c new file +261 -0
261 lines not on this page · raw message
arch/powerpc/sysdev/bestcomm/gen_bd.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
1.5.1.2
PATCH 8/9 drivers/net: Add support for Freescale MPC5200 SoC internal FEC.
Not quite a clean driver, but it get things done. Only included to be able to test functionalityi/usage of the BestComm driver.
--- drivers/net/Kconfig | 1 + drivers/net/Makefile | 1 + drivers/net/fec_mpc52xx/Kconfig | 24 ++ drivers/net/fec_mpc52xx/Makefile | 7 + drivers/net/fec_mpc52xx/fec.c | 813 +++++++++++++++++++++++++++++++++++++ drivers/net/fec_mpc52xx/fec.h | 306 ++++++++++++++ drivers/net/fec_mpc52xx/fec_phy.c | 526 ++++++++++++++++++++++++ drivers/net/fec_mpc52xx/fec_phy.h | 73 ++++ 8 files changed, 1751 insertions(+), 0 deletions(-) create mode 100644 drivers/net/fec_mpc52xx/Kconfig create mode 100644 drivers/net/fec_mpc52xx/Makefile create mode 100644 drivers/net/fec_mpc52xx/fec.c create mode 100644 drivers/net/fec_mpc52xx/fec.h create mode 100644 drivers/net/fec_mpc52xx/fec_phy.c create mode 100644 drivers/net/fec_mpc52xx/fec_phy.h
drivers/net/Kconfig +1 -0
@@ -1890,6 +1890,7 @@ config NE_H8300 controller on the Renesas H8/300 processor. source "drivers/net/fec_8xx/Kconfig" +source "drivers/net/fec_mpc52xx/Kconfig" source "drivers/net/fs_enet/Kconfig" endmenu
drivers/net/Makefile +1 -0
@@ -196,6 +196,7 @@ obj-$(CONFIG_SMC91X) += smc91x.o obj-$(CONFIG_SMC911X) += smc911x.o obj-$(CONFIG_DM9000) += dm9000.o obj-$(CONFIG_FEC_8XX) += fec_8xx/ +obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx/ obj-$(CONFIG_PASEMI_MAC) += pasemi_mac.o obj-$(CONFIG_MLX4_CORE) += mlx4/
drivers/net/fec_mpc52xx/Kconfig new file +24 -0
@@ -0,0 +1,24 @@ +menu "MPC5200 Networking Options" + depends PPC_MPC52xx && NET_ETHERNET + +config FEC_MPC52xx + tristate "FEC Ethernet" + depends on NET_ETHERNET + select PPC_BESTCOMM + select PPC_BESTCOMM_FEC + select CRC32 + ---help--- + This option enables support for the MPC5200's on-chip + Fast Ethernet Controller + +config USE_MDIO + bool "Use external Ethernet MII PHY" + select MII + depends FEC_MPC52xx + ---help--- + The MPC5200's FEC can connect to the Ethernet either with + an external MII PHY chip or 10 Mbps 7-wire interface + (Motorola? industry standard). + If your board uses an external PHY, say y, else n. + +endmenu
drivers/net/fec_mpc52xx/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx.o + +fec_mpc52xx-objs := fec.o + +ifeq ($(CONFIG_USE_MDIO),y) +fec_mpc52xx-objs += fec_phy.o +endif
drivers/net/fec_mpc52xx/fec.c new file +813 -0
813 lines not on this page · raw message
drivers/net/fec_mpc52xx/fec.h new file +306 -0
306 lines not on this page · raw message
drivers/net/fec_mpc52xx/fec_phy.c new file +526 -0
526 lines not on this page · raw message
drivers/net/fec_mpc52xx/fec_phy.h new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
1.5.1.2
PATCH 9/9 sound: Add support for Freescale MPC5200 AC97 interface.
Not quite a clean driver, but it get things done (well, mostly).
Only included to be able to test functionalityi/usage of the BestComm driver.
--- sound/ppc/Kconfig | 16 + sound/ppc/Makefile | 3 + sound/ppc/mpc52xx_ac97.c | 870 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 889 insertions(+), 0 deletions(-) create mode 100644 sound/ppc/mpc52xx_ac97.c
sound/ppc/Kconfig +16 -0
@@ -33,3 +33,19 @@ config SND_POWERMAC_AUTO_DRC option. endmenu + + +# ALSA ppc drivers + +menu "ALSA PPC devices" + depends on SND!=n && PPC + +config SND_PPC_MPC52xx_AC97 + tristate "Freescale MPC52xx AC97 interface support" + depends on SND && PPC_MPC52xx + select SND_AC97_CODEC + help + Say Y or M if you want to support any AC97 codec attached to + the Freescqle MPC52xx AC97 interface. + +endmenu
sound/ppc/Makefile +3 -0
@@ -4,6 +4,9 @@ # snd-powermac-objs := powermac.o pmac.o awacs.o burgundy.o daca.o tumbler.o keywest.o beep.o +snd-mpc52xx-ac97-objs := mpc52xx_ac97.o # Toplevel Module Dependency obj-$(CONFIG_SND_POWERMAC) += snd-powermac.o + +obj-$(CONFIG_SND_PPC_MPC52xx_AC97) += snd-mpc52xx-ac97.o
sound/ppc/mpc52xx_ac97.c new file +870 -0
870 lines not on this page · raw message
Signature · 1 line
1.5.1.2
Re: [PATCH 4/9] powerpc: BestComm core support for Freescale MPC5200
In reply to Sylvain MunautQuoted 4 lines · Sylvain Munaut
This patch adds support for the core of the BestComm API for the Freescale MPC5200(b). The BestComm engine is a microcode-controlled / tasks-based DMA used by several of the onchip devices.
Have you tried if the DMA engine API that is now in drivers/dma fits the hardware interfaces? Could they perhaps be extended to do so?
Quoted 1 line
+struct
bcom_engine*bcom = NULL;
Doe this need to be a global? In most cases, you get a cleaner driver by passing around pointers through function calls and your own device specific data structures.
If you can't make that work, at least give it a longer name to make sure it doesn't conflict with other global variables.
arch/powerpc/sysdev/bestcomm/bestcomm.c line 41
Quoted 7 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +7
-0+/* ======================================================================== */ +/* Public and private API */ +/* ======================================================================== */ + +/* Debug Dump */ + +#define BCOM_DPRINTK(a,b...) printk(KERN_DEBUG DRIVER_NAME ": " a, ## b)
just use pr_debug in new code instead of defining your own
Quoted 4 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +4
-0+static int __init +mpc52xx_bcom_init (void ) +{ +struct device_node *ofn_bcom, *ofn_sram;
arch/powerpc/sysdev/bestcomm/bestcomm.c line 465
Quoted 10 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +10
-0+struct resource res_bcom; + +int rv; + +/* Find the bestcomm node. If none, fails 'silently' since +* we may just be on another platform */ + ofn_bcom =of_find_compatible_node ( +NULL ,"dma-controller" ,"mpc5200-bestcomm" ); +if (!ofn_bcom) +return -ENODEV ;
I know, my usual rant is getting old, but why is this one not an of_platform_driver? It's not shared with arch/ppc or with arch/mips, and it's not needed before module_init() time.
arch/powerpc/sysdev/bestcomm/bestcomm.c line 581
Quoted 11 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +11
-0+ +#ifdef MODULE +module_init (mpc52xx_bcom_init); +module_exit (mpc52xx_bcom_exit); +#endif + +/* If we're not a module, we must make sure everything is setup before anyone */ +/* tries to use us ... */ +#ifndef MODULE +subsys_initcall (mpc52xx_bcom_init); +#endif
You can make it subsys_initcall() unconditionally. If the driver gets built as a module, it will turn into module_init() by itself.
arch/powerpc/sysdev/bestcomm/bestcomm.c line 587
Quoted 5 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +5
-0+MODULE_DESCRIPTION ("Freescale MPC52xx BestComm DMA" ); +MODULE_AUTHOR ("Sylvain Munaut <[email protected]>" ); +MODULE_AUTHOR ("Andrey Volkov <[email protected]>" ); +MODULE_AUTHOR ("Dale Farnsworth <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );
I didn't know that you could have multiple MODULE_AUTHOR statements. Does this do the right thing with /bin/modinfo?
arch/powerpc/sysdev/bestcomm/bestcomm.c line 599
Quoted 10 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +10
-0+EXPORT_SYMBOL (bcom); +EXPORT_SYMBOL (bcom_dump_status); +EXPORT_SYMBOL (bcom_dump_task); +EXPORT_SYMBOL (bcom_dump_bdring); +EXPORT_SYMBOL (bcom_task_alloc); +EXPORT_SYMBOL (bcom_task_release); +EXPORT_SYMBOL (bcom_load_image); +EXPORT_SYMBOL (bcom_set_initiator); +EXPORT_SYMBOL (bcom_enable); +EXPORT_SYMBOL (bcom_disable);
Please put every EXPORT_SYMBOL right after the definition of the symbol you are exporting.
Why don't you use EXPORT_SYMBOL_GPL?
arch/powerpc/sysdev/bestcomm/sram.c line 180
Quoted 8 lines
arch/powerpc/sysdev/bestcomm/sram.c new file +8
-0+ +EXPORT_SYMBOL (bcom_sram); + +EXPORT_SYMBOL (bcom_sram_init); +EXPORT_SYMBOL (bcom_sram_cleanup); +EXPORT_SYMBOL (bcom_sram_alloc); +EXPORT_SYMBOL (bcom_sram_free); +
Same comment as above.
Arnd <><
Re: [PATCH 5/9] powerpc: BestcComm ATA task support
In reply to Sylvain Munautarch/powerpc/sysdev/bestcomm/ata.c line 150
Quoted 6 lines · Sylvain Munaut
arch/powerpc/sysdev/bestcomm/ata.c new file +6
-0+ +EXPORT_SYMBOL (bcom_ata_init); +EXPORT_SYMBOL (bcom_ata_rx_prepare); +EXPORT_SYMBOL (bcom_ata_tx_prepare); +EXPORT_SYMBOL (bcom_ata_reset); +EXPORT_SYMBOL (bcom_ata_release);
See my comment in 4/9: why not EXPORT_SYMBOL_GPL?
Quoted 31 lines
arch/powerpc/sysdev/bestcomm/bcom_ata_task.c new file +31
-0+u32 bcom_ata_task[] = { +/* header */ +0x4243544b , +0x0e060709 , +0x00000000 , +0x00000000 , + +/* Task descriptors */ +0x8198009b ,/* LCD: idx0 = var3; idx0 <= var2; idx0 += inc3 */ +0x13e00c08 ,/* DRD1A: var3 = var1; FN=0 MORE init=31 WS=0 RS=0 */ +0xb8000264 ,/* LCD: idx1 = *idx0, idx2 = var0; idx1 < var9; idx1 += inc4, idx2 += inc4 */ +0x10000f00 ,/* DRD1A: var3 = idx0; FN=0 MORE init=0 WS=0 RS=0 */ +0x60140002 ,/* DRD2A: EU0=0 EU1=0 EU2=0 EU3=2 EXT init=0 WS=2 RS=2 */ +0x0c8cfc8a ,/* DRD2B1: *idx2 = EU3(); EU3(*idx2,var10) */ +0xd8988240 ,/* LCDEXT: idx1 = idx1; idx1 > var9; idx1 += inc0 */ +0xf845e011 ,/* LCDEXT: idx2 = *(idx0 + var00000015); ; idx2 += inc2 */ +0xb845e00a ,/* LCD: idx3 = *(idx0 + var00000019); ; idx3 += inc1 */ +0x0bfecf90 ,/* DRD1A: *idx3 = *idx2; FN=0 TFD init=31 WS=3 RS=3 */ +0x9898802d ,/* LCD: idx1 = idx1; idx1 once var0; idx1 += inc5 */ +0x64000005 ,/* DRD2A: EU0=0 EU1=0 EU2=0 EU3=5 INT EXT init=0 WS=0 RS=0 */ +0x0c0cf849 ,/* DRD2B1: *idx0 = EU3(); EU3(idx1,var9) */ +0x000001f8 ,/* NOP */ + +/* VAR[9]-VAR[14] */ +0x40000000 , +0x7fff7fff , +0x00000000 , +0x00000000 , +0x00000000 , +0x00000000 , +
arch/powerpc/sysdev/bestcomm/bcom_ata_task.c line 61
Quoted 10 lines
arch/powerpc/sysdev/bestcomm/bcom_ata_task.c new file +10
-0+/* INC[0]-INC[6] */ +0x40000000 , +0xe0000000 , +0xe0000000 , +0xa000000c , +0x20000000 , +0x00000000 , + 0x00000000, +}; +
Does it make any sense to define these symbolically? It's entirely nonobvious what all these magic numbers do. Maybe at least give the URL of the document that this comes from.
Arnd <><
Re: [PATCH 4/9] powerpc: BestComm core support for Freescale MPC5200
In reply to Arnd BergmannHi Arnd,
Quoted 10 lines · Arnd Bergmann
Quoted 4 lines · Sylvain Munaut
This patch adds support for the core of the BestComm API for the Freescale MPC5200(b). The BestComm engine is a microcode-controlled / tasks-based DMA used by several of the onchip devices.
Have you tried if the DMA engine API that is now in
drivers/dmafits the hardware interfaces? Could they perhaps be extended to do so?
BestComm has some pretty specific needs and I think trying to somehow extends a generic interface to fit those needs would just pollute it.
However, you could totally implement a "DMA devices" that would just use a simple "copy from there to there" task using this BestComm driver. So other part of the kernel (like network) could use that interface to use the dma engine ...
Quoted 8 lines
Quoted 1 line
+struct
bcom_engine*bcom = NULL;Doe this need to be a global? In most cases, you get a cleaner driver by passing around pointers through function calls and your own device specific data structures.
If you can't make that work, at least give it a longer name to make sure it doesn't conflict with other global variables.
Yes, it kinda needs to be global. It's used in many many places. I didn't like it much but I finally resigned because it ends up being a lot easier, and more readable code to have it global.
I can rename it bcom_eng, quite unlikely to conflict.
Quoted 10 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c line 41
Quoted 7 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +7
-0+/* ======================================================================== */ +/* Public and private API */ +/* ======================================================================== */ + +/* Debug Dump */ + +#define BCOM_DPRINTK(a,b...) printk(KERN_DEBUG DRIVER_NAME ": " a, ## b)just use
pr_debugin new code instead of defining your own
Noted, will be fixed.
Quoted 10 lines
Quoted 10 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +10
-0+static int __init +mpc52xx_bcom_init (void ) +{ +struct device_node *ofn_bcom, *ofn_sram; +struct resource res_bcom; + +int rv; + +/* Find the bestcomm node. If none, fails 'silently' since +* we may just be on another platform */
Quoted 8 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c line 465
Quoted 4 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +4
-0+ ofn_bcom =of_find_compatible_node ( +NULL ,"dma-controller" ,"mpc5200-bestcomm" ); +if (!ofn_bcom) +return -ENODEV ;I know, my usual rant is getting old, but why is this one not an
of_platform_driver? It's not shared witharch/ppcor witharch/mips, and it's not needed beforemodule_init()time.
It needs to be initialized before _any_ other driver that uses bestcomm. When compiled as module that could be an of_platform_driver but when built-in there is apparently no way to ensure it's going to be probed first. (At least no clean way ... )
Quoted 6 lines
Quoted 6 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +6
-0+ +#ifdef MODULE +module_init (mpc52xx_bcom_init); +module_exit (mpc52xx_bcom_exit); +#endif +
Quoted 8 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c line 581
Quoted 5 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +5
-0+/* If we're not a module, we must make sure everything is setup before anyone */ +/* tries to use us ... */ +#ifndef MODULE +subsys_initcall (mpc52xx_bcom_init); +#endif You can make it
subsys_initcall()unconditionally. If the driver gets built as a module, it will turn intomodule_init()by itself.
Oh, great, I didn't know that. I guess the module_exit still has to be conditionnal.
Quoted 8 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c line 587
Quoted 5 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +5
-0+MODULE_DESCRIPTION ("Freescale MPC52xx BestComm DMA" ); +MODULE_AUTHOR ("Sylvain Munaut <[email protected]>" ); +MODULE_AUTHOR ("Andrey Volkov <[email protected]>" ); +MODULE_AUTHOR ("Dale Farnsworth <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );I didn't know that you could have multiple
MODULE_AUTHORstatements. Does this do the right thing with/bin/modinfo?
I wasn't sure before I tried it myself. And it worked, so I used it ;)
tnt@efika:~$ /sbin/modinfo bestcomm-core filename: /lib/modules/2.6.21-efika-g4f18984a-dirty/kernel/arch/powerpc/sysdev/bestcomm/bestcomm-core.ko license: GPL v2 author: Sylvain Munaut <[email protected]> author: Andrey Volkov <[email protected]> author: Dale Farnsworth <[email protected]> description: Freescale MPC52xx BestComm DMA depends: vermagic: 2.6.21-efika-g4f18984a-dirty mod_unload
Quoted 5 lines
Quoted 5 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +5
-0+EXPORT_SYMBOL (bcom); +EXPORT_SYMBOL (bcom_dump_status); +EXPORT_SYMBOL (bcom_dump_task); +EXPORT_SYMBOL (bcom_dump_bdring); +EXPORT_SYMBOL (bcom_task_alloc);
Quoted 8 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c line 599
Quoted 5 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +5
-0+EXPORT_SYMBOL (bcom_task_release); +EXPORT_SYMBOL (bcom_load_image); +EXPORT_SYMBOL (bcom_set_initiator); +EXPORT_SYMBOL (bcom_enable); +EXPORT_SYMBOL (bcom_disable);Please put every
EXPORT_SYMBOLright after the definition of the symbol you are exporting.
Ok, I've seen both style I didn't know which to use.
Quoted 1 line
Why don't you use
EXPORT_SYMBOL_GPL?
Why would I ? Is it mandatory now ?
I don't really have an objection to non-gpl modules to use the exported functions ...
If Dale or Andrey have, they're free to post a patch to change to _GPL.
Sylvain
Re: [PATCH 4/9] powerpc: BestComm core support for Freescale MPC5200
Quoted 3 lines · Sylvain Munaut
BestComm has some pretty specific needs and I think trying to somehow extends a generic interface to fit those needs would just pollute it.
ok.
Quoted 4 lines
However, you could totally implement a "DMA devices" that would just use a simple "copy from there to there" task using this BestComm driver. So other part of the kernel (like network) could use that interface to use the dma engine ...
Can it also do the advanced operations like XOR on DMA that the Intel ioat has? That would be even more interesting, I guess.
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +10
-0+static int __init +mpc52xx_bcom_init (void ) +{ +struct device_node *ofn_bcom, *ofn_sram; +struct resource res_bcom; + +int rv; + +/* Find the bestcomm node. If none, fails 'silently' since +* we may just be on another platform */ Quoted 8 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c line 465
Quoted 4 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +4
-0+ ofn_bcom =of_find_compatible_node ( +NULL ,"dma-controller" ,"mpc5200-bestcomm" ); +if (!ofn_bcom) +return -ENODEV ;I know, my usual rant is getting old, but why is this one not an
of_platform_driver? It's not shared witharch/ppcor witharch/mips, and it's not needed beforemodule_init()time.
Quoted 4 lines
It needs to be initialized before _any_ other driver that uses bestcomm. When compiled as module that could be an
of_platform_driverbut when built-in there is apparently no way to ensure it's going to be probed first. (At least no clean way ... )
Initialization order is always a little tricky, but if you use a subsys_initcall, it should at least come before any regular driver like network or disk, and arch/ drivers come before any code in drivers/, so I don't see much of a problem here.
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +6
-0+ +#ifdef MODULE +module_init (mpc52xx_bcom_init); +module_exit (mpc52xx_bcom_exit); +#endif +Quoted 8 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c line 581
Quoted 5 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +5
-0+/* If we're not a module, we must make sure everything is setup before anyone */ +/* tries to use us ... */ +#ifndef MODULE +subsys_initcall (mpc52xx_bcom_init); +#endif You can make it
subsys_initcall()unconditionally. If the driver gets built as a module, it will turn intomodule_init()by itself.
Quoted 2 lines
Oh, great, I didn't know that. I guess the
module_exitstill has to be conditionnal.
No, it's designed so that you don't need any #ifdef. The module_exit function can simply be left out entirely when doing a builtin driver.
Quoted 4 lines
Quoted 1 line
Why don't you use
EXPORT_SYMBOL_GPL?Why would I ? Is it mandatory now ?
I don't really have an objection to non-gpl modules to use the exported functions ...
It's your choice, but there is a strong recommendation to use _GPL for all new interfaces nowadays. If you don't, people might suspect that you have a hidden agenda and actually plan to do non-gpl modules yourself.
However, this is a legal minefield and I'm not trying to force you to change it, it is always the decision of the copyright holder.
Arnd <><
Re: [PATCH 4/9] powerpc: BestComm core support for Freescale MPC5200
In reply to Sylvain MunautQuoted 6 lines · Sylvain Munaut
Quoted 1 line · Arnd Bergmann
Why don't you use
EXPORT_SYMBOL_GPL?Why would I ? Is it mandatory now ?
I don't really have an objection to non-gpl modules to use the exported functions ...
If Dale or Andrey have, they're free to post a patch to change to_GPL.
Hi Sylvain,
The general recommendation is to use EXPORT_SYMBOL_GPL unless there is some overriding reason not to. I agree with that recommendation. That's my preference for this code, but I'll defer to you Sylvain.
BTW, it's great to see this code being submitted.
-Dale Farnsworth
Re: [PATCH 4/9] powerpc: BestComm core support for Freescale MPC5200
In reply to Arnd BergmannQuoted 10 lines
Quoted 6 lines
However, you could totally implement a "DMA devices" that would just use a simple "copy from there to there" task using this BestComm driver. So other part of the kernel (like network) could use that interface to use the dma engine ...
Can it also do the advanced operations like XOR on DMA that the Intel ioat has? That would be even more interesting, I guess.
Actually yes it can.
It just need someone motivated enough to write it ;)
Quoted 25 lines
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +10
-0+static int __init +mpc52xx_bcom_init (void ) +{ +struct device_node *ofn_bcom, *ofn_sram; +struct resource res_bcom; + +int rv; + +/* Find the bestcomm node. If none, fails 'silently' since +* we may just be on another platform */ Quoted 9 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c line 465
Quoted 5 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +4
-0+ ofn_bcom =of_find_compatible_node ( +NULL ,"dma-controller" ,"mpc5200-bestcomm" ); +if (!ofn_bcom) +return -ENODEV ;I know, my usual rant is getting old, but why is this one not an
of_platform_driver? It's not shared witharch/ppcor witharch/mips, and it's not needed beforemodule_init()time.Quoted 5 lines
It needs to be initialized before _any_ other driver that uses bestcomm. When compiled as module that could be an
of_platform_driverbut when built-in there is apparently no way to ensure it's going to be probed first. (At least no clean way ... )
Quoted 5 lines
Initialization order is always a little tricky, but if you use a
subsys_initcall, it should at least come before any regular driver like network or disk, andarch/drivers come before any code indrivers/, so I don't see much of a problem here.
Mmm ... Silly of me but I didn't think of that.
I'll give it a shot.
(Actually before the transition to arch/powerpc, this was a platform_driver ...
but there I could control the probe order with ppc_sys ).
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Why don't you use
EXPORT_SYMBOL_GPL?Why would I ? Is it mandatory now ?
I don't really have an objection to non-gpl modules to use the exported functions ...
Quoted 5 lines
It's your choice, but there is a strong recommendation to use
_GPLfor all new interfaces nowadays. If you don't, people might suspect that you have a hidden agenda and actually plan to do non-gpl modules yourself.
Well if it's recommended ... And since Dale is in favor of it, so be it, I don't have any hidden agenda ;)
Sylvain
Re: [PATCH 4/9] powerpc: BestComm core support for Freescale MPC5200
Quoted 10 lines · Sylvain Munaut
Quoted 8 lines
Quoted 5 lines
However, you could totally implement a "DMA devices" that would just use a simple "copy from there to there" task using this BestComm driver. So other part of the kernel (like network) could use that interface to use the dma engine ...
Can it also do the advanced operations like XOR on DMA that the Intel ioat has? That would be even more interesting, I guess.
Actually yes it can.
It just need someone motivated enough to write it ;)
Isn't there an XOR-while-copying-DMA example somewhere?
I'm sure I've seen reference to it, or it being used somewhere.. to be honest the worst part of using BestComm is it's only well documented on how to use tasks and how to set up the engine, actually writing them is some kind of black art which Freescale hold close to their chest.
Signature · 2 lines
Matt Sealey <[email protected]> Genesi, Manager, Developer Relations
Re: [PATCH 3/9] powerpc/ppc32: Update mpc52xx_psc structure with B revision changes
In reply to Sylvain MunautWould a note next to these new fields be worth it? "5200B only" or "reserved on 5200" or even create a new PSC structure for the old processor and recast it in drivers that really want to support both revisions of the CPU?
Real nitpick:
Setting the CCR on the MPC5200 (not B) now means you need to left shift your required CCR values by 16 bits before applying them into the field for the desired effect.
If you were being lazy and just wanted to set some low-order bits in the CCR on the 5200, with the old structure that's fine. With the new structure, it will be writing into previously reserved space on the 5200. The 5200B might work fine, unless it's a driver someone missed, and is programming a value that should be in the upper 16 bits of the new CCR, in which case now you have to left shift by 16 bits.. :)
I don't suppose it matters a great deal (who uses an original MPC5200?), but it would be an intrusive change if any drivers did actually use the CCR already.. it's nice to mention somewhere though, I guess.
Signature · 2 lines
Matt Sealey <[email protected]> Genesi, Manager, Developer Relations
Quoted 41 lines · Sylvain Munaut
On the mpc5200b the ccr register is 32 bits wide while on the mpc5200 it's only 16 bits. It's up to the driver to use the correct format depending on the chip it's running on.
The 5200b also offers some more registers & status in AC97 mode. Again, if not running on a 5200b the driver should not use those.
Signed-off-by Sylvain Munaut <[email protected]>--- include/asm-ppc/mpc52xx_psc.h | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)include/asm-ppc/mpc52xx_psc.h +8
-2@@ -28,6 +28,10 @@#define MPC52xx_PSC_MAXNUM 6/* Programmable Serial Controller (PSC) status register bits */ +#define MPC52xx_PSC_SR_UNEX_RX 0x0001 +#define MPC52xx_PSC_SR_DATA_VAL 0x0002 +#define MPC52xx_PSC_SR_DATA_OVR 0x0004 +#define MPC52xx_PSC_SR_CMDSEND 0x0008#define MPC52xx_PSC_SR_CDE 0x0080#define MPC52xx_PSC_SR_RXRDY 0x0100#define MPC52xx_PSC_SR_RXFULL 0x0200@@ -132,8 +136,10 @@ struct mpc52xx_psc {u8 reserved5[3 ];u8 ctlr;/* PSC + 0x1c */ u8 reserved6[3 ]; -u16 ccr;/* PSC + 0x20 */ -u8 reserved7[14 ]; +u32 ccr;/* PSC + 0x20 */ +u32 ac97_slots;/* PSC + 0x24 */ +u32 ac97_cmd;/* PSC + 0x28 */ +u32 ac97_data;/* PSC + 0x2c */ u8 ivr;/* PSC + 0x30 */ u8 reserved8[3 ];u8 ip;/* PSC + 0x34 */
Re: [PATCH 4/9] powerpc: BestComm core support for Freescale MPC5200
In reply to Matt SealeyQuoted 12 lines · Matt Sealey
Quoted 10 lines · Sylvain Munaut
Quoted 10 lines
Quoted 6 lines
However, you could totally implement a "DMA devices" that would just use a simple "copy from there to there" task using this BestComm driver. So other part of the kernel (like network) could use that interface to use the dma engine ...
Can it also do the advanced operations like XOR on DMA that the Intel ioat has? That would be even more interesting, I guess.
Quoted 6 lines
Quoted 3 lines
Actually yes it can.
It just need someone motivated enough to write it ;)Isn't there an XOR-while-copying-DMA example somewhere?
Never saw it. But in the gen BD task it's easy to find the DRD that really does the copy and using the hand assembly guide and the example DRD than auto-shutdown the task, it's possible to figure out how to replace that simple DRD by a one calling xor in EU3.
Quoted 5 lines
I'm sure I've seen reference to it, or it being used somewhere.. to be honest the worst part of using BestComm is it's only well documented on how to use tasks and how to set up the engine, actually writing them is some kind of black art which Freescale hold close to their chest.
No kidding ;)
Sylvain
Re: [PATCH 3/9] powerpc/ppc32: Update mpc52xx_psc structure with B revision changes
In reply to Matt SealeyQuoted 5 lines · Matt Sealey
Would a note next to these new fields be worth it? "5200B only" or "reserved on 5200" or even create a new PSC structure for the old processor and recast it in drivers that really want to support both revisions of the CPU?
A comment next to them yes, that looks a good idea. A new structure certainly not.
Quoted 6 lines
Real nitpick:
Setting the CCR on the MPC5200 (not B) now means you need to left shift your required CCR values by 16 bits before applying them into the field for the desired effect.
Quoted 7 lines
If you were being lazy and just wanted to set some low-order bits in the CCR on the 5200, with the old structure that's fine. With the new structure, it will be writing into previously reserved space on the 5200. The 5200B might work fine, unless it's a driver someone missed, and is programming a value that should be in the upper 16 bits of the new CCR, in which case now you have to left shift by 16 bits.. :)
I know about the ccr that's annoying.
I guess I could make ccr a union and have it contains ccr16 and ccr32.
Note that old driver will still work ... then most likely do out_be16(&psc->ccr, ...) and the &psc->ccr address didn't change. They will just have a warning because ccr is a u32 so &psc->ccr is a u32* and they give it to out_be16 ...
Sylvain
Re: [PATCH 3/9] powerpc/ppc32: Update mpc52xx_psc structure with B revision changes
Sylvain, thanks.
http://bbrv.blogspot.com/2007/05/not-waiting-for-world-to-change-ii.html
Read through the post. Your effort is being applied to good use.
R&B
Quoted 30 lines · Sylvain Munaut
Quoted 5 lines · Matt Sealey
Would a note next to these new fields be worth it? "5200B only" or "reserved on 5200" or even create a new PSC structure for the old processor and recast it in drivers that really want to support both revisions of the CPU?
A comment next to them yes, that looks a good idea. A new structure certainly not.
Quoted 6 lines
Real nitpick:
Setting the CCR on the MPC5200 (not B) now means you need to left shift your required CCR values by 16 bits before applying them into the field for the desired effect.
Quoted 7 lines
If you were being lazy and just wanted to set some low-order bits in the CCR on the 5200, with the old structure that's fine. With the new structure, it will be writing into previously reserved space on the 5200. The 5200B might work fine, unless it's a driver someone missed, and is programming a value that should be in the upper 16 bits of the new CCR, in which case now you have to left shift by 16 bits.. :)
I know about the ccr that's annoying.
I guess I could make ccr a union and have it contains ccr16 and ccr32.Note that old driver will still work ... then most likely do
out_be16(&psc->ccr, ...)and the&psc->ccraddress didn't change. They will just have a warning because ccr is a u32 so&psc->ccris a u32* and they give it toout_be16...
Quoted 5 lines
Sylvain
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev
Raquel and Bill
http://bbrv.blogspot.com
Re: [PATCH 2/9] powerpc: Changes the config mechanism for rheap
In reply to Sylvain MunautQuoted 4 lines · Sylvain Munaut
Instead of having in the makefile all the option that requires rheap, we define a configuration symbol and when needed we make sure it's selected.
Quoted 8 lines
Signed-off-by Sylvain Munaut <[email protected]>--- arch/powerpc/Kconfig | 2 ++ arch/powerpc/lib/Kconfig | 3 +++ arch/powerpc/lib/Makefile | 4 +--- arch/powerpc/platforms/Kconfig | 2 ++ 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/lib/Kconfig
You need to fixup arch/ppc as well since its now using rheap from arch/powerpc/lib.
- k
Quoted 75 lines
arch/powerpc/Kconfig +2
-0@@ -193,6 +193,7 @@ config PPC_8xx bool "Freescale 8xx" select FSL_SOC select 8xx + select PPC_LIB_RHEAP config 40x bool "AMCC 40x"@@ -885,6 +886,7 @@ source "fs/Kconfig" source "arch/powerpc/sysdev/qe_lib/Kconfig" +source "arch/powerpc/lib/Kconfig" source "lib/Kconfig" menu "Instrumentation Support"arch/powerpc/lib/Kconfig new file +3
-0@@ -0,0 +1,3 @@ +config PPC_LIB_RHEAP + bool + default narch/powerpc/lib/Makefile +1
-3@@ -13,7 +13,6 @@ endif obj-$(CONFIG_PPC64) += checksum_64.o copypage_64.o copyuser_64.o \ memcpy_64.o usercopy_64.o mem_64.o string.o -obj-$(CONFIG_QUICC_ENGINE) += rheap.o obj-$(CONFIG_XMON) += sstep.o obj-$(CONFIG_KPROBES) += sstep.o obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o@@ -23,5 +22,4 @@ obj-$(CONFIG_SMP) += locks.o endif # Temporary hack until we have migrated to asm-powerpc -obj-$(CONFIG_8xx) += rheap.o -obj-$(CONFIG_CPM2) += rheap.o +obj-$(CONFIG_PPC_LIB_RHEAP) += rheap.oarch/powerpc/platforms/Kconfig +1
-0@@ -242,6 +242,7 @@ config TAU_AVERAGE config QUICC_ENGINE bool + select PPC_LIB_RHEAP help The QUICC Engine (QE) is a new generation of communications coprocessors on Freescale embedded CPUs (akin to CPM in olderchips).
arch/powerpc/platforms/Kconfig +1
-0@@ -251,6 +252,7 @@ config QUICC_ENGINE config CPM2 bool default n + select PPC_LIB_RHEAP help The CPM2 (Communications Processor Module) is a coprocessor on embedded CPUs made by Freescale. Selecting this option means thatSignature · 5 lines
1.5.1.2 _______________________________________________ Linuxppc-dev mailing list [email protected] https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [PATCH 4/9] powerpc: BestComm core support for Freescale MPC5200
In reply to Sylvain MunautQuoted 11 lines · Sylvain Munaut
This patch adds support for the core of the BestComm API for the Freescale MPC5200(b). The BestComm engine is a microcode-controlled / tasks-based DMA used by several of the onchip devices.
Setting up the tasks / memory allocation and all common low level functions are handled by this patch. The specifics details of each tasks and their microcode are split-out in separate patches.
This is not the official API, but a much cleaner one.
Can you give more detail about how the API works.
Quoted 74 lines
Signed-off-by Sylvain Munaut <[email protected]>--- arch/powerpc/platforms/Kconfig | 2 + arch/powerpc/sysdev/Makefile | 1 + arch/powerpc/sysdev/bestcomm/Kconfig | 18 + arch/powerpc/sysdev/bestcomm/Makefile | 8 + arch/powerpc/sysdev/bestcomm/bestcomm.c | 600 +++++++++++++++ +++++++++++ arch/powerpc/sysdev/bestcomm/bestcomm.h | 136 ++++++ arch/powerpc/sysdev/bestcomm/bestcomm_priv.h | 325 ++++++++++++++ arch/powerpc/sysdev/bestcomm/sram.c | 180 ++++++++ arch/powerpc/sysdev/bestcomm/sram.h | 54 +++ 9 files changed, 1324 insertions(+), 0 deletions(-) create mode 100644 arch/powerpc/sysdev/bestcomm/Kconfig create mode 100644 arch/powerpc/sysdev/bestcomm/Makefile create mode 100644 arch/powerpc/sysdev/bestcomm/bestcomm.c create mode 100644 arch/powerpc/sysdev/bestcomm/bestcomm.h create mode 100644 arch/powerpc/sysdev/bestcomm/bestcomm_priv.h create mode 100644 arch/powerpc/sysdev/bestcomm/sram.c create mode 100644 arch/powerpc/sysdev/bestcomm/sram.harch/powerpc/platforms/Kconfig +2
-0@@ -259,4 +259,6 @@ config CPM2 you wish to build a kernel for a machine with a CPM2 coprocessor on it (826x, 827x, 8560). +source "arch/powerpc/sysdev/bestcomm/Kconfig" + endmenuarch/powerpc/sysdev/Makefile +1
-0@@ -16,6 +16,7 @@ obj-$(CONFIG_FSL_SOC) += fsl_soc.o obj-$(CONFIG_FSL_PCIE) += fsl_pcie.o obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o obj-$(CONFIG_QUICC_ENGINE) += qe_lib/ +obj-$(CONFIG_PPC_BESTCOMM) += bestcomm/ mv64x60-$(CONFIG_PCI) += mv64x60_pci.o obj-$(CONFIG_MV64X60) += $(mv64x60-y) mv64x60_pic.o mv64x60_dev.oarch/powerpc/sysdev/bestcomm/Kconfig new file +18
-0@@ -0,0 +1,18 @@ +# +# Kconfig options for Bestcomm +# + +config PPC_BESTCOMM + tristate "Bestcomm DMA engine support" + depends on PPC_MPC52xx + default n + select PPC_LIB_RHEAP + help + BestComm is the name of the communication coprocessor found + on the Freescale MPC5200 family of processor. It's usage is + optionnal for some drivers (like ATA), but required for + others (like FEC). + + If you want to use drivers that require DMA operations, + answer Y or M. Otherwise say N. +arch/powerpc/sysdev/bestcomm/Makefile new file +0
-0
arch/powerpc/sysdev/bestcomm/Makefile line 7
Quoted 7 lines
arch/powerpc/sysdev/bestcomm/Makefile new file +7
-0@@ -0,0 +1,8 @@ +# +# Makefile for BestComm & co +# + +bestcomm-core-objs := bestcomm.o sram.o + +obj-$(CONFIG_PPC_BESTCOMM) += bestcomm-core.o
Any reason why sram isn't on the ojb-$(CONFIG_PPC_BESTCOMM) line?
Quoted 55 lines
arch/powerpc/sysdev/bestcomm/Makefile new file +1
-0+arch/powerpc/sysdev/bestcomm/bestcomm.c new file +7
-0@@ -0,0 +1,600 @@ +/* +* Driver for MPC52xx processor BestComm peripheral controller +* +* +* Copyright (C) 2006-2007 Sylvain Munaut <[email protected]> +* Copyright (C) 2005 Varma Electronics Oy, +* ( by Andrey Volkov <avolkov@varma- el.com> )
+ * Copyright (C) 2003-2004 MontaVista, Software, Inc.
+ * ( by Dale Farnsworth
<[email protected]> )
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */arch/powerpc/sysdev/bestcomm/bestcomm.c new file +21
-0+ +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/slab.h> + +#include <asm/io.h> +#include <asm/irq.h> +#include <asm/prom.h> +#include <asm/mpc52xx.h> + +#include "sram.h" +#include "bestcomm_priv.h" +#include "bestcomm.h" + +#define DRIVER_NAME "bestcomm-core" + + +struct bcom_engine *bcom =NULL ; + + +/* ======================================================================== */ +/* Public and private
API */
+/* ======================================================================== */arch/powerpc/sysdev/bestcomm/bestcomm.c new file +4
-0+ +/* Debug Dump */ + +#define BCOM_DPRINTK(a,b...) printk(KERN_DEBUG DRIVER_NAME ": " a,
Quoted 1 line
## b)
We have dev_dbg and dev_printk can we not use them?
Quoted 91 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +11
-0+ +void +bcom_dump_status (void ) +{ +int i; +struct mpc52xx_sdma __iomem *r = bcom->regs; + +BCOM_DPRINTK ("BestComm status dump (pa=%08lx, va=%p)\n" , + bcom->regs_base, bcom->regs); +BCOM_DPRINTK (" taskBar = %08x\n" ,in_be32 (&r->taskBar)); + BCOM_DPRINTK(" currentPointer = %08x\n", in_be32(&r-Quoted 1 line
currentPointer));
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +2
-0+BCOM_DPRINTK (" endPointer = %08x\n" ,in_be32 (&r->endPointer)); + BCOM_DPRINTK(" variablePointer = %08x\n", in_be32(&r-Quoted 1 line
variablePointer));
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +76
-0+BCOM_DPRINTK (" IntVect1 = %08x\n" , (u32 )in_8 (&r->IntVect1)); +BCOM_DPRINTK (" IntVect2 = %08x\n" , (u32 )in_8 (&r->IntVect2)); +BCOM_DPRINTK (" PtdCntrl = %08hx\n" ,in_be16 (&r->PtdCntrl)); +BCOM_DPRINTK (" IntPend = %08x\n" ,in_be32 (&r->IntPend)); +BCOM_DPRINTK (" IntMask = %08x\n" ,in_be32 (&r->IntMask)); + +BCOM_DPRINTK (" TCR dump :\n" ); + +for (i=0 ; i<16 ; i++) { +printk ("%s%04hx%s" , + (i&0x7 ) ==0x0 ?KERN_DEBUG "\t" :"" , +in_be16 (&r->tcr[i]), + (i&0x7 ) ==0x7 ?"\n" :" " ); + } + +BCOM_DPRINTK (" IPR dump :\n" ); + +for (i=0 ; i<32 ; i++) { +printk ("%s%02x%s" , + (i&0x7 ) ==0x0 ?KERN_DEBUG "\t" :"" , + (u32 )in_8 (&r->ipr[i]), + (i&0x7 ) ==0x7 ?"\n" :" " ); + } + +BCOM_DPRINTK (" cReqSelect = %08x\n" ,in_be32 (&r->cReqSelect)); +BCOM_DPRINTK (" task_size0 = %08x\n" ,in_be32 (&r->task_size0)); +BCOM_DPRINTK (" task_size1 = %08x\n" ,in_be32 (&r->task_size1)); +BCOM_DPRINTK (" MDEDebug = %08x\n" ,in_be32 (&r->MDEDebug)); +BCOM_DPRINTK (" ADSDebug = %08x\n" ,in_be32 (&r->ADSDebug)); +BCOM_DPRINTK (" Value1 = %08x\n" ,in_be32 (&r->Value1)); +BCOM_DPRINTK (" Value2 = %08x\n" ,in_be32 (&r->Value2)); +BCOM_DPRINTK (" Control = %08x\n" ,in_be32 (&r->Control)); +BCOM_DPRINTK (" Status = %08x\n" ,in_be32 (&r->Status)); +BCOM_DPRINTK (" PTDDebug = %08x\n" ,in_be32 (&r->PTDDebug)); +} + +void +bcom_dump_task (int task) +{ +int i; +u32 *p; +struct bcom_tdt *tdt = &bcom->tdt[task]; + +BCOM_DPRINTK ("Task dump %d\n" , task); +BCOM_DPRINTK (" tcr = %04hx\n" , bcom->regs->tcr[task]); +BCOM_DPRINTK (" tdt = %p\n" , &bcom->tdt[task]); +BCOM_DPRINTK (" tdt->start = %08x\n" , tdt->start); +BCOM_DPRINTK (" tdt->stop = %08x\n" , tdt->stop); +BCOM_DPRINTK (" tdt->var = %08x\n" , tdt->var); +BCOM_DPRINTK (" tdt->fdt = %08x\n" , tdt->fdt); +BCOM_DPRINTK (" tdt->status = %08x\n" , tdt->exec_status); +BCOM_DPRINTK (" tdt->mvtp = %08x\n" , tdt->mvtp); +BCOM_DPRINTK (" tdt->context = %08x\n" , tdt->context); +BCOM_DPRINTK (" tdt->litbase = %08x\n" , tdt->litbase); + +BCOM_DPRINTK (" code :\n" ); + + p =bcom_task_desc (task); +for (i=0 ; i<bcom_task_num_descs (task); i++) +printk (KERN_DEBUG "\t%p %08x\n" , &p[i], p[i]); + +BCOM_DPRINTK (" var/inc :\n" ); + + p =bcom_task_var (task); +for (i=0 ; i<BCOM_MAX_VAR +BCOM_MAX_INC ; i++) +printk (KERN_DEBUG "\t%p %08x\n" , &p[i], p[i]); +} + +void +bcom_dump_bdring (struct bcom_task *tsk) +{ +int i, j; + +BCOM_DPRINTK ("BD ring dump %d\n" , tsk->tasknum); + +for (i=0 ; i<tsk->num_bd; i++) {
arch/powerpc/sysdev/bestcomm/bestcomm.c line 140
Quoted 10 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +10
-0+BCOM_DPRINTK (" BD[%02d] :\n" , i); +BCOM_DPRINTK (" cookie : %p\n" , tsk->cookie[i]); +BCOM_DPRINTK (" status : %08x\n" , tsk->bd[i].status); +for (j=0 ; j<(tsk->bd_size/sizeof (u32))-1 ; j++) +BCOM_DPRINTK (" data[%02d] : %08x\n" , + j, tsk->bd[i].data[j]); + } +} + +
Would all bcom_dump_status(), bcom_dump_task(), bcom_dump_bdring be better using debugfs? At minimum there should be a Kconfig option to enable bestcomm debug that enables this code.
arch/powerpc/sysdev/bestcomm/bestcomm.c line 142
Quoted 2 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +2
-0+/* Private API */ +
What's private about it?
It would probably be good for the API functions to have DocBook style comments. See something like drivers/rapidio/rio.c for an example.
Quoted 58 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +58
-0+struct bcom_task * +bcom_task_alloc (int bd_count,int bd_size,int priv_size) +{ +int i, tasknum =-1 ; +struct bcom_task *tsk; + +/* Get and reserve a task num */ +spin_lock (&bcom->lock); + +for (i=0 ; i<BCOM_MAX_TASKS ; i++) +if (!bcom->tdt[i].stop) {/* we use stop as a marker */ + bcom->tdt[i].stop =0xfffffffful ;/* dummy addr */ + tasknum = i; +break ; + } + +spin_unlock (&bcom->lock); + +if (tasknum <0 ) +return NULL ; + +/* Allocate our structure */ + tsk =kzalloc (sizeof (struct bcom_task ) + priv_size,GFP_KERNEL ); +if (!tsk) + goto error; + + tsk->tasknum = tasknum; +if (priv_size) + tsk->priv = (void *)tsk +sizeof (struct bcom_task ); + +/* Get IRQ of that task */ + tsk->irq =irq_of_parse_and_map (bcom->ofnode, tsk->tasknum); +if (tsk->irq ==NO_IRQ ) + goto error; + +/* Init the BDs, if needed */ +if (bd_count) { + tsk->cookie =kmalloc (sizeof (void *) * bd_count,GFP_KERNEL ); +if (!tsk->cookie) + goto error; + + tsk->bd =bcom_sram_alloc (bd_count * bd_size,4 , &tsk->bd_pa); +if (!tsk->bd) + goto error; +memset (tsk->bd,0x00 , bd_count * bd_size); + + tsk->num_bd = bd_count; + tsk->bd_size = bd_size; + } + +return tsk; + +error: +if (tsk) { +if (tsk->irq !=NO_IRQ ) +irq_dispose_mapping (tsk->irq); +bcom_sram_free (tsk->bd); +kfree (tsk->cookie);
arch/powerpc/sysdev/bestcomm/bestcomm.c line 210
Quoted 10 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +10
-0+kfree (tsk); + } + + bcom->tdt[tasknum].stop =0 ; + +return NULL ; +} + +void +bcom_task_release (struct bcom_task *tsk)
bcom_task_free() to match alloc/free semantics?
Quoted 101 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +19
-0+{ +/* Stop the task */ +bcom_disable_task (tsk->tasknum); + +/* Clear TDT */ + bcom->tdt[tsk->tasknum].start =0 ; + bcom->tdt[tsk->tasknum].stop =0 ; + +/* Free everything */ +irq_dispose_mapping (tsk->irq); +bcom_sram_free (tsk->bd); +kfree (tsk->cookie); +kfree (tsk); +} + +int +bcom_load_image (int task,u32 *task_image) +{ + struct bcom_task_header *hdr = (struct bcom_task_header *)
task_image;arch/powerpc/sysdev/bestcomm/bestcomm.c new file +81
-0+struct bcom_tdt *tdt; +u32 *desc, *var, *inc; +u32 *desc_src, *var_src, *inc_src; + +/* Safety checks */ +if (hdr->magic !=BCOM_TASK_MAGIC ) { + printk(KERN_ERR DRIVER_NAME + ": Trying to load invalid microcode\n"); +return -EINVAL ; + } + +if ((task <0 ) || (task >=BCOM_MAX_TASKS )) { + printk(KERN_ERR DRIVER_NAME + ": Trying to load invalid task %d\n", task); +return -EINVAL ; + } + +/* Initial load or reload */ + tdt = &bcom->tdt[task]; + +if (tdt->start) { + desc =bcom_task_desc (task); +if (hdr->desc_size !=bcom_task_num_descs (task)) { + printk(KERN_ERR DRIVER_NAME +": Trying to reload wrong task image " +"(%d size %d/%d)!\n" , + task, + hdr->desc_size, + bcom_task_num_descs(task)); +return -EINVAL ; + } + }else { +phys_addr_t start_pa; + + desc =bcom_sram_alloc (hdr->desc_size *sizeof (u32),4 , &start_pa); +if (!desc) +return -ENOMEM ; + + tdt->start = start_pa; + tdt->stop = start_pa + ((hdr->desc_size-1 ) *sizeof (u32)); + } + + var =bcom_task_var (task); + inc =bcom_task_inc (task); + +/* Clear & copy */ +memset (var,0x00 ,BCOM_VAR_SIZE ); +memset (inc,0x00 ,BCOM_INC_SIZE ); + + desc_src = (u32 *)(hdr +1 ); + var_src = desc_src + hdr->desc_size; + inc_src = var_src + hdr->var_size; + +memcpy (desc, desc_src, hdr->desc_size *sizeof (u32)); +memcpy (var + hdr->first_var, var_src, hdr->var_size *sizeof (u32)); +memcpy (inc, inc_src, hdr->inc_size *sizeof (u32)); + +return 0 ; +} + +void +bcom_set_initiator (int task,int initiator) +{ +int i; +int num_descs; +u32 *desc; +int next_drd_has_initiator; + +bcom_set_tcr_initiator (task, initiator); + +/* Just setting tcr is apparently not enough due to some problem */ +/* with it. So we just go thru all the microcode and replace in */ +/* the DRD directly */ + + desc =bcom_task_desc (task); + next_drd_has_initiator =1 ; + num_descs =bcom_task_num_descs (task); + +for (i=0 ; i<num_descs; i++, desc++) { +if (!bcom_desc_is_drd (*desc)) +continue ;
arch/powerpc/sysdev/bestcomm/bestcomm.c line 320
Quoted 10 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +10
-0+if (next_drd_has_initiator) +if (bcom_desc_initiator (*desc) !=BCOM_INITIATOR_ALWAYS ) +bcom_set_desc_initiator (desc, initiator); + next_drd_has_initiator = !bcom_drd_is_extended (*desc); + } +} + + +/* Public API */ +
What's public about these?
Quoted 1,056 lines
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +14
-0+void +bcom_enable (struct bcom_task *tsk) +{ +bcom_enable_task (tsk->tasknum); +} + +void +bcom_disable (struct bcom_task *tsk) +{ +bcom_disable_task (tsk->tasknum); +} + + +/* ======================================================================== */ +/* Engine
init/
cleanup */
+/* ======================================================================== */arch/powerpc/sysdev/bestcomm/bestcomm.c new file +3
-0+ +/* Function Descriptor table */ +/* this will need to be updated if Freescale changes their task code FDT */
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +28
-0+static u32 fdt_ops[] = { +0xa0045670 ,/* FDT[48] - load_acc() */ +0x80045670 ,/* FDT[49] - unload_acc() */ +0x21800000 ,/* FDT[50] - and() */ +0x21e00000 ,/* FDT[51] - or() */ +0x21500000 ,/* FDT[52] - xor() */ +0x21400000 ,/* FDT[53] - andn() */ +0x21500000 ,/* FDT[54] - not() */ +0x20400000 ,/* FDT[55] - add() */ +0x20500000 ,/* FDT[56] - sub() */ +0x20800000 ,/* FDT[57] - lsh() */ +0x20a00000 ,/* FDT[58] - rsh() */ +0xc0170000 ,/* FDT[59] - crc8() */ +0xc0145670 ,/* FDT[60] - crc16() */ +0xc0345670 ,/* FDT[61] - crc32() */ +0xa0076540 ,/* FDT[62] - endian32() */ +0xa0000760 ,/* FDT[63] - endian16() */ +}; + + +static int __devinit +bcom_engine_init (void ) +{ +int task; +phys_addr_t tdt_pa, ctx_pa, var_pa, fdt_pa; +unsigned int tdt_size, ctx_size, var_size, fdt_size; + +/* Allocate & clear SRAM zones for FDT, TDTs, contexts and vars/ incs */
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +81
-0+ tdt_size =BCOM_MAX_TASKS *sizeof (struct bcom_tdt ); + ctx_size =BCOM_MAX_TASKS *BCOM_CTX_SIZE ; + var_size =BCOM_MAX_TASKS * (BCOM_VAR_SIZE +BCOM_INC_SIZE ); + fdt_size =BCOM_FDT_SIZE ; + + bcom->tdt =bcom_sram_alloc (tdt_size,sizeof (u32), &tdt_pa); + bcom->ctx =bcom_sram_alloc (ctx_size,BCOM_CTX_ALIGN , &ctx_pa); + bcom->var =bcom_sram_alloc (var_size,BCOM_VAR_ALIGN , &var_pa); + bcom->fdt =bcom_sram_alloc (fdt_size,BCOM_FDT_ALIGN , &fdt_pa); + +if (!bcom->tdt || !bcom->ctx || !bcom->var || !bcom->fdt) { +printk (KERN_ERR "DMA: SRAM alloc failed in engine init !\n" ); + +bcom_sram_free (bcom->tdt); +bcom_sram_free (bcom->ctx); +bcom_sram_free (bcom->var); +bcom_sram_free (bcom->fdt); + +return -ENOMEM ; + } + +memset (bcom->tdt,0x00 , tdt_size); +memset (bcom->ctx,0x00 , ctx_size); +memset (bcom->var,0x00 , var_size); +memset (bcom->fdt,0x00 , fdt_size); + +/* Copy the FDT for the EU#3 */ +memcpy (&bcom->fdt[48 ], fdt_ops,sizeof (fdt_ops)); + +/* Initialize Task base structure */ +for (task=0 ; task<BCOM_MAX_TASKS ; task++) + { +out_be16 (&bcom->regs->tcr[task],0 ); +out_8 (&bcom->regs->ipr[task],0 ); + + bcom->tdt[task].context = ctx_pa; + bcom->tdt[task].var = var_pa; + bcom->tdt[task].fdt = fdt_pa; + + var_pa +=BCOM_VAR_SIZE +BCOM_INC_SIZE ; + ctx_pa +=BCOM_CTX_SIZE ; + } + +out_be32 (&bcom->regs->taskBar, tdt_pa); + +/* Init 'always' initiator */ +out_8 (&bcom->regs->ipr[BCOM_INITIATOR_ALWAYS ],BCOM_IPR_ALWAYS ); + +/* Disable COMM Bus Prefetch, apparently it's not reliable yet */ +/* FIXME: This should be done on 5200 and not 5200B ... */ +out_be16 (&bcom->regs->PtdCntrl,in_be16 (&bcom->regs->PtdCntrl) |1 ); + +/* Init lock */ +spin_lock_init (&bcom->lock); + +return 0 ; +} + +static void +bcom_engine_cleanup (void ) +{ +int task; + +/* Stop all tasks */ +for (task=0 ; task<BCOM_MAX_TASKS ; task++) + { +out_be16 (&bcom->regs->tcr[task],0 ); +out_8 (&bcom->regs->ipr[task],0 ); + } + +out_be32 (&bcom->regs->taskBar,0ul ); + +/* Release the SRAM zones */ +bcom_sram_free (bcom->tdt); +bcom_sram_free (bcom->ctx); +bcom_sram_free (bcom->var); +bcom_sram_free (bcom->fdt); +} + + +/* ======================================================================== */ +/* System/Module init &
cleanup */
+/* ======================================================================== */arch/powerpc/sysdev/bestcomm/bestcomm.c new file +127
-0+ +static int __init +mpc52xx_bcom_init (void ) +{ +struct device_node *ofn_bcom, *ofn_sram; +struct resource res_bcom; + +int rv; + +/* Find the bestcomm node. If none, fails 'silently' since +* we may just be on another platform */ + ofn_bcom =of_find_compatible_node ( +NULL ,"dma-controller" ,"mpc5200-bestcomm" ); +if (!ofn_bcom) +return -ENODEV ; + +/* Inform user we're ok so far */ +printk (KERN_INFO "DMA: MPC52xx BestComm driver\n" ); + +/* Prepare SRAM */ + ofn_sram =of_find_compatible_node (NULL ,"sram" ,"mpc5200-sram" ); +if (!ofn_sram) { + printk(KERN_ERR DRIVER_NAME ": " + "No SRAM found in device tree\n"); + rv = -ENODEV ; + goto error_ofput; + } + + rv =bcom_sram_init (ofn_sram,DRIVER_NAME ); + +of_node_put (ofn_sram); + +if (rv) { + printk(KERN_ERR DRIVER_NAME ": " + "Error in SRAM init\n"); + goto error_ofput; + } + +/* Get a clean struct */ + bcom =kzalloc (sizeof (struct bcom_engine ),GFP_KERNEL ); +if (!bcom) { + printk(KERN_ERR DRIVER_NAME ": " + "Can't allocate state structure\n"); + rv = -ENOMEM ; + goto error_sramclean; + } + +/* Save the node */ + bcom->ofnode = ofn_bcom; + +/* Get, reserve & map io */ +if (of_address_to_resource (bcom->ofnode,0 , &res_bcom)) { + printk(KERN_ERR DRIVER_NAME ": " + "Can't get resource\n"); + rv = -EINVAL ; + goto error_sramclean; + } + +if (!request_mem_region (res_bcom.start,sizeof (struct mpc52xx_sdma ), +DRIVER_NAME )) { + printk(KERN_ERR DRIVER_NAME ": " + "Can't request registers region\n"); + rv = -EBUSY ; + goto error_sramclean; + } + + bcom->regs_base = res_bcom.start; + bcom->regs =ioremap (res_bcom.start,sizeof (struct mpc52xx_sdma )); +if (!bcom->regs) { + printk(KERN_ERR DRIVER_NAME ": " + "Can't map registers\n"); + rv = -ENOMEM ; + goto error_release; + } + +/* Now, do the real init */ + rv =bcom_engine_init (); +if (rv) + goto error_unmap; + +/* Done ! */ +printk (KERN_INFO "DMA: MPC52xx BestComm engine @%08lx ok !\n" , + bcom->regs_base); + +return 0 ; + +/* Error path */ +error_unmap: +iounmap (bcom->regs); +error_release: +release_mem_region (res_bcom.start,sizeof (struct mpc52xx_sdma )); +error_sramclean: +bcom_sram_cleanup (); +error_ofput: +of_node_put (bcom->ofnode); + +printk (KERN_ERR "DMA: MPC52xx BestComm init failed !\n" ); + +return rv; +} + +static void __exit +mpc52xx_bcom_exit (void ) +{ +/* Clean up the engine */ +bcom_engine_cleanup (); + +/* Cleanup SRAM */ +bcom_sram_cleanup (); + +/* Release regs */ +iounmap (bcom->regs); +release_mem_region (bcom->regs_base,sizeof (struct mpc52xx_sdma )); + +/* Release the node */ +of_node_put (bcom->ofnode); + +/* Release memory */ +kfree (bcom); +} + +#ifdef MODULE +module_init (mpc52xx_bcom_init); +module_exit (mpc52xx_bcom_exit); +#endif + +/* If we're not a module, we must make sure everything is setup before anyone */
arch/powerpc/sysdev/bestcomm/bestcomm.c new file +23
-0+/* tries to use us ... */ +#ifndef MODULE +subsys_initcall (mpc52xx_bcom_init); +#endif + +MODULE_DESCRIPTION ("Freescale MPC52xx BestComm DMA" ); +MODULE_AUTHOR ("Sylvain Munaut <[email protected]>" ); +MODULE_AUTHOR ("Andrey Volkov <[email protected]>" ); +MODULE_AUTHOR ("Dale Farnsworth <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); + + +EXPORT_SYMBOL (bcom); +EXPORT_SYMBOL (bcom_dump_status); +EXPORT_SYMBOL (bcom_dump_task); +EXPORT_SYMBOL (bcom_dump_bdring); +EXPORT_SYMBOL (bcom_task_alloc); +EXPORT_SYMBOL (bcom_task_release); +EXPORT_SYMBOL (bcom_load_image); +EXPORT_SYMBOL (bcom_set_initiator); +EXPORT_SYMBOL (bcom_enable); +EXPORT_SYMBOL (bcom_disable); +arch/powerpc/sysdev/bestcomm/bestcomm.h new file +7
-0@@ -0,0 +1,136 @@ +/* +* Public header for the MPC52xx processor BestComm driver +* +* +* Copyright (C) 2006 Sylvain Munaut <[email protected]> +* Copyright (C) 2005 Varma Electronics Oy, +* ( by Andrey Volkov <avolkov@varma- el.com> )
+ * Copyright (C) 2003-2004 MontaVista, Software, Inc.
+ * ( by Dale Farnsworth
<[email protected]> )
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */arch/powerpc/sysdev/bestcomm/bestcomm.h new file +8
-0+ +#ifndef __BESTCOMM_H__ +#define __BESTCOMM_H__ + +struct bcom_bd ;/* defined later on ... */ + + +/* ======================================================================== */ +/* Generic task
managment */
+/* ======================================================================== */arch/powerpc/sysdev/bestcomm/bestcomm.h new file +37
-0+ +struct bcom_task { +unsigned int tasknum; +unsigned int flags; +int irq; + +struct bcom_bd *bd; +phys_addr_t bd_pa; +void **cookie; +unsigned short index; +unsigned short outdex; +unsigned int num_bd; +unsigned int bd_size; + +void * priv; +}; + +#define BCOM_FLAGS_NONE 0x00000000ul +#define BCOM_FLAGS_ENABLE_TASK (1ul << 0) + + +extern void bcom_enable (struct bcom_task *tsk); +extern void bcom_disable (struct bcom_task *tsk); + +static inline int +bcom_get_task_irq (struct bcom_task *tsk) { +return tsk->irq; +} + + +/* Debug dumps */ +extern void bcom_dump_status (void ); +extern void bcom_dump_task (int task); +extern void bcom_dump_bdring (struct bcom_task *tsk); + + +/* ======================================================================== */ +/* BD based tasks
helpers */
+/* ======================================================================== */arch/powerpc/sysdev/bestcomm/bestcomm.h new file +60
-0+ +struct bcom_bd { +u32 status; +u32 data[1 ];/* variable, but at least 1 */ +}; + +#define BCOM_BD_READY 0x40000000ul + +static inline int /* user shouldn't use this ! */ +_bcom_next_index (struct bcom_task *tsk) +{ +return ((tsk->index +1 ) == tsk->num_bd) ?0 : tsk->index +1 ; +} + +static inline int /* user shouldn't use this ! */ +_bcom_next_outdex (struct bcom_task *tsk) +{ +return ((tsk->outdex +1 ) == tsk->num_bd) ?0 : tsk->outdex +1 ; +} + +static inline int +bcom_queue_empty (struct bcom_task *tsk) +{ +return tsk->index == tsk->outdex; +} + +static inline int +bcom_queue_full (struct bcom_task *tsk) +{ +return tsk->outdex ==_bcom_next_index (tsk); +} + +static inline int +bcom_buffer_done (struct bcom_task *tsk) +{ +if (bcom_queue_empty (tsk)) +return 0 ; +return !(tsk->bd[tsk->outdex].status &BCOM_BD_READY ); +} + +static inline struct bcom_bd * +bcom_prepare_next_buffer (struct bcom_task *tsk) +{ + tsk->bd[tsk->index].status =0 ;/* cleanup last status */ +return &tsk->bd[tsk->index]; +} + +static inline void +bcom_submit_next_buffer (struct bcom_task *tsk,void *cookie) +{ + tsk->cookie[tsk->index] = cookie; +mb ();/* ensure the bd is really up-to-date */ + tsk->bd[tsk->index].status |=BCOM_BD_READY ; + tsk->index =_bcom_next_index (tsk); +if (tsk->flags &BCOM_FLAGS_ENABLE_TASK ) +bcom_enable (tsk); +} + +static inline void * +bcom_retrieve_buffer(struct bcom_task *tsk, u32 *p_status, struct
bcom_bd**p_bd)arch/powerpc/sysdev/bestcomm/bestcomm.h new file +13
-0+{ +void *cookie = tsk->cookie[tsk->outdex]; +if (p_status) + *p_status = tsk->bd[tsk->outdex].status; +if (p_bd) + *p_bd = &tsk->bd[tsk->outdex]; + tsk->outdex =_bcom_next_outdex (tsk); +return cookie; +} + + +#endif /* __BESTCOMM_H__ */ +arch/powerpc/sysdev/bestcomm/bestcomm_priv.h new file +7
-0@@ -0,0 +1,325 @@ +/* +* Private header for the MPC52xx processor BestComm driver +* +* +* Copyright (C) 2006 Sylvain Munaut <[email protected]> +* Copyright (C) 2005 Varma Electronics Oy, +* ( by Andrey Volkov <avolkov@varma- el.com> )
+ * Copyright (C) 2003-2004 MontaVista, Software, Inc.
+ * ( by Dale Farnsworth
<[email protected]> )
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */arch/powerpc/sysdev/bestcomm/bestcomm_priv.h new file +13
-0+ +#ifndef __BESTCOMM_PRIV_H__ +#define __BESTCOMM_PRIV_H__ + +#include <linux/spinlock.h> +#include <asm/io.h> +#include <asm/prom.h> +#include <asm/mpc52xx.h> + +#include "sram.h" + + +/* ======================================================================== */ +/* Engine related
stuff */
+/* ======================================================================== */arch/powerpc/sysdev/bestcomm/bestcomm_priv.h new file +45
-0+ +/* Zones sizes and needed alignments */ +#define BCOM_MAX_TASKS 16 +#define BCOM_MAX_VAR 24 +#define BCOM_MAX_INC 8 +#define BCOM_MAX_FDT 64 +#define BCOM_MAX_CTX 20 +#define BCOM_CTX_SIZE (BCOM_MAX_CTX * sizeof(u32)) +#define BCOM_CTX_ALIGN 0x100 +#define BCOM_VAR_SIZE (BCOM_MAX_VAR * sizeof(u32)) +#define BCOM_INC_SIZE (BCOM_MAX_INC * sizeof(u32)) +#define BCOM_VAR_ALIGN 0x80 +#define BCOM_FDT_SIZE (BCOM_MAX_FDT * sizeof(u32)) +#define BCOM_FDT_ALIGN 0x100 + +/* Task Descriptor Table Entry */ +struct bcom_tdt { +u32 start; +u32 stop; +u32 var; +u32 fdt; +u32 exec_status;/* used internally by BestComm engine */ +u32 mvtp;/* used internally by BestComm engine */ +u32 context; +u32 litbase; +}; + +/* This holds all info needed globaly to handle the engine */ +struct bcom_engine { +struct device_node *ofnode; +struct mpc52xx_sdma __iomem *regs; +phys_addr_t regs_base; + +struct bcom_tdt *tdt; +u32 *ctx; +u32 *var; +u32 *fdt; + +spinlock_t lock; +}; + +extern struct bcom_engine *bcom; + + +/* ======================================================================== */ +/* Tasks related
stuff */
+/* ======================================================================== */arch/powerpc/sysdev/bestcomm/bestcomm_priv.h new file +22
-0+ +/* Tasks image header */ +#define BCOM_TASK_MAGIC 0x4243544B/* 'BCTK' */ + +struct bcom_task_header { +u32 magic; +u8 desc_size;/* the size fields */ +u8 var_size;/* are given in number */ +u8 inc_size;/* of 32-bits words */ +u8 first_var; +u8 reserved[8 ]; +}; + +/* Descriptors stucture & co */ +#define BCOM_DESC_NOP 0x000001f8 +#define BCOM_LCD_MASK 0x80000000 +#define BCOM_DRD_EXTENDED 0x40000000 +#define BCOM_DRD_INITIATOR_SHIFT 21 + +/* Tasks pragma */ +#define BCOM_PRAGMA_BIT_RSV 7/* reserved pragma bit */ +#define BCOM_PRAGMA_BIT_PRECISE_INC 6/* increment 0=when possible, */
arch/powerpc/sysdev/bestcomm/bestcomm_priv.h new file +11
-0+/* 1=iter end */ +#define BCOM_PRAGMA_BIT_RST_ERROR_NO 5/* don't reset errors on */ +/* task enable */ +#define BCOM_PRAGMA_BIT_PACK 4/* pack data enable */ +#define BCOM_PRAGMA_BIT_INTEGER 3/* data alignment */ +/* 0=frac(msb), 1=int(lsb) */ +#define BCOM_PRAGMA_BIT_SPECREAD 2/* XLB speculative read */ +#define BCOM_PRAGMA_BIT_CW 1/* write line buffer enable */ +#define BCOM_PRAGMA_BIT_RL 0/* read line buffer enable */ + +/* Looks like XLB speculative read generates XLB errors when a buffer
arch/powerpc/sysdev/bestcomm/bestcomm_priv.h new file +2
-0+* is at the end of the physical memory. i.e. when accessing the +* lasts words, the engine tries to prefetch the next but there is no
arch/powerpc/sysdev/bestcomm/bestcomm_priv.h new file +111
-0+* next ... +*/ +#define BCOM_STD_PRAGMA ((0 << BCOM_PRAGMA_BIT_RSV) | \ + (0 << BCOM_PRAGMA_BIT_PRECISE_INC) | \ + (0 << BCOM_PRAGMA_BIT_RST_ERROR_NO) | \ + (0 << BCOM_PRAGMA_BIT_PACK) | \ + (0 << BCOM_PRAGMA_BIT_INTEGER) | \ + (0 << BCOM_PRAGMA_BIT_SPECREAD) | \ + (1 << BCOM_PRAGMA_BIT_CW) | \ + (1 << BCOM_PRAGMA_BIT_RL)) + +#define BCOM_PCI_PRAGMA ((0 << BCOM_PRAGMA_BIT_RSV) | \ + (0 << BCOM_PRAGMA_BIT_PRECISE_INC) | \ + (0 << BCOM_PRAGMA_BIT_RST_ERROR_NO) | \ + (0 << BCOM_PRAGMA_BIT_PACK) | \ + (1 << BCOM_PRAGMA_BIT_INTEGER) | \ + (0 << BCOM_PRAGMA_BIT_SPECREAD) | \ + (1 << BCOM_PRAGMA_BIT_CW) | \ + (1 << BCOM_PRAGMA_BIT_RL)) + +#define BCOM_ATA_PRAGMA BCOM_STD_PRAGMA +#define BCOM_CRC16_DP_0_PRAGMA BCOM_STD_PRAGMA +#define BCOM_CRC16_DP_1_PRAGMA BCOM_STD_PRAGMA +#define BCOM_FEC_RX_BD_PRAGMA BCOM_STD_PRAGMA +#define BCOM_FEC_TX_BD_PRAGMA BCOM_STD_PRAGMA +#define BCOM_GEN_DP_0_PRAGMA BCOM_STD_PRAGMA +#define BCOM_GEN_DP_1_PRAGMA BCOM_STD_PRAGMA +#define BCOM_GEN_DP_2_PRAGMA BCOM_STD_PRAGMA +#define BCOM_GEN_DP_3_PRAGMA BCOM_STD_PRAGMA +#define BCOM_GEN_DP_BD_0_PRAGMA BCOM_STD_PRAGMA +#define BCOM_GEN_DP_BD_1_PRAGMA BCOM_STD_PRAGMA +#define BCOM_GEN_RX_BD_PRAGMA BCOM_STD_PRAGMA +#define BCOM_GEN_TX_BD_PRAGMA BCOM_STD_PRAGMA +#define BCOM_GEN_LPC_PRAGMA BCOM_STD_PRAGMA +#define BCOM_PCI_RX_PRAGMA BCOM_PCI_PRAGMA +#define BCOM_PCI_TX_PRAGMA BCOM_PCI_PRAGMA + +/* Initiators number */ +#define BCOM_INITIATOR_ALWAYS 0 +#define BCOM_INITIATOR_SCTMR_0 1 +#define BCOM_INITIATOR_SCTMR_1 2 +#define BCOM_INITIATOR_FEC_RX 3 +#define BCOM_INITIATOR_FEC_TX 4 +#define BCOM_INITIATOR_ATA_RX 5 +#define BCOM_INITIATOR_ATA_TX 6 +#define BCOM_INITIATOR_SCPCI_RX 7 +#define BCOM_INITIATOR_SCPCI_TX 8 +#define BCOM_INITIATOR_PSC3_RX 9 +#define BCOM_INITIATOR_PSC3_TX 10 +#define BCOM_INITIATOR_PSC2_RX 11 +#define BCOM_INITIATOR_PSC2_TX 12 +#define BCOM_INITIATOR_PSC1_RX 13 +#define BCOM_INITIATOR_PSC1_TX 14 +#define BCOM_INITIATOR_SCTMR_2 15 +#define BCOM_INITIATOR_SCLPC 16 +#define BCOM_INITIATOR_PSC5_RX 17 +#define BCOM_INITIATOR_PSC5_TX 18 +#define BCOM_INITIATOR_PSC4_RX 19 +#define BCOM_INITIATOR_PSC4_TX 20 +#define BCOM_INITIATOR_I2C2_RX 21 +#define BCOM_INITIATOR_I2C2_TX 22 +#define BCOM_INITIATOR_I2C1_RX 23 +#define BCOM_INITIATOR_I2C1_TX 24 +#define BCOM_INITIATOR_PSC6_RX 25 +#define BCOM_INITIATOR_PSC6_TX 26 +#define BCOM_INITIATOR_IRDA_RX 25 +#define BCOM_INITIATOR_IRDA_TX 26 +#define BCOM_INITIATOR_SCTMR_3 27 +#define BCOM_INITIATOR_SCTMR_4 28 +#define BCOM_INITIATOR_SCTMR_5 29 +#define BCOM_INITIATOR_SCTMR_6 30 +#define BCOM_INITIATOR_SCTMR_7 31 + +/* Initiators priorities */ +#define BCOM_IPR_ALWAYS 7 +#define BCOM_IPR_SCTMR_0 2 +#define BCOM_IPR_SCTMR_1 2 +#define BCOM_IPR_FEC_RX 6 +#define BCOM_IPR_FEC_TX 5 +#define BCOM_IPR_ATA_RX 4 +#define BCOM_IPR_ATA_TX 3 +#define BCOM_IPR_SCPCI_RX 2 +#define BCOM_IPR_SCPCI_TX 2 +#define BCOM_IPR_PSC3_RX 2 +#define BCOM_IPR_PSC3_TX 2 +#define BCOM_IPR_PSC2_RX 2 +#define BCOM_IPR_PSC2_TX 2 +#define BCOM_IPR_PSC1_RX 2 +#define BCOM_IPR_PSC1_TX 2 +#define BCOM_IPR_SCTMR_2 2 +#define BCOM_IPR_SCLPC 2 +#define BCOM_IPR_PSC5_RX 2 +#define BCOM_IPR_PSC5_TX 2 +#define BCOM_IPR_PSC4_RX 2 +#define BCOM_IPR_PSC4_TX 2 +#define BCOM_IPR_I2C2_RX 2 +#define BCOM_IPR_I2C2_TX 2 +#define BCOM_IPR_I2C1_RX 2 +#define BCOM_IPR_I2C1_TX 2 +#define BCOM_IPR_PSC6_RX 2 +#define BCOM_IPR_PSC6_TX 2 +#define BCOM_IPR_IRDA_RX 2 +#define BCOM_IPR_IRDA_TX 2 +#define BCOM_IPR_SCTMR_3 2 +#define BCOM_IPR_SCTMR_4 2 +#define BCOM_IPR_SCTMR_5 2 +#define BCOM_IPR_SCTMR_6 2 +#define BCOM_IPR_SCTMR_7 2 + + +/* ======================================================================== */ +/*
API
*/
+/* ======================================================================== */arch/powerpc/sysdev/bestcomm/bestcomm_priv.h new file +2
-0+ +extern struct bcom_task *bcom_task_alloc(int bd_count, int
bd_size, intpriv_size);arch/powerpc/sysdev/bestcomm/bestcomm_priv.h new file +100
-0+extern void bcom_task_release (struct bcom_task *tsk); + +extern int bcom_load_image (int task,u32 *task_image); +extern void bcom_set_initiator (int task,int initiator); + + +#define TASK_ENABLE 0x8000 + +static inline void +bcom_enable_task (int task) +{ +u16 reg; + reg =in_be16 (&bcom->regs->tcr[task]); +out_be16 (&bcom->regs->tcr[task], reg |TASK_ENABLE ); +} + +static inline void +bcom_disable_task (int task) +{ +u16 reg =in_be16 (&bcom->regs->tcr[task]); +out_be16 (&bcom->regs->tcr[task], reg & ~TASK_ENABLE ); +} + + +static inline u32 * +bcom_task_desc (int task) +{ +return bcom_sram_pa2va (bcom->tdt[task].start); +} + +static inline int +bcom_task_num_descs (int task) +{ +return (bcom->tdt[task].stop - bcom->tdt[task].start)/sizeof (u32 ) +1 ; +} + +static inline u32 * +bcom_task_var (int task) +{ +return bcom_sram_pa2va (bcom->tdt[task].var); +} + +static inline u32 * +bcom_task_inc (int task) +{ +return &bcom_task_var (task)[BCOM_MAX_VAR ]; +} + + +static inline int +bcom_drd_is_extended (u32 desc) +{ +return (desc) &BCOM_DRD_EXTENDED ; +} + +static inline int +bcom_desc_is_drd (u32 desc) +{ +return !(desc &BCOM_LCD_MASK ) && desc !=BCOM_DESC_NOP ; +} + +static inline int +bcom_desc_initiator (u32 desc) +{ +return (desc >>BCOM_DRD_INITIATOR_SHIFT ) &0x1f ; +} + +static inline void +bcom_set_desc_initiator (u32 *desc,int initiator) +{ + *desc = (*desc & ~(0x1f <<BCOM_DRD_INITIATOR_SHIFT )) | + ((initiator &0x1f ) <<BCOM_DRD_INITIATOR_SHIFT ); +} + + +static inline void +bcom_set_task_pragma (int task,int pragma) +{ +u32 *fdt = &bcom->tdt[task].fdt; + *fdt = (*fdt & ~0xff ) | pragma; +} + +static inline void +bcom_set_task_auto_start (int task,int next_task) +{ +u16 __iomem *tcr = &bcom->regs->tcr[task]; +out_be16 (tcr, (in_be16 (tcr) & ~0xff ) |0x00c0 | next_task); +} + +static inline void +bcom_set_tcr_initiator (int task,int initiator) +{ +u16 __iomem *tcr = &bcom->regs->tcr[task]; +out_be16 (tcr, (in_be16 (tcr) & ~0x1f00 ) | ((initiator &0x1f ) <<8 )); +} + + +#endif /* __BESTCOMM_PRIV_H__ */ +arch/powerpc/sysdev/bestcomm/sram.c new file +9
-0@@ -0,0 +1,180 @@ +/* +* Simple memory allocator for on-board SRAM +* +* +* Maintainer : Sylvain Munaut <[email protected]> +* +* Copyright (C) 2005 Sylvain Munaut <[email protected]> +* +* This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */arch/powerpc/sysdev/bestcomm/sram.c new file +20
-0+ +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/string.h> +#include <linux/ioport.h> + +#include <asm/io.h> +#include <asm/mmu.h> +#include <asm/prom.h> + +#include "sram.h" + + +/* Struct keeping our 'state' */ +struct bcom_sram *bcom_sram =NULL ; + + +/* ======================================================================== */ +/* Public
API */
+/* ======================================================================== */ +/* DO NOT USE in interrupts, if needed in irq handler, we should use thearch/powerpc/sysdev/bestcomm/sram.c new file +39
-0+_irqsave version of the spin_locks */ + +int bcom_sram_init(struct device_node *sram_node, char *owner) +{ + int rv; + const u32 *regaddr_p; + u64 regaddr64, size64; + unsigned int psize; + + /* Create our state struct */ + if (bcom_sram) { + printk(KERN_ERR "%s: bcom_sram_init: " + "Already initialiwed !\n", owner); + return -EBUSY; + } + + bcom_sram = kmalloc(sizeof(struct bcom_sram), GFP_KERNEL); + if (!bcom_sram) { + printk(KERN_ERR "%s: bcom_sram_init: " + "Couldn't allocate internal state !\n", owner); + return -ENOMEM; + } + + /* Get address and size of the sram */ + regaddr_p = of_get_address(sram_node, 0, &size64, NULL); + if (!regaddr_p) { + printk(KERN_ERR "%s: bcom_sram_init: " + "Invalid device node !\n", owner); + rv = -EINVAL; + goto error_free; + } + + regaddr64 = of_translate_address(sram_node, regaddr_p); + + bcom_sram->base_phys = (phys_addr_t) regaddr64; + bcom_sram->size = (unsigned int) size64; + + /* Request region */ + if (!request_mem_region(bcom_sram->base_phys, bcom_sram->size,owner)) {
arch/powerpc/sysdev/bestcomm/sram.c new file +9
-0+printk (KERN_ERR "%s: bcom_sram_init: " +"Couln't request region !\n" , owner); + rv = -EBUSY ; + goto error_free; + } + +/* Map SRAM */ +/* sram is not really __iomem */ + bcom_sram->base_virt = (void*) ioremap(bcom_sram->base_phys,
bcom_sram->size);arch/powerpc/sysdev/bestcomm/sram.c new file +29
-0+ +if (!bcom_sram->base_virt) { +printk (KERN_ERR "%s: bcom_sram_init: " +"Map error SRAM zone 0x%08lx (0x%0x)!\n" , + owner, bcom_sram->base_phys, bcom_sram->size ); + rv = -ENOMEM ; + goto error_release; + } + +/* Create an rheap (defaults to 32 bits word alignment) */ + bcom_sram->rh =rh_create (4 ); + +/* Attach the free zones */ +#if 0 +/* Currently disabled ... for future use only */ + reg_addr_p =of_get_property (sram_node,"available" , &psize); +#else + regaddr_p =NULL ; + psize =0 ; +#endif + +if (!regaddr_p || !psize) { +/* Attach the whole zone */ +rh_attach_region (bcom_sram->rh,0 , bcom_sram->size); + }else { +/* Attach each zone independently */ +while (psize >=2 *sizeof (u32)) { +phys_addr_t zbase =of_translate_address (sram_node, regaddr_p); + rh_attach_region(bcom_sram->rh, zbase - bcom_sram->base_phys,regaddr_p[1]);
arch/powerpc/sysdev/bestcomm/sram.c new file +68
-0+ regaddr_p +=2 ; + psize -=2 *sizeof (u32); + } + } + +/* Init our spinlock */ +spin_lock_init (&bcom_sram->lock); + +return 0 ; + +error_release: +release_mem_region (bcom_sram->base_phys, bcom_sram->size); +error_free: +kfree (bcom_sram); + bcom_sram =NULL ; + +return rv; +} + +void bcom_sram_cleanup (void ) +{ +/* Free resources */ +if (bcom_sram) { +rh_destroy (bcom_sram->rh); +iounmap ((void __iomem *)bcom_sram->base_virt); +release_mem_region (bcom_sram->base_phys, bcom_sram->size); +kfree (bcom_sram); + bcom_sram =NULL ; + } +} + +void *bcom_sram_alloc (int size,int align,phys_addr_t *phys) +{ +unsigned long offset; + +spin_lock (&bcom_sram->lock); + offset =rh_alloc_align (bcom_sram->rh, size, align,NULL ); +spin_unlock (&bcom_sram->lock); + +if (IS_ERR_VALUE (offset)) +return NULL ; + + *phys = bcom_sram->base_phys + offset; +return bcom_sram->base_virt + offset; +} + +void bcom_sram_free (void *ptr) +{ +unsigned long offset; + +if (!ptr) +return ; + + offset = ptr - bcom_sram->base_virt; + +spin_lock (&bcom_sram->lock); +rh_free (bcom_sram->rh, offset); +spin_unlock (&bcom_sram->lock); +} + + +EXPORT_SYMBOL (bcom_sram); + +EXPORT_SYMBOL (bcom_sram_init); +EXPORT_SYMBOL (bcom_sram_cleanup); +EXPORT_SYMBOL (bcom_sram_alloc); +EXPORT_SYMBOL (bcom_sram_free); +arch/powerpc/sysdev/bestcomm/sram.h new file +7
-0@@ -0,0 +1,54 @@ +/* +* Handling of a sram zone for bestcomm +* +* +* Copyright (C) 2007 Sylvain Munaut <[email protected]> +* +* This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */arch/powerpc/sysdev/bestcomm/sram.h new file +26
-0+ +#ifndef __BESTCOMM_SRAM_H__ +#define __BESTCOMM_SRAM_H__ + +#include <asm/rheap.h> +#include <asm/mmu.h> +#include <linux/spinlock.h> + + +/* Structure used internally */ +/* The internals are here for the inline functions +* sake, certainly not for the user to mess with ! +*/ +struct bcom_sram { +phys_addr_t base_phys; +void *base_virt; +unsigned int size; +rh_info_t *rh; +spinlock_t lock; +}; + +extern struct bcom_sram *bcom_sram; + + +/* Public API */ +extern int bcom_sram_init(struct device_node *sram_node, char*owner);
arch/powerpc/sysdev/bestcomm/sram.h new file +18
-0+extern void bcom_sram_cleanup (void ); + +extern void *bcom_sram_alloc (int size,int align,phys_addr_t *phys); +extern void bcom_sram_free (void *ptr); + +static inline phys_addr_t bcom_sram_va2pa (void *va) { +return bcom_sram->base_phys + + (unsigned long )(va - bcom_sram->base_virt); +} + +static inline void *bcom_sram_pa2va (phys_addr_t pa) { +return bcom_sram->base_virt + + (unsigned long )(pa - bcom_sram->base_phys); +} + + +#endif /* __BESTCOMM_SRAM_H__ */ +Signature · 5 lines
1.5.1.2 _______________________________________________ Linuxppc-dev mailing list [email protected] https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [PATCH 4/9] powerpc: BestComm core support for Freescale MPC5200
Quoted 8 lines · Kumar Gala
Quoted 5 lines · Sylvain Munaut
This patch adds support for the core of the BestComm API for the Freescale MPC5200(b). The BestComm engine is a microcode-controlled / tasks-based DMA used by several of the onchip devices.
Quoted 8 lines
Quoted 6 lines
Setting up the tasks / memory allocation and all common low level functions are handled by this patch. The specifics details of each tasks and their microcode are split-out in separate patches.
This is not the official API, but a much cleaner one.
Can you give more detail about how the API works.
Yes, I'll try to write something that gives a little explanation for Documentation/
In the mean time, here's a small informative text that describe the API usage from a driver writer perspective :
You need to allocate yourself a task, depending on what driver you're writing, that might be a generic one or one dedicated to that device (depends on the peripheral). For example FEC needs one TX and one RX task, both specialized.
Each 'type' of task you can create has a specific function to create it. For example, to create a new instance of the FEC rx task, you call bcom_fec_rx_init.
It returns a (struct bcom_task*) that's gonna be your link to bestcomm for all further calls.
Each task "type" needs a different init function because depending on the microcode, the way to initialize it is slightly different ...
Most task are buffer descriptor based (well ... currently, they all are but that's not an obligation), and the bestcomm API handle details of the BD ring commonly. It assumes each buffer descriptor is formed by a status word and a certain number of data pointers (1,2,..n).
The signification of each of theses data pointers and of the status depends on the type of task. There is however a convention in all tasks that the upper 4 bits of the status are reserved for "Ready" flags and that the lsbs are for the length (how much lsb depends of task ...)
When you need to submit a new buffer for sending, you just call bcom_prepare_next_buffer(...) that returns you a pointer to a (struct bcom_bd *) to fill up with the info you want (most often just the lenght and data pointers ...). When filled up, you just "push" the BD calling bcom_submit_next_buffer(...). Each time a BD is completed, bestcomm generates an interrupt and you just have to call bcom_retrieve_buffer(...) to reclaim the BD that was sent (along with the info needed to identify which one it is).
For receive task, it's more or less the same except you submit empty buffer that bestcomm will fill up. And the status word in the bd you recover by calling _retrieve is gonna give you how many bytes were put into the buffer.
Quoted 17 lines
Quoted 8 lines
arch/powerpc/sysdev/bestcomm/Makefile new file +0
-0arch/powerpc/sysdev/bestcomm/Makefile line 7
Quoted 7 lines
arch/powerpc/sysdev/bestcomm/Makefile new file +7
-0@@ -0,0 +1,8 @@ +# +# Makefile for BestComm & co +# + +bestcomm-core-objs := bestcomm.o sram.o + +obj-$(CONFIG_PPC_BESTCOMM) += bestcomm-core.oAny reason why sram isn't on the ojb-$(CONFIG_PPC_BESTCOMM) line?
Huh, I want the module to be named bestcomm-core when built as modules, is it possible to do it in another way ?
I'm not an expert as kbuild so if there is a better way ...
Quoted 7 lines
Quoted 5 lines
arch/powerpc/sysdev/bestcomm/Makefile new file +3
-0+/* Debug Dump */ + +#define BCOM_DPRINTK(a,b...) printk(KERN_DEBUG DRIVER_NAME ": " a,## b)
We have
dev_dbganddev_printkcan we not use them?
I don't use dev_dbg because I want the stuff printed even if DEBUG was not defined when
compiling bestcomm-core.
Those are debug functions that a developer can call, from the driver, to see what state bestcomm is
in. So when he calls them, the user expects them to print stuff, regardless is DEBUG was defined
or not when compiling bestcomm-core ...
Same thing for pr_debug.
And dev_printk forces me to repeat "dev_printk(dev, KERN_DEBUG, " on each line which makes
them very long ...
I could define BCOM_DPRINTK(a,b,...) as dev_printk(dev, KERN_DEBUG, ...) if you think it's better.
Quoted 4 lines
Would all
bcom_dump_status(),bcom_dump_task(),bcom_dump_bdringbe better using debugfs? At minimum there should be aKconfigoption to enable bestcomm debug that enables this code.
Theses are _never_ called ...
They are just there because when you work on a driver and something goes wrong, it's useful to print debug info to see exactly what happened at that exact moment.
So for example when working on the sound driver, some times I got an interrupt but no buffer was finished, printing the bestcomm status at that exact moment in the ISR when detecting that condition allowed me to figure out what was going on. On the final submitted driver the call will be removed ...
Quoted 4 lines
arch/powerpc/sysdev/bestcomm/Makefile
Quoted 2 lines
arch/powerpc/sysdev/bestcomm/Makefile new file +2
-0+/* Private API */ +What's private about it?
Driver code should not use it directly.
Only task support code should use it.
(basically anything outside sysdev/bestcomm/* should not include bestcomm_priv.h)
Quoted 2 lines
It would probably be good for the API functions to have DocBook style comments. See something like
drivers/rapidio/rio.cfor an example.
Yes that would be nice ... just need to write it ;)
Quoted 4 lines
arch/powerpc/sysdev/bestcomm/Makefile
Quoted 3 lines
arch/powerpc/sysdev/bestcomm/Makefile new file +2
-0+void +bcom_task_release(struct bcom_task *tsk)
bcom_task_free()to match alloc/free semantics?
Ok, I'll change that.
Quoted 5 lines
arch/powerpc/sysdev/bestcomm/Makefile
Quoted 4 lines
arch/powerpc/sysdev/bestcomm/Makefile new file +4
-0+ + +/* Public API */ +What's public about these?
Driver can use those ;)
Thanks for the comments.
Sylvain