Aspeed: Add SCU interrupt controller and XDMA engine drivers
Subsystems (4)
Eddie James
maintainercover Aspeed: Add SCU interrupt controller and XDMA engine drivers
This series first adds a driver to control the interrupt controller provided by the System Control Unit (SCU) on the AST2500 and AST2600 SOCs. The interrupts made available are necessary for the control of the XDMA engine embedded in the same Aspeed SOCs.
This series then adds a driver to control the XDMA engine. This driver was previously sent to the list without support for the AST2600, and has been refactored significantly to enable that support. The XDMA engine performs automatic DMA operations between the Aspeed SOC (acting as a BMC) and a host processor.
Eddie James (12):
dt-bindings: interrupt-controller: Add Aspeed SCU interrupt controller
irqchip: Add Aspeed SCU interrupt controller
ARM: dts: aspeed: ast2500: Add SCU interrupt controller
ARM: dts: aspeed: ast2600: Add SCU interrupt controllers
dt-bindings: soc: Add Aspeed XDMA Engine
drivers/soc: Add Aspeed XDMA Engine Driver
drivers/soc: xdma: Add user interface
ARM: dts: aspeed: ast2500: Add XDMA Engine
ARM: dts: aspeed: ast2600: Add XDMA Engine
ARM: dts: aspeed: witherspoon: Enable XDMA Engine
ARM: dts: aspeed: rainier: Enable XDMA engine
ARM: dts: aspeed: tacoma: Enable XDMA engine
.../interrupt-controller/aspeed,ast2xxx-scu-ic.txt | 26 + .../devicetree/bindings/soc/aspeed/xdma.txt | 24 + MAINTAINERS | 16 + arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts | 4 + arch/arm/boot/dts/aspeed-bmc-opp-tacoma.dts | 4 + arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 4 + arch/arm/boot/dts/aspeed-g5.dtsi | 21 +- arch/arm/boot/dts/aspeed-g6.dtsi | 29 + drivers/irqchip/Makefile | 2 +- drivers/irqchip/irq-aspeed-scu-ic.c | 233 +++++ drivers/soc/aspeed/Kconfig | 8 + drivers/soc/aspeed/Makefile | 1 + drivers/soc/aspeed/aspeed-xdma.c | 1079 ++++++++++++++++++++ .../interrupt-controller/aspeed-scu-ic.h | 23 + include/uapi/linux/aspeed-xdma.h | 49 + 15 files changed, 1521 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/aspeed,ast2xxx-scu-ic.txt create mode 100644 Documentation/devicetree/bindings/soc/aspeed/xdma.txt create mode 100644 drivers/irqchip/irq-aspeed-scu-ic.c create mode 100644 drivers/soc/aspeed/aspeed-xdma.c create mode 100644 include/dt-bindings/interrupt-controller/aspeed-scu-ic.h create mode 100644 include/uapi/linux/aspeed-xdma.h
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 1/12 dt-bindings: interrupt-controller: Add Aspeed SCU interrupt controller
Document the Aspeed SCU interrupt controller and add an include file for the interrupts it provides.
--- .../interrupt-controller/aspeed,ast2xxx-scu-ic.txt | 26 ++++++++++++++++++++++ MAINTAINERS | 7 ++++++ .../interrupt-controller/aspeed-scu-ic.h | 23 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/aspeed,ast2xxx-scu-ic.txt create mode 100644 include/dt-bindings/interrupt-controller/aspeed-scu-ic.h
Documentation/devicetree/bindings/interrupt-controller/aspeed,ast2xxx-scu-ic.txt new file +26 -0
@@ -0,0 +1,26 @@ +Aspeed AST25XX and AST26XX SCU Interrupt Controller + +Required Properties: + - #interrupt-cells : must be 1 + - compatible : must be "aspeed,ast2500-scu-ic", + "aspeed,ast2600-scu-ic0" or + "aspeed,ast2600-scu-ic1" + - reg : address and size of the SCU register + associated with the controller + - interrupts : interrupt from the parent controller + - interrupt-controller : indicates that the controlle receives and + fires new interrupts for child busses + +Example: + + syscon at 1e6e2000 { + ranges = <0 0x1e6e2000 0x1a8>; + + scu_ic: interrupt-controller at 18 { + #interrupt-cells = <1>; + compatible = "aspeed,ast2500-scu-ic"; + reg = <0x18 0x04>; + interrupts = <21>; + interrupt-controller; + }; + };
MAINTAINERS +7 -0
@@ -2675,6 +2675,13 @@ S: Maintained F: drivers/pinctrl/aspeed/ F: Documentation/devicetree/bindings/pinctrl/aspeed,* +ASPEED SCU INTERRUPT CONTROLLER DRIVER +M: Eddie James <[email protected]> +L: linux-aspeed at lists.ozlabs.org (moderated for non-subscribers) +S: Maintained +F: Documentation/devicetree/bindings/interrupt-controller/aspeed,ast2xxx-scu-ic.txt +F: include/dt-bindings/interrupt-controller/aspeed-scu-ic.h + ASPEED VIDEO ENGINE DRIVER M: Eddie James <[email protected]> L: linux-media at vger.kernel.org
include/dt-bindings/interrupt-controller/aspeed-scu-ic.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _DT_BINDINGS_INTERRUPT_CONTROLLER_ASPEED_SCU_IC_H_ +#define _DT_BINDINGS_INTERRUPT_CONTROLLER_ASPEED_SCU_IC_H_ + +#define ASPEED_SCU_IC_VGA_CURSOR_CHANGE 0 +#define ASPEED_SCU_IC_VGA_SCRATCH_REG_CHANGE 1 + +#define ASPEED_AST2500_SCU_IC_PCIE_RESET_LO_TO_HI 2 +#define ASPEED_AST2500_SCU_IC_PCIE_RESET_HI_TO_LO 3 +#define ASPEED_AST2500_SCU_IC_LPC_RESET_LO_TO_HI 4 +#define ASPEED_AST2500_SCU_IC_LPC_RESET_HI_TO_LO 5 +#define ASPEED_AST2500_SCU_IC_ISSUE_MSI 6 + +#define ASPEED_AST2600_SCU_IC0_PCIE_PERST_LO_TO_HI 2 +#define ASPEED_AST2600_SCU_IC0_PCIE_PERST_HI_TO_LO 3 +#define ASPEED_AST2600_SCU_IC0_PCIE_RCRST_LO_TO_HI 4 +#define ASPEED_AST2600_SCU_IC0_PCIE_RCRST_HI_TO_LO 5 + +#define ASPEED_AST2600_SCU_IC1_LPC_RESET_LO_TO_HI 0 +#define ASPEED_AST2600_SCU_IC1_LPC_RESET_HI_TO_LO 1 + +#endif /* _DT_BINDINGS_INTERRUPT_CONTROLLER_ASPEED_SCU_IC_H_ */
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 2/12 irqchip: Add Aspeed SCU interrupt controller
In reply to Eddie JamesThe Aspeed SOCs provide some interrupts through the System Control Unit registers. Add an interrupt controller that provides these interrupts to the system.
--- MAINTAINERS | 1 + drivers/irqchip/Makefile | 2 +- drivers/irqchip/irq-aspeed-scu-ic.c | 233 ++++++++++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 drivers/irqchip/irq-aspeed-scu-ic.c
MAINTAINERS +1 -0
@@ -2680,6 +2680,7 @@ M: Eddie James <[email protected]> L: linux-aspeed at lists.ozlabs.org (moderated for non-subscribers) S: Maintained F: Documentation/devicetree/bindings/interrupt-controller/aspeed,ast2xxx-scu-ic.txt +F: drivers/irqchip/irq-aspeed-scu-ic.c F: include/dt-bindings/interrupt-controller/aspeed-scu-ic.h ASPEED VIDEO ENGINE DRIVER
drivers/irqchip/Makefile +1 -1
@@ -86,7 +86,7 @@ obj-$(CONFIG_MVEBU_PIC) += irq-mvebu-pic.o obj-$(CONFIG_MVEBU_SEI) += irq-mvebu-sei.o obj-$(CONFIG_LS_SCFG_MSI) += irq-ls-scfg-msi.o obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o -obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o irq-aspeed-i2c-ic.o +obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o irq-aspeed-i2c-ic.o irq-aspeed-scu-ic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o obj-$(CONFIG_IRQ_UNIPHIER_AIDET) += irq-uniphier-aidet.o
drivers/irqchip/irq-aspeed-scu-ic.c new file +233 -0
233 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 3/12 ARM: dts: aspeed: ast2500: Add SCU interrupt controller
In reply to Eddie JamesAdd a node for the interrupt controller provided by the SCU.
--- arch/arm/boot/dts/aspeed-g5.dtsi | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/arm/boot/dts/aspeed-g5.dtsi +10 -1
@@ -216,8 +216,9 @@ syscon: syscon at 1e6e2000 { compatible = "aspeed,ast2500-scu", "syscon", "simple-mfd"; reg = <0x1e6e2000 0x1a8>; + ranges = <0 0x1e6e2000 0x1a8>; #address-cells = <1>; - #size-cells = <0>; + #size-cells = <1>; #clock-cells = <1>; #reset-cells = <1>;
@@ -231,6 +232,14 @@ compatible = "aspeed,ast2500-p2a-ctrl"; status = "disabled"; }; + + scu_ic: interrupt-controller at 18 { + #interrupt-cells = <1>; + compatible = "aspeed,ast2500-scu-ic"; + reg = <0x18 0x04>; + interrupts = <21>; + interrupt-controller; + }; }; rng: hwrng at 1e6e2078 {
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 4/12 ARM: dts: aspeed: ast2600: Add SCU interrupt controllers
In reply to Eddie JamesAdd nodes for the interrupt controllers provided by the SCU.
--- arch/arm/boot/dts/aspeed-g6.dtsi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
arch/arm/boot/dts/aspeed-g6.dtsi +18 -0
@@ -288,6 +288,24 @@ compatible = "aspeed,ast2600-smpmem"; reg = <0x180 0x40>; }; + + scu_ic0: interrupt-controller at 0 { + #interrupt-cells = <1>; + compatible = "aspeed,ast2600-scu-ic0"; + reg = <0x560 0x4>; + interrupt-parent = <&gic>; + interrupts = <GIC_SPI 12 IRQ_TYPE_LEVEL_HIGH>; + interrupt-controller; + }; + + scu_ic1: interrupt-controller at 1 { + #interrupt-cells = <1>; + compatible = "aspeed,ast2600-scu-ic1"; + reg = <0x570 0x4>; + interrupt-parent = <&gic>; + interrupts = <GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>; + interrupt-controller; + }; }; rng: hwrng at 1e6e2524 {
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 5/12 dt-bindings: soc: Add Aspeed XDMA Engine
In reply to Eddie JamesDocument the bindings for the Aspeed AST25XX and AST26XX XDMA engine.
--- .../devicetree/bindings/soc/aspeed/xdma.txt | 24 ++++++++++++++++++++++ MAINTAINERS | 6 ++++++ 2 files changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/aspeed/xdma.txt
Documentation/devicetree/bindings/soc/aspeed/xdma.txt new file +24 -0
@@ -0,0 +1,24 @@ +Aspeed AST25XX and AST26XX XDMA Engine + +The XDMA Engine embedded in the AST2500 and AST2600 SOCs can perform automatic +DMA operations over PCI between the SOC (acting as a BMC) and a host processor. + +Required properties: + - compatible : must be "aspeed,ast2500-xdma" or + "aspeed,ast2600-xdma" + - reg : contains the address and size of the memory region + associated with the XDMA engine registers + - resets : reset specifier for the syscon reset associated with + the XDMA engine + - interrupts-extended : two interrupt nodes; the first specifies the global + interrupt for the XDMA engine and the second + specifies the PCI-E reset or PERST interrupt. + +Example: + + xdma at 1e6e7000 { + compatible = "aspeed,ast2500-xdma"; + reg = <0x1e6e7000 0x100>; + resets = <&syscon ASPEED_RESET_XDMA>; + interrupts-extended = <&vic 6>, <&scu_ic ASPEED_AST2500_SCU_IC_PCIE_RESET_LO_TO_HI>; + };
MAINTAINERS +6 -0
@@ -2691,6 +2691,12 @@ S: Maintained F: drivers/media/platform/aspeed-video.c F: Documentation/devicetree/bindings/media/aspeed-video.txt +ASPEED XDMA ENGINE DRIVER +M: Eddie James <[email protected]> +L: linux-aspeed at lists.ozlabs.org (moderated for non-subscribers) +S: Maintained +F: Documentation/devicetree/bindings/soc/aspeed/xdma.txt + ASUS NOTEBOOKS AND EEEPC ACPI/WMI EXTRAS DRIVERS M: Corentin Chary <[email protected]> L: acpi4asus-user at lists.sourceforge.net
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 6/12 drivers/soc: Add Aspeed XDMA Engine Driver
In reply to Eddie JamesThe XDMA engine embedded in the AST2500 and AST2600 SOCs performs PCI DMA operations between the SOC (acting as a BMC) and a host processor in a server.
This commit adds a driver to control the XDMA engine and adds functions to initialize the hardware and memory and start DMA operations.
--- MAINTAINERS | 2 + drivers/soc/aspeed/Kconfig | 8 + drivers/soc/aspeed/Makefile | 1 + drivers/soc/aspeed/aspeed-xdma.c | 856 +++++++++++++++++++++++++++++++++++++++ include/uapi/linux/aspeed-xdma.h | 49 +++ 5 files changed, 916 insertions(+) create mode 100644 drivers/soc/aspeed/aspeed-xdma.c create mode 100644 include/uapi/linux/aspeed-xdma.h
MAINTAINERS +2 -0
@@ -2696,6 +2696,8 @@ M: Eddie James <[email protected]> L: linux-aspeed at lists.ozlabs.org (moderated for non-subscribers) S: Maintained F: Documentation/devicetree/bindings/soc/aspeed/xdma.txt +F: drivers/soc/aspeed/aspeed-xdma.c +F: include/uapi/linux/aspeed-xdma.h ASUS NOTEBOOKS AND EEEPC ACPI/WMI EXTRAS DRIVERS M: Corentin Chary <[email protected]>
drivers/soc/aspeed/Kconfig +8 -0
@@ -29,4 +29,12 @@ config ASPEED_P2A_CTRL ioctl()s, the driver also provides an interface for userspace mappings to a pre-defined region. +config ASPEED_XDMA + tristate "Aspeed XDMA Engine Driver" + depends on SOC_ASPEED && REGMAP && MFD_SYSCON && HAS_DMA + help + Enable support for the Aspeed XDMA Engine found on the Aspeed AST2XXX + SOCs. The XDMA engine can perform automatic PCI DMA operations + between the AST2XXX (acting as a BMC) and a host processor. + endmenu
drivers/soc/aspeed/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_ASPEED_LPC_CTRL) += aspeed-lpc-ctrl.o obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o obj-$(CONFIG_ASPEED_P2A_CTRL) += aspeed-p2a-ctrl.o +obj-$(CONFIG_ASPEED_XDMA) += aspeed-xdma.o
drivers/soc/aspeed/aspeed-xdma.c new file +856 -0
856 lines not on this page · raw message
include/uapi/linux/aspeed-xdma.h new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 7/12 drivers/soc: xdma: Add user interface
In reply to Eddie JamesThis commits adds a miscdevice to provide a user interface to the XDMA engine. The interface provides the write operation to start DMA operations. The DMA parameters are passed as the data to the write call. The actual data to transfer is NOT passed through write. Note that both directions of DMA operation are accomplished through the write command; BMC to host and host to BMC.
The XDMA engine is restricted to only accessing the reserved memory space on the AST2500, typically used by the VGA. For this reason, the VGA memory space is pooled and allocated with genalloc. Users calling mmap allocate pages from this pool for their usage. The space allocated by a client will be the space used in the DMA operation. For an "upstream" (BMC to host) operation, the data in the client's area will be transferred to the host. For a "downstream" (host to BMC) operation, the host data will be placed in the client's memory area.
Poll is also provided in order to determine when the DMA operation is complete for non-blocking IO.
--- drivers/soc/aspeed/aspeed-xdma.c | 223 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+)
drivers/soc/aspeed/aspeed-xdma.c +223 -0
@@ -64,6 +64,9 @@#define XDMA_CMDQ_SIZE PAGE_SIZE#define XDMA_NUM_CMDS \ (XDMA_CMDQ_SIZE / sizeof(struct aspeed_xdma_cmd)) +#define XDMA_OP_SIZE_MAX sizeof(struct aspeed_xdma_op) +#define XDMA_OP_SIZE_MIN \ + (sizeof(struct aspeed_xdma_op) - sizeof(u64))/* Aspeed specification requires 10ms after switching the reset line */ #define XDMA_RESET_TIME_MS 10
@@ -216,6 +219,7 @@ struct aspeed_xdma {bool in_reset;bool upstream;unsigned int cmd_idx; +struct mutex file_lock;struct mutex start_lock;struct delayed_work reset_work;spinlock_t client_lock;
@@ -230,6 +234,8 @@ struct aspeed_xdma {dma_addr_t cmdq_vga_phys;void *cmdq_vga_virt;struct gen_pool *vga_pool; + +struct miscdevice misc; };struct aspeed_xdma_client {
@@ -557,6 +563,204 @@ static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg)return IRQ_HANDLED ; } +static ssize_t aspeed_xdma_write (struct file *file,const char __user *buf, +size_t len,loff_t *offset) +{ +int rc; +struct aspeed_xdma_op op; +struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; +u32 offs = client->phys ? (client->phys - ctx->vga_phys) : +XDMA_CMDQ_SIZE ; + +if (len <XDMA_OP_SIZE_MIN ) +return -EINVAL ; + +if (len >XDMA_OP_SIZE_MAX ) + len =XDMA_OP_SIZE_MAX ; + + rc =copy_from_user (&op, buf, len); +if (rc) +return rc; + +if (op.direction ==ASPEED_XDMA_DIRECTION_RESET ) { +mutex_lock (&ctx->start_lock); + +if (aspeed_xdma_reset_start (ctx)) { +msleep (XDMA_RESET_TIME_MS ); + +aspeed_xdma_reset_finish (ctx); + } + +mutex_unlock (&ctx->start_lock); + +return len; + }else if (op.direction >ASPEED_XDMA_DIRECTION_RESET ) { +return -EINVAL ; + } + +if (op.len > ctx->vga_size - offs) +return -EINVAL ; + +if (file->f_flags &O_NONBLOCK ) { +if (!mutex_trylock (&ctx->file_lock)) +return -EAGAIN ; + +if (ctx->in_progress || ctx->in_reset) { +mutex_unlock (&ctx->file_lock); +return -EAGAIN ; + } + }else { +mutex_lock (&ctx->file_lock); + + rc =wait_event_interruptible (ctx->wait, !ctx->in_progress && + !ctx->in_reset); +if (rc) { +mutex_unlock (&ctx->file_lock); +return -EINTR ; + } + } + +aspeed_xdma_start (ctx, &op, ctx->vga_phys + offs, client); + +mutex_unlock (&ctx->file_lock); + +if (!(file->f_flags &O_NONBLOCK )) { + rc =wait_event_interruptible (ctx->wait, !ctx->in_progress); +if (rc) +return -EINTR ; + +if (client->error) +return -EIO ; + } + +return len; +} + +static __poll_t aspeed_xdma_poll (struct file *file, +struct poll_table_struct *wait) +{ +__poll_t mask =0 ; +__poll_t req =poll_requested_events (wait); +struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; + +if (req & (EPOLLIN |EPOLLRDNORM )) { +if (client->in_progress) +poll_wait (file, &ctx->wait, wait); + +if (!client->in_progress) { +if (client->error) + mask |=EPOLLERR ; +else + mask |=EPOLLIN |EPOLLRDNORM ; + } + } + +if (req & (EPOLLOUT |EPOLLWRNORM )) { +if (ctx->in_progress) +poll_wait (file, &ctx->wait, wait); + +if (!ctx->in_progress) + mask |=EPOLLOUT |EPOLLWRNORM ; + } + +return mask; +} + +static void aspeed_xdma_vma_close (struct vm_area_struct *vma) +{ +struct aspeed_xdma_client *client = vma->vm_private_data; + +gen_pool_free (client->ctx->vga_pool, (unsigned long )client->virt, + client->size); + + client->virt =NULL ; + client->phys =0 ; + client->size =0 ; +} + +static const struct vm_operations_struct aspeed_xdma_vm_ops = { + .close = aspeed_xdma_vma_close, +}; + +static int aspeed_xdma_mmap (struct file *file,struct vm_area_struct *vma) +{ +int rc; +struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; + +/* restrict file to one mapping */ +if (client->size) +return -ENOMEM ; + + client->size = vma->vm_end - vma->vm_start; + client->virt =gen_pool_dma_alloc (ctx->vga_pool, client->size, + &client->phys); +if (!client->virt) { + client->phys =0 ; + client->size =0 ; +return -ENOMEM ; + } + + vma->vm_pgoff = (client->phys - ctx->vga_phys) >>PAGE_SHIFT ; + vma->vm_ops = &aspeed_xdma_vm_ops; + vma->vm_private_data = client; + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); + + rc =io_remap_pfn_range (vma, vma->vm_start, client->phys >>PAGE_SHIFT , + client->size, vma->vm_page_prot); +if (rc) { +gen_pool_free (ctx->vga_pool, (unsigned long )client->virt, + client->size); + + client->virt =NULL ; + client->phys =0 ; + client->size =0 ; +return rc; + } + +dev_dbg (ctx->dev,"mmap: v[%08lx] to p[%08x], s[%08x]\n" , + vma->vm_start, (u32 )client->phys, client->size); + +return 0 ; +} + +static int aspeed_xdma_open (struct inode *inode,struct file *file) +{ +struct miscdevice *misc = file->private_data; + struct aspeed_xdma *ctx = container_of(misc, struct aspeed_xdma, misc); +struct aspeed_xdma_client *client =kzalloc (sizeof (*client), +GFP_KERNEL ); + +if (!client) +return -ENOMEM ; + + client->ctx = ctx; + file->private_data = client; +return 0 ; +} + +static int aspeed_xdma_release (struct inode *inode,struct file *file) +{ +struct aspeed_xdma_client *client = file->private_data; + +if (client->ctx->current_client == client) + client->ctx->current_client =NULL ; + +kfree (client); +return 0 ; +} + +static const struct file_operations aspeed_xdma_fops = { + .owner =THIS_MODULE , + .write = aspeed_xdma_write, + .poll = aspeed_xdma_poll, + .mmap = aspeed_xdma_mmap, + .open = aspeed_xdma_open, + .release = aspeed_xdma_release, +}; +static int aspeed_xdma_init (struct aspeed_xdma *ctx) {int rc;
@@ -739,6 +943,7 @@ static int aspeed_xdma_probe(struct platform_device *pdev) ctx->dev = dev;platform_set_drvdata (pdev, ctx); +mutex_init (&ctx->file_lock);mutex_init (&ctx->start_lock);INIT_DELAYED_WORK (&ctx->reset_work, aspeed_xdma_reset_work);spin_lock_init (&ctx->client_lock);
@@ -797,6 +1002,23 @@ static int aspeed_xdma_probe(struct platform_device *pdev)aspeed_xdma_init_eng (ctx); + ctx->misc.minor =MISC_DYNAMIC_MINOR ; + ctx->misc.fops = &aspeed_xdma_fops; + ctx->misc.name ="aspeed-xdma" ; + ctx->misc.parent = dev; + rc =misc_register (&ctx->misc); +if (rc) { +dev_err (dev,"Unable to register xdma miscdevice.\n" ); + +gen_pool_free (ctx->vga_pool, (unsigned long )ctx->cmdq_vga_virt, +XDMA_CMDQ_SIZE ); +iounmap (ctx->vga_virt); + +reset_control_assert (ctx->reset); +clk_disable_unprepare (ctx->clock); +return rc; + } +/* * This interrupt could fire immediately so only request it once the * engine and driver are initialized.
@@ -818,6 +1040,7 @@ static int aspeed_xdma_remove(struct platform_device *pdev) {struct aspeed_xdma *ctx =platform_get_drvdata (pdev); +misc_deregister (&ctx->misc);gen_pool_free (ctx->vga_pool, (unsigned long )ctx->cmdq_vga_virt,XDMA_CMDQ_SIZE );iounmap (ctx->vga_virt);
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 8/12 ARM: dts: aspeed: ast2500: Add XDMA Engine
In reply to Eddie JamesAdd a node for the XDMA engine with all the necessary information.
--- arch/arm/boot/dts/aspeed-g5.dtsi | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm/boot/dts/aspeed-g5.dtsi +10 -0
@@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ #include <dt-bindings/clock/aspeed-clock.h> +#include <dt-bindings/interrupt-controller/aspeed-scu-ic.h> / { model = "Aspeed BMC";
@@ -259,6 +260,15 @@ interrupts = <0x19>; }; + xdma: xdma at 1e6e7000 { + compatible = "aspeed,ast2500-xdma"; + reg = <0x1e6e7000 0x100>; + clocks = <&syscon ASPEED_CLK_GATE_BCLK>; + resets = <&syscon ASPEED_RESET_XDMA>; + interrupts-extended = <&vic 6>, <&scu_ic ASPEED_AST2500_SCU_IC_PCIE_RESET_LO_TO_HI>; + status = "disabled"; + }; + adc: adc at 1e6e9000 { compatible = "aspeed,ast2500-adc"; reg = <0x1e6e9000 0xb0>;
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 9/12 ARM: dts: aspeed: ast2600: Add XDMA Engine
In reply to Eddie JamesAdd a node for the XDMA engine with all the necessary information.
--- arch/arm/boot/dts/aspeed-g6.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm/boot/dts/aspeed-g6.dtsi +11 -0
@@ -3,6 +3,7 @@ #include <dt-bindings/interrupt-controller/arm-gic.h> #include <dt-bindings/clock/ast2600-clock.h> +#include <dt-bindings/interrupt-controller/aspeed-scu-ic.h> / { model = "Aspeed BMC";
@@ -315,6 +316,16 @@ quality = <100>; }; + xdma: xdma at 1e6e7000 { + compatible = "aspeed,ast2600-xdma"; + reg = <0x1e6e7000 0x100>; + clocks = <&syscon ASPEED_CLK_GATE_BCLK>; + resets = <&syscon ASPEED_RESET_DEV_XDMA>; + interrupts-extended = <&gic GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>, + <&scu_ic0 ASPEED_AST2600_SCU_IC0_PCIE_PERST_LO_TO_HI>; + status = "disabled"; + }; + gpio0: gpio at 1e780000 { #gpio-cells = <2>; gpio-controller;
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 10/12 ARM: dts: aspeed: witherspoon: Enable XDMA Engine
In reply to Eddie JamesEnable the XDMA engine node.
--- arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts +4 -0
@@ -658,4 +658,8 @@ memory-region = <&video_engine_memory>; }; +&xdma { + status = "okay"; +}; + #include "ibm-power9-dual.dtsi"
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 11/12 ARM: dts: aspeed: rainier: Enable XDMA engine
In reply to Eddie JamesEnable the XDMA engine node.
--- arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts +4 -0
@@ -970,3 +970,7 @@ spi-max-frequency = <100000000>; }; }; + +&xdma { + status = "okay"; +};
Signature · 1 line
1.8.3.1
Eddie James
maintainerPATCH 12/12 ARM: dts: aspeed: tacoma: Enable XDMA engine
In reply to Eddie JamesEnable the XDMA engine node.
--- arch/arm/boot/dts/aspeed-bmc-opp-tacoma.dts | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/boot/dts/aspeed-bmc-opp-tacoma.dts +4 -0
@@ -1193,3 +1193,7 @@ pinctrl-0 = <&pinctrl_lpc_default>, <&pinctrl_lsirq_default>; }; + +&xdma { + status = "okay"; +};
Signature · 1 line
1.8.3.1
Re: [PATCH 02/12] irqchip: Add Aspeed SCU interrupt controller
In reply to Eddie JamesOn Fri, 8 Nov 2019 14:18:23 -0600
Eddie James <[email protected]> wrote:
Hi Eddie,
Quoted 11 lines
The Aspeed SOCs provide some interrupts through the System Control Unit registers. Add an interrupt controller that provides these interrupts to the system.
Signed-off-by Eddie James <[email protected]>--- MAINTAINERS | 1 + drivers/irqchip/Makefile | 2 +- drivers/irqchip/irq-aspeed-scu-ic.c | 233 ++++++++++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 drivers/irqchip/irq-aspeed-scu-ic.c
[...]
drivers/irqchip/irq-aspeed-scu-ic.c line 131
Quoted 4 lines
drivers/irqchip/irq-aspeed-scu-ic.c new file +4
-0+static int aspeed_scu_ic_map (struct irq_domain *domain,unsigned int irq, +irq_hw_number_t hwirq) +{ +irq_set_chip_and_handler (irq, &aspeed_scu_ic_chip, handle_simple_irq);
handle_simple_irq is usually wrong, and works badly with threaded interrupts. I suggest you'd change it to handle_level_irq, which probably matches the behaviour of the controller.
Otherwise, this looks good.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Rob Herring
maintainerRe: [PATCH 01/12] dt-bindings: interrupt-controller: Add Aspeed SCU interrupt controller
In reply to Eddie JamesQuoted 12 lines · Eddie James
Document the Aspeed SCU interrupt controller and add an include file for the interrupts it provides.
Signed-off-by Eddie James <[email protected]>--- .../interrupt-controller/aspeed,ast2xxx-scu-ic.txt | 26 ++++++++++++++++++++++ MAINTAINERS | 7 ++++++ .../interrupt-controller/aspeed-scu-ic.h | 23 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/aspeed,ast2xxx-scu-ic.txt create mode 100644 include/dt-bindings/interrupt-controller/aspeed-scu-ic.h
Please add Acked-by/Reviewed-by tags when posting new versions. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for acks received on the version they apply.
If a tag was not added on purpose, please state why and what changed.
Re: [PATCH 05/12] dt-bindings: soc: Add Aspeed XDMA Engine
In reply to Eddie JamesQuoted 9 lines · Eddie James
Document the bindings for the Aspeed AST25XX and AST26XX XDMA engine.
Signed-off-by Eddie James <[email protected]>--- .../devicetree/bindings/soc/aspeed/xdma.txt | 24 ++++++++++++++++++++++ MAINTAINERS | 6 ++++++ 2 files changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/aspeed/xdma.txt
Re: [PATCH 06/12] drivers/soc: Add Aspeed XDMA Engine Driver
In reply to Eddie JamesQuoted 63 lines · Eddie James
The XDMA engine embedded in the AST2500 and AST2600 SOCs performs PCI DMA operations between the SOC (acting as a BMC) and a host processor in a server.
This commit adds a driver to control the XDMA engine and adds functions to initialize the hardware and memory and start DMA operations.
Signed-off-by Eddie James <[email protected]>--- MAINTAINERS | 2 + drivers/soc/aspeed/Kconfig | 8 + drivers/soc/aspeed/Makefile | 1 + drivers/soc/aspeed/aspeed-xdma.c | 856 +++++++++++++++++++++++++++++++++++++++ include/uapi/linux/aspeed-xdma.h | 49 +++ 5 files changed, 916 insertions(+) create mode 100644 drivers/soc/aspeed/aspeed-xdma.c create mode 100644 include/uapi/linux/aspeed-xdma.hMAINTAINERS +2
-0@@ -2696,6 +2696,8 @@ M: Eddie James <[email protected]> L: [email protected] (moderated for non-subscribers) S: Maintained F: Documentation/devicetree/bindings/soc/aspeed/xdma.txt +F: drivers/soc/aspeed/aspeed-xdma.c +F: include/uapi/linux/aspeed-xdma.h ASUS NOTEBOOKS AND EEEPC ACPI/WMI EXTRAS DRIVERS M: Corentin Chary <[email protected]>drivers/soc/aspeed/Kconfig +8
-0@@ -29,4 +29,12 @@ config ASPEED_P2A_CTRL ioctl()s, the driver also provides an interface for userspace mappings to a pre-defined region. +config ASPEED_XDMA + tristate "Aspeed XDMA Engine Driver" + depends on SOC_ASPEED && REGMAP && MFD_SYSCON && HAS_DMA + help + Enable support for the Aspeed XDMA Engine found on the Aspeed AST2XXX + SOCs. The XDMA engine can perform automatic PCI DMA operations + between the AST2XXX (acting as a BMC) and a host processor. + endmenudrivers/soc/aspeed/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_ASPEED_LPC_CTRL) += aspeed-lpc-ctrl.o obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o obj-$(CONFIG_ASPEED_P2A_CTRL) += aspeed-p2a-ctrl.o +obj-$(CONFIG_ASPEED_XDMA) += aspeed-xdma.odrivers/soc/aspeed/aspeed-xdma.c new file +0
-0
drivers/soc/aspeed/aspeed-xdma.c line 1
Quoted 1 line
drivers/soc/aspeed/aspeed-xdma.c new file +1
-0@@ -0,0 +1,856 @@ +// SPDX-License-Identifier: GPL-2.0+
This should be "GPL-2.0-or-later" (https://spdx.org/licenses/)
drivers/soc/aspeed/aspeed-xdma.c line 4
Quoted 3 lines
drivers/soc/aspeed/aspeed-xdma.c new file +3
-0+// Copyright IBM Corp 2019 + +#include <linux/aspeed-xdma.h>
A device-specific header in this include path seems a little strange to me.
Quoted 21 lines
drivers/soc/aspeed/aspeed-xdma.c new file +21
-0+#include <linux/bitfield.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/fs.h> +#include <linux/genalloc.h> +#include <linux/interrupt.h> +#include <linux/jiffies.h> +#include <linux/mfd/syscon.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/poll.h> +#include <linux/regmap.h> +#include <linux/reset.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/string.h>
drivers/soc/aspeed/aspeed-xdma.c line 35
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+#include <linux/uaccess.h> +#include <linux/wait.h> +#include <linux/workqueue.h> + +#define DEVICE_NAME "aspeed-xdma" + +#define SCU_AST2500_STRAP 0x070 +#define SCU_AST2500_STRAP_VGA_MEM GENMASK(3, 2) +#define SCU_AST2600_STRAP 0x500 +#define SCU_AST2600_STRAP_VGA_MEM GENMASK(14, 13)
It could be easier to review if you add support for one SoC at a time.
Quoted 17 lines
drivers/soc/aspeed/aspeed-xdma.c new file +17
-0+ +#define SCU_AST2500_PCIE_CONF 0x180 +#define SCU_AST2600_PCIE_CONF 0xc20 +#define SCU_PCIE_CONF_VGA_EN BIT(0) +#define SCU_PCIE_CONF_VGA_EN_MMIO BIT(1) +#define SCU_PCIE_CONF_VGA_EN_LPC BIT(2) +#define SCU_PCIE_CONF_VGA_EN_MSI BIT(3) +#define SCU_PCIE_CONF_VGA_EN_MCTP BIT(4) +#define SCU_PCIE_CONF_VGA_EN_IRQ BIT(5) +#define SCU_PCIE_CONF_VGA_EN_DMA BIT(6) +#define SCU_PCIE_CONF_BMC_EN BIT(8) +#define SCU_PCIE_CONF_BMC_EN_MMIO BIT(9) +#define SCU_PCIE_CONF_BMC_EN_MSI BIT(11) +#define SCU_PCIE_CONF_BMC_EN_MCTP BIT(12) +#define SCU_PCIE_CONF_BMC_EN_IRQ BIT(13) +#define SCU_PCIE_CONF_BMC_EN_DMA BIT(14) +
drivers/soc/aspeed/aspeed-xdma.c line 62
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+#define SCU_AST2500_BMC_CLASS_REV 0x19c +#define SCU_AST2600_BMC_CLASS_REV 0xc4c +#define SCU_BMC_CLASS_REV_XDMA 0xff000001 + +#define SDMC_BASE 0x1e6e0000 +#define SDMC_CONF 0x004 +#define SDMC_CONF_MEM GENMASK(1, 0) +#define SDMC_REMAP 0x008 +#define SDMC_AST2500_REMAP_MAGIC (BIT(16) | BIT(17)) +#define SDMC_AST2600_REMAP_MAGIC BIT(18)
Can we have something more descriptive than "MAGIC"? What these bits are doing is well documented and defined.
Quoted 40 lines
drivers/soc/aspeed/aspeed-xdma.c new file +40
-0+ +#define XDMA_CMDQ_SIZE PAGE_SIZE +#define XDMA_NUM_CMDS \ + (XDMA_CMDQ_SIZE / sizeof(struct aspeed_xdma_cmd)) + +/* Aspeed specification requires 10ms after switching the reset line */ +#define XDMA_RESET_TIME_MS 10 + +#define XDMA_DS_PCIE_REQ_SIZE_128 0 +#define XDMA_DS_PCIE_REQ_SIZE_256 1 +#define XDMA_DS_PCIE_REQ_SIZE_512 2 +#define XDMA_DS_PCIE_REQ_SIZE_1K 3 +#define XDMA_DS_PCIE_REQ_SIZE_2K 4 +#define XDMA_DS_PCIE_REQ_SIZE_4K 5 + +#define XDMA_CMD_AST2500_PITCH_SHIFT 3 +#define XDMA_CMD_AST2500_PITCH_BMC GENMASK_ULL(62, 51) +#define XDMA_CMD_AST2500_PITCH_HOST GENMASK_ULL(46, 35) +#define XDMA_CMD_AST2500_PITCH_UPSTREAM BIT_ULL(31) +#define XDMA_CMD_AST2500_PITCH_ADDR GENMASK_ULL(29, 4) +#define XDMA_CMD_AST2500_PITCH_ID BIT_ULL(0) +#define XDMA_CMD_AST2500_CMD_IRQ_EN BIT_ULL(31) +#define XDMA_CMD_AST2500_CMD_LINE_NO GENMASK_ULL(27, 16) +#define XDMA_CMD_AST2500_CMD_IRQ_BMC BIT_ULL(15) +#define XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT 4 +#define XDMA_CMD_AST2500_CMD_LINE_SIZE \ + GENMASK_ULL(14, XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT) +#define XDMA_CMD_AST2500_CMD_ID BIT_ULL(1) + +#define XDMA_CMD_AST2600_PITCH_BMC GENMASK_ULL(62, 48) +#define XDMA_CMD_AST2600_PITCH_HOST GENMASK_ULL(46, 32) +#define XDMA_CMD_AST2600_PITCH_ADDR GENMASK_ULL(30, 0) +#define XDMA_CMD_AST2600_CMD_64_EN BIT_ULL(40) +#define XDMA_CMD_AST2600_CMD_IRQ_BMC BIT_ULL(37) +#define XDMA_CMD_AST2600_CMD_IRQ_HOST BIT_ULL(36) +#define XDMA_CMD_AST2600_CMD_UPSTREAM BIT_ULL(32) +#define XDMA_CMD_AST2600_CMD_LINE_NO GENMASK_ULL(27, 16) +#define XDMA_CMD_AST2600_CMD_LINE_SIZE GENMASK_ULL(14, 0) +#define XDMA_CMD_AST2600_CMD_MULTILINE_SIZE GENMASK_ULL(14, 12) +
drivers/soc/aspeed/aspeed-xdma.c line 112
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+#define XDMA_AST2500_QUEUE_ENTRY_SIZE 4 +#define XDMA_AST2500_HOST_CMDQ_ADDR0 0x00 +#define XDMA_AST2500_HOST_CMDQ_ENDP 0x04 +#define XDMA_AST2500_HOST_CMDQ_WRITEP 0x08 +#define XDMA_AST2500_HOST_CMDQ_READP 0x0c +#define XDMA_AST2500_BMC_CMDQ_ADDR 0x10 +#define XDMA_AST2500_BMC_CMDQ_ENDP 0x14 +#define XDMA_AST2500_BMC_CMDQ_WRITEP 0x18 +#define XDMA_AST2500_BMC_CMDQ_READP 0x1c +#define XDMA_BMC_CMDQ_READP_MAGIC 0xee882266
What's this about? Using a macro to abstract a magic number and then using the word "magic" in the name isn't very helpful. I think it should be renamed or documented, or both.
Quoted 100 lines
drivers/soc/aspeed/aspeed-xdma.c new file +100
-0+#define XDMA_AST2500_CTRL 0x20 +#define XDMA_AST2500_CTRL_US_COMP BIT(4) +#define XDMA_AST2500_CTRL_DS_COMP BIT(5) +#define XDMA_AST2500_CTRL_DS_DIRTY BIT(6) +#define XDMA_AST2500_CTRL_DS_SIZE GENMASK(19, 17) +#define XDMA_AST2500_CTRL_DS_TIMEOUT BIT(28) +#define XDMA_AST2500_CTRL_DS_CHECK_ID BIT(29) +#define XDMA_AST2500_STATUS 0x24 +#define XDMA_AST2500_STATUS_US_COMP BIT(4) +#define XDMA_AST2500_STATUS_DS_COMP BIT(5) +#define XDMA_AST2500_STATUS_DS_DIRTY BIT(6) +#define XDMA_AST2500_INPRG_DS_CMD1 0x38 +#define XDMA_AST2500_INPRG_DS_CMD2 0x3c +#define XDMA_AST2500_INPRG_US_CMD00 0x40 +#define XDMA_AST2500_INPRG_US_CMD01 0x44 +#define XDMA_AST2500_INPRG_US_CMD10 0x48 +#define XDMA_AST2500_INPRG_US_CMD11 0x4c +#define XDMA_AST2500_INPRG_US_CMD20 0x50 +#define XDMA_AST2500_INPRG_US_CMD21 0x54 +#define XDMA_AST2500_HOST_CMDQ_ADDR1 0x60 +#define XDMA_AST2500_VGA_CMDQ_ADDR0 0x64 +#define XDMA_AST2500_VGA_CMDQ_ENDP 0x68 +#define XDMA_AST2500_VGA_CMDQ_WRITEP 0x6c +#define XDMA_AST2500_VGA_CMDQ_READP 0x70 +#define XDMA_AST2500_VGA_CMD_STATUS 0x74 +#define XDMA_AST2500_VGA_CMDQ_ADDR1 0x78 + +#define XDMA_AST2600_QUEUE_ENTRY_SIZE 2 +#define XDMA_AST2600_HOST_CMDQ_ADDR0 0x00 +#define XDMA_AST2600_HOST_CMDQ_ADDR1 0x04 +#define XDMA_AST2600_HOST_CMDQ_ENDP 0x08 +#define XDMA_AST2600_HOST_CMDQ_WRITEP 0x0c +#define XDMA_AST2600_HOST_CMDQ_READP 0x10 +#define XDMA_AST2600_BMC_CMDQ_ADDR 0x14 +#define XDMA_AST2600_BMC_CMDQ_ENDP 0x18 +#define XDMA_AST2600_BMC_CMDQ_WRITEP 0x1c +#define XDMA_AST2600_BMC_CMDQ_READP 0x20 +#define XDMA_AST2600_VGA_CMDQ_ADDR0 0x24 +#define XDMA_AST2600_VGA_CMDQ_ADDR1 0x28 +#define XDMA_AST2600_VGA_CMDQ_ENDP 0x2c +#define XDMA_AST2600_VGA_CMDQ_WRITEP 0x30 +#define XDMA_AST2600_VGA_CMDQ_READP 0x34 +#define XDMA_AST2600_CTRL 0x38 +#define XDMA_AST2600_CTRL_US_COMP BIT(16) +#define XDMA_AST2600_CTRL_DS_COMP BIT(17) +#define XDMA_AST2600_CTRL_DS_DIRTY BIT(18) +#define XDMA_AST2600_CTRL_DS_SIZE GENMASK(22, 20) +#define XDMA_AST2600_STATUS 0x3c +#define XDMA_AST2600_STATUS_US_COMP BIT(16) +#define XDMA_AST2600_STATUS_DS_COMP BIT(17) +#define XDMA_AST2600_STATUS_DS_DIRTY BIT(18) +#define XDMA_AST2600_INPRG_DS_CMD00 0x40 +#define XDMA_AST2600_INPRG_DS_CMD01 0x44 +#define XDMA_AST2600_INPRG_DS_CMD10 0x48 +#define XDMA_AST2600_INPRG_DS_CMD11 0x4c +#define XDMA_AST2600_INPRG_DS_CMD20 0x50 +#define XDMA_AST2600_INPRG_DS_CMD21 0x54 +#define XDMA_AST2600_INPRG_US_CMD00 0x60 +#define XDMA_AST2600_INPRG_US_CMD01 0x64 +#define XDMA_AST2600_INPRG_US_CMD10 0x68 +#define XDMA_AST2600_INPRG_US_CMD11 0x6c +#define XDMA_AST2600_INPRG_US_CMD20 0x70 +#define XDMA_AST2600_INPRG_US_CMD21 0x74 + +enum versions { xdma_ast2500, xdma_ast2600 }; + +struct aspeed_xdma_cmd { +u64 host_addr; +u64 pitch; +u64 cmd; +u64 reserved; +}; + +struct aspeed_xdma_regs { +u8 bmc_cmdq_addr; +u8 bmc_cmdq_endp; +u8 bmc_cmdq_writep; +u8 bmc_cmdq_readp; +u8 control; +u8 status; +}; + +struct aspeed_xdma_status_bits { +u32 us_comp; +u32 ds_comp; +u32 ds_dirty; +}; + +struct aspeed_xdma_client ; + +struct aspeed_xdma { +enum versions version; +u32 control; +unsigned int queue_entry_size; +struct aspeed_xdma_regs regs; +struct aspeed_xdma_status_bits status_bits; + +struct device *dev; +void __iomem *base; +struct clk *clock;
drivers/soc/aspeed/aspeed-xdma.c line 222
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+struct reset_control *reset; + +bool in_progress; +bool in_reset; +bool upstream; +unsigned int cmd_idx; +struct mutex start_lock; +struct delayed_work reset_work; +spinlock_t client_lock; +spinlock_t reset_lock;
What data are each of these locks protecting? Please add documentation about how you intend to use them. Try to group the locks with the data they protect if this is not already the case.
Quoted 24 lines
drivers/soc/aspeed/aspeed-xdma.c new file +24
-0+wait_queue_head_t wait; +struct aspeed_xdma_client *current_client; + +u32 vga_phys; +u32 vga_size; +void *cmdq; +void __iomem *vga_virt; +dma_addr_t cmdq_vga_phys; +void *cmdq_vga_virt; +struct gen_pool *vga_pool; +}; + +struct aspeed_xdma_client { +struct aspeed_xdma *ctx; + +bool error; +bool in_progress; +void *virt; +dma_addr_t phys; +u32 size; +}; + +static u32 aspeed_xdma_readl (struct aspeed_xdma *ctx,u8 reg) +{
drivers/soc/aspeed/aspeed-xdma.c line 256
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+u32 v =readl (ctx->base + reg); + +dev_dbg (ctx->dev,"read %02x[%08x]\n" , reg, v); +return v; +} + +static void aspeed_xdma_writel (struct aspeed_xdma *ctx,u8 reg,u32 val) +{ +writel (val, ctx->base + reg); +dev_dbg (ctx->dev,"write %02x[%08x]\n" , reg,readl (ctx->base + reg));
That readl() seems a bit paranoid, and is probably evaluated whether or not this dev_dbg() is enabled. What drove this approach?
Quoted 36 lines
drivers/soc/aspeed/aspeed-xdma.c new file +36
-0+} + +static void aspeed_xdma_init_eng (struct aspeed_xdma *ctx) +{ +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_endp, + ctx->queue_entry_size *XDMA_NUM_CMDS ); +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_readp, +XDMA_BMC_CMDQ_READP_MAGIC ); +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_writep,0 ); +aspeed_xdma_writel (ctx, ctx->regs.control, ctx->control); +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_addr, ctx->cmdq_vga_phys); + + ctx->cmd_idx =0 ; + ctx->in_progress = false; +} + +static unsigned int aspeed_xdma_ast2500_set_cmd (struct aspeed_xdma *ctx, +struct aspeed_xdma_op *op, +u32 bmc_addr) +{ +u64 cmd =XDMA_CMD_AST2500_CMD_IRQ_EN |XDMA_CMD_AST2500_CMD_IRQ_BMC | +XDMA_CMD_AST2500_CMD_ID ; +u64 cmd_pitch = (op->direction ?XDMA_CMD_AST2500_PITCH_UPSTREAM :0 ) | +XDMA_CMD_AST2500_PITCH_ID ; +unsigned int line_size; +unsigned int nidx = (ctx->cmd_idx +1 ) %XDMA_NUM_CMDS ; +unsigned int line_no =1 ; +unsigned int pitch =1 ; +struct aspeed_xdma_cmd *ncmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[ctx->cmd_idx]); + +dev_dbg (ctx->dev,"xdma %s ast2500: bmc[%08x] len[%08x] host[%08x]\n" , + op->direction ?"upstream" :"downstream" , bmc_addr, op->len, + (u32 )op->host_addr); + +if (op->len >XDMA_CMD_AST2500_CMD_LINE_SIZE ) {
drivers/soc/aspeed/aspeed-xdma.c line 302
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+unsigned int rem; +unsigned int total; + + line_no = op->len /XDMA_CMD_AST2500_CMD_LINE_SIZE ; + total =XDMA_CMD_AST2500_CMD_LINE_SIZE * line_no; + rem = (op->len - total) >> +XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT ; + line_size =XDMA_CMD_AST2500_CMD_LINE_SIZE ; + pitch = line_size >>XDMA_CMD_AST2500_PITCH_SHIFT ; + line_size >>=XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT ;
Can we clean up the configuration of line_size and pitch here? They are set to constants in this case.
Quoted 118 lines
drivers/soc/aspeed/aspeed-xdma.c new file +118
-0+ +if (rem) { +u32 rbmc = bmc_addr + total; +struct aspeed_xdma_cmd *rcmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[nidx]); + + rcmd->host_addr = op->host_addr + (u64 )total; + rcmd->pitch = cmd_pitch | + ((u64 )rbmc &XDMA_CMD_AST2500_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_HOST ,1 ) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_BMC ,1 ); + rcmd->cmd = cmd | +FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_NO ,1 ) | +FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_SIZE , + rem); + +print_hex_dump_debug ("xdma rem" ,DUMP_PREFIX_OFFSET , +16 ,1 , rcmd,sizeof (*rcmd), true); + + cmd &= ~(XDMA_CMD_AST2500_CMD_IRQ_EN | +XDMA_CMD_AST2500_CMD_IRQ_BMC ); + + nidx = (nidx +1 ) %XDMA_NUM_CMDS ; + } + }else { + line_size = op->len >>XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT ; + } + + ncmd->host_addr = op->host_addr; + ncmd->pitch = cmd_pitch | + ((u64 )bmc_addr &XDMA_CMD_AST2500_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_HOST , pitch) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_BMC , pitch); + ncmd->cmd = cmd |FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_NO , line_no) | +FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_SIZE , line_size); + +print_hex_dump_debug ("xdma cmd" ,DUMP_PREFIX_OFFSET ,16 ,1 , ncmd, +sizeof (*ncmd), true); + +return nidx; +} + +static unsigned int aspeed_xdma_ast2600_set_cmd (struct aspeed_xdma *ctx, +struct aspeed_xdma_op *op, +u32 bmc_addr) +{ +u64 cmd =XDMA_CMD_AST2600_CMD_IRQ_BMC | + (op->direction ?XDMA_CMD_AST2600_CMD_UPSTREAM :0 ); +unsigned int line_size; +unsigned int nidx = (ctx->cmd_idx +1 ) %XDMA_NUM_CMDS ; +unsigned int line_no =1 ; +unsigned int pitch =1 ; +struct aspeed_xdma_cmd *ncmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[ctx->cmd_idx]); + +if ((op->host_addr + op->len) &0xffffffff00000000ULL ) + cmd |=XDMA_CMD_AST2600_CMD_64_EN ; + +dev_dbg (ctx->dev,"xdma %s ast2600: bmc[%08x] len[%08x] " +"host[%016llx]\n" , op->direction ?"upstream" :"downstream" , + bmc_addr, op->len, op->host_addr); + +if (op->len >XDMA_CMD_AST2600_CMD_LINE_SIZE ) { +unsigned int rem; +unsigned int total; + + line_no = op->len /XDMA_CMD_AST2600_CMD_MULTILINE_SIZE ; + total =XDMA_CMD_AST2600_CMD_MULTILINE_SIZE * line_no; + rem = op->len - total; + line_size =XDMA_CMD_AST2600_CMD_MULTILINE_SIZE ; + pitch = line_size; + +if (rem) { +u32 rbmc = bmc_addr + total; +struct aspeed_xdma_cmd *rcmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[nidx]); + + rcmd->host_addr = op->host_addr + (u64 )total; + rcmd->pitch = + ((u64 )rbmc &XDMA_CMD_AST2600_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_HOST ,1 ) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_BMC ,1 ); + rcmd->cmd = cmd | +FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_NO ,1 ) | +FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_SIZE , + rem); + +print_hex_dump_debug ("xdma rem" ,DUMP_PREFIX_OFFSET , +16 ,1 , rcmd,sizeof (*rcmd), true); + + cmd &= ~XDMA_CMD_AST2600_CMD_IRQ_BMC ; + + nidx = (nidx +1 ) %XDMA_NUM_CMDS ; + } + }else { + line_size = op->len; + } + + ncmd->host_addr = op->host_addr; + ncmd->pitch = ((u64 )bmc_addr &XDMA_CMD_AST2600_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_HOST , pitch) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_BMC , pitch); + ncmd->cmd = cmd |FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_NO , line_no) | +FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_SIZE , line_size); + +print_hex_dump_debug ("xdma cmd" ,DUMP_PREFIX_OFFSET ,16 ,1 , ncmd, +sizeof (*ncmd), true); + +return nidx; +} + +static void aspeed_xdma_start (struct aspeed_xdma *ctx, +struct aspeed_xdma_op *op,u32 bmc_addr, +struct aspeed_xdma_client *client) +{ +unsigned int nidx; + +mutex_lock (&ctx->start_lock);
drivers/soc/aspeed/aspeed-xdma.c line 430
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ +switch (ctx->version) { +default : +case xdma_ast2500: + nidx =aspeed_xdma_ast2500_set_cmd (ctx, op, bmc_addr); +break ; +case xdma_ast2600: + nidx =aspeed_xdma_ast2600_set_cmd (ctx, op, bmc_addr); +break ; + }
What was the trade-off between the enum and function pointers? Is the enum approach strictly better for some reason?
drivers/soc/aspeed/aspeed-xdma.c line 437
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+ +memcpy (ctx->cmdq_vga_virt, ctx->cmdq,XDMA_CMDQ_SIZE ); + + client->in_progress = true; + ctx->current_client = client; + + ctx->in_progress = true;
Do we need ctx->in_progress vs just using the NULL state of ctx->current_client? Is it possible for ctx->current_client to be set and not have a transfer in progress?
Quoted 11 lines
drivers/soc/aspeed/aspeed-xdma.c new file +11
-0+ ctx->upstream = op->direction ? true : false; + +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_writep, + nidx * ctx->queue_entry_size); + + ctx->cmd_idx = nidx; + +mutex_unlock (&ctx->start_lock); +} + +static void aspeed_xdma_done (struct aspeed_xdma *ctx,bool error)
drivers/soc/aspeed/aspeed-xdma.c line 458
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+{ +unsigned long flags; + +/* +* Lock to make sure simultaneous reset and transfer complete don't +* leave the client with the wrong error state. +*/ +spin_lock_irqsave (&ctx->client_lock, flags); + +if (ctx->current_client) {
You're testing ctx->current_client under ctx->client_lock here, but ctx->current_client is set under ctx->start_lock in aspeed_xdma_start(), which does not take ctx->client_lock. What data is protected by ctx->client_lock? What data is protected by ctx->client_lock?
drivers/soc/aspeed/aspeed-xdma.c line 466
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c new file +8
-0+ ctx->current_client->error = error; + ctx->current_client->in_progress = false; + ctx->current_client =NULL ; + } + +spin_unlock_irqrestore (&ctx->client_lock, flags); + + ctx->in_progress = false;
You set ctx->in_progress under ctx->start_lock in aspeed_xdma_start() but you do not take ctx->start_lock when setting it here. What data is ctx->start_lock protecting?
Quoted 47 lines
drivers/soc/aspeed/aspeed-xdma.c new file +47
-0+wake_up_interruptible_all (&ctx->wait); +} + +static irqreturn_t aspeed_xdma_irq (int irq,void *arg) +{ +struct aspeed_xdma *ctx = arg; +u32 status =aspeed_xdma_readl (ctx, ctx->regs.status); + +if (status & ctx->status_bits.ds_dirty) { +aspeed_xdma_done (ctx, true); + }else { +if (status & ctx->status_bits.us_comp) { +if (ctx->upstream) +aspeed_xdma_done (ctx, false); + } + +if (status & ctx->status_bits.ds_comp) { +if (!ctx->upstream) +aspeed_xdma_done (ctx, false); + } + } + +aspeed_xdma_writel (ctx, ctx->regs.status, status); + +return IRQ_HANDLED ; +} + +static void aspeed_xdma_reset_finish (struct aspeed_xdma *ctx) +{ +unsigned long flags; + +spin_lock_irqsave (&ctx->reset_lock, flags); + + ctx->in_reset = false; +reset_control_deassert (ctx->reset); + +spin_unlock_irqrestore (&ctx->reset_lock, flags); + +msleep (XDMA_RESET_TIME_MS ); + +aspeed_xdma_init_eng (ctx); +aspeed_xdma_done (ctx, true); +} + +static bool aspeed_xdma_reset_start (struct aspeed_xdma *ctx) +{ +bool rc = true;
drivers/soc/aspeed/aspeed-xdma.c line 523
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+unsigned long flags; + +spin_lock_irqsave (&ctx->reset_lock, flags); + +if (ctx->in_reset) { + rc = false; + }else { + ctx->in_reset = true; +reset_control_assert (ctx->reset); + }
Do start and finish need to be split in this way?
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c new file +5
-0+ +spin_unlock_irqrestore (&ctx->reset_lock, flags); + +return rc; +}
drivers/soc/aspeed/aspeed-xdma.c line 538
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ +static void aspeed_xdma_reset_work (struct work_struct *work) +{ +struct delayed_work *dwork =to_delayed_work (work); + struct aspeed_xdma *ctx = container_of(dwork, struct aspeed_xdma, + reset_work); + +/* +* Lock to make sure operations aren't started while the engine is +* in an undefined state coming out of reset and waiting to init.
Shouldn't we be holding it across both aspeed_xdma_reset_start() and aspeed_xdma_reset_finish()?
Quoted 25 lines
drivers/soc/aspeed/aspeed-xdma.c new file +25
-0+*/ +mutex_lock (&ctx->start_lock); + +aspeed_xdma_reset_finish (ctx); + +mutex_unlock (&ctx->start_lock); +} + +static irqreturn_t aspeed_xdma_pcie_irq (int irq,void *arg) +{ +struct aspeed_xdma *ctx = arg; + +dev_dbg (ctx->dev,"pcie reset\n" ); + +if (aspeed_xdma_reset_start (ctx)) +schedule_delayed_work (&ctx->reset_work, +msecs_to_jiffies (XDMA_RESET_TIME_MS )); + +return IRQ_HANDLED ; +} + +static int aspeed_xdma_init (struct aspeed_xdma *ctx) +{ +int rc; +struct regmap *scu;
drivers/soc/aspeed/aspeed-xdma.c
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+u32 conf; +u32 mem_size; +u32 remap; +u32 scu_bmc_class; +u32 scu_pcie_conf; +u32 scu_strap; +u32 sdmc_remap_magic; +u32 strap =0 ; +const u32 bmc =SCU_PCIE_CONF_BMC_EN |SCU_PCIE_CONF_BMC_EN_MSI | +SCU_PCIE_CONF_BMC_EN_MCTP
Do we need MCTP here?
| SCU_PCIE_CONF_BMC_EN_IRQ |
drivers/soc/aspeed/aspeed-xdma.c
Quoted 3 lines
drivers/soc/aspeed/aspeed-xdma.c new file +3
-0+SCU_PCIE_CONF_BMC_EN_DMA ; +const u32 vga =SCU_PCIE_CONF_VGA_EN |SCU_PCIE_CONF_VGA_EN_MSI | +SCU_PCIE_CONF_VGA_EN_MCTP
Do we need MCTP here?
| SCU_PCIE_CONF_VGA_EN_IRQ |
drivers/soc/aspeed/aspeed-xdma.c line 580
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c new file +4
-0+SCU_PCIE_CONF_VGA_EN_DMA ; +u32 mem_sizes[4 ] = {0x8000000 ,0x10000000 ,0x20000000 ,0x40000000 }; +const u32 vga_sizes[4 ] = {0x800000 ,0x1000000 ,0x2000000 ,0x4000000 }; +void __iomem *sdmc_base =ioremap (SDMC_BASE ,0x100 );
Surely this should be a phandle from the devicetree? And what about conflicts with a potential SDMC driver? I don't think what you have is the right approach.
drivers/soc/aspeed/aspeed-xdma.c line 593
Quoted 13 lines
drivers/soc/aspeed/aspeed-xdma.c new file +13
-0+ +if (!sdmc_base) { +dev_err (ctx->dev,"Failed to ioremap mem controller regs.\n" ); +return -ENOMEM ; + } + +switch (ctx->version) { +default : +case xdma_ast2500: + scu_bmc_class =SCU_AST2500_BMC_CLASS_REV ; + scu_pcie_conf =SCU_AST2500_PCIE_CONF ; + scu_strap =SCU_AST2500_STRAP ; + sdmc_remap_magic =SDMC_AST2500_REMAP_MAGIC ;
Can't this be described statically? The values should be derived from the devicetree compatible.
drivers/soc/aspeed/aspeed-xdma.c line 595
Quoted 2 lines
drivers/soc/aspeed/aspeed-xdma.c new file +2
-0+ + scu =syscon_regmap_lookup_by_compatible ("aspeed,ast2500-scu" );
I think we should do this via phandle in the devicetree.
drivers/soc/aspeed/aspeed-xdma.c line 601
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+break ; +case xdma_ast2600: + scu_bmc_class =SCU_AST2600_BMC_CLASS_REV ; + scu_pcie_conf =SCU_AST2600_PCIE_CONF ; + scu_strap =SCU_AST2600_STRAP ; + sdmc_remap_magic =SDMC_AST2600_REMAP_MAGIC ;
Can't this be described statically? The values should be derived from the devicetree compatible.
drivers/soc/aspeed/aspeed-xdma.c line 606
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c new file +5
-0+ + mem_sizes[0 ] *=2 ; + mem_sizes[1 ] *=2 ; + mem_sizes[2 ] *=2 ; + mem_sizes[3 ] *=2 ;
Same query as above.
drivers/soc/aspeed/aspeed-xdma.c line 608
Quoted 2 lines
drivers/soc/aspeed/aspeed-xdma.c new file +2
-0+ + scu =syscon_regmap_lookup_by_compatible ("aspeed,ast2600-scu" );
I think we should do this via phandle in the devicetree.
drivers/soc/aspeed/aspeed-xdma.c line 619
Quoted 11 lines
drivers/soc/aspeed/aspeed-xdma.c new file +11
-0+break ; + }; + +if (!scu) { +dev_err (ctx->dev,"Failed to grab SCU regs.\n" ); +return -ENOMEM ; + } + +/* Set SOC to use the BMC PCIe device and set the device class code */ +regmap_update_bits (scu, scu_pcie_conf, bmc | vga, bmc); +regmap_write (scu, scu_bmc_class,SCU_BMC_CLASS_REV_XDMA );
This should be selectable, probably via the devicetree.
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+ +/* +* Calculate the VGA memory size and physical address from the SCU and +* memory controller registers. +*/ +regmap_read (scu, scu_strap, &strap);
drivers/soc/aspeed/aspeed-xdma.c line 635
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ +switch (ctx->version) { +case xdma_ast2500: + ctx->vga_size = vga_sizes[FIELD_GET (SCU_AST2500_STRAP_VGA_MEM , + strap)]; +break ; +case xdma_ast2600: + ctx->vga_size = vga_sizes[FIELD_GET (SCU_AST2600_STRAP_VGA_MEM , + strap)]; +break ;
Can't this be described statically? The values should be derived from the devicetree compatible.
drivers/soc/aspeed/aspeed-xdma.c line 642
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+ } + + conf =readl (sdmc_base +SDMC_CONF ); + remap =readl (sdmc_base +SDMC_REMAP ); + remap |= sdmc_remap_magic; +writel (remap, sdmc_base +SDMC_REMAP ); + mem_size = mem_sizes[conf &SDMC_CONF_MEM ];
See previous objection to this.
drivers/soc/aspeed/aspeed-xdma.c line 646
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c new file +4
-0+ +iounmap (sdmc_base); + + ctx->vga_phys = (mem_size - ctx->vga_size) +0x80000000 ;
RAM base should be extracted from the devicetree. Better yet, the VGA space should be extracted from the devicetree and this calculation avoided altogether.
drivers/soc/aspeed/aspeed-xdma.c line 654
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c new file +8
-0+ + ctx->cmdq =devm_kzalloc (ctx->dev,XDMA_CMDQ_SIZE ,GFP_KERNEL ); +if (!ctx->cmdq) { +dev_err (ctx->dev,"Failed to allocate command queue.\n" ); +return -ENOMEM ; + } + + ctx->vga_virt =ioremap (ctx->vga_phys, ctx->vga_size);
Use devm_ioremap() to avoid the cleanup.
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c new file +5
-0+if (!ctx->vga_virt) { +dev_err (ctx->dev,"Failed to ioremap VGA memory.\n" ); +return -ENOMEM ; + } +
drivers/soc/aspeed/aspeed-xdma.c line 669
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ rc =gen_pool_add_virt (ctx->vga_pool, (unsigned long )ctx->vga_virt, + ctx->vga_phys, ctx->vga_size,-1 ); +if (rc) { +dev_err (ctx->dev,"Failed to add memory to genalloc pool.\n" ); +iounmap (ctx->vga_virt); +return rc; + } + + ctx->cmdq_vga_virt =gen_pool_dma_alloc (ctx->vga_pool,XDMA_CMDQ_SIZE , + &ctx->cmdq_vga_phys);
Can you educate me on this a little? Why is a command queue being allocated in memory writable by the host? Aren't we opening ourselves up to potential corruption?
Quoted 39 lines
drivers/soc/aspeed/aspeed-xdma.c new file +39
-0+if (!ctx->cmdq_vga_virt) { +dev_err (ctx->dev,"Failed to genalloc cmdq.\n" ); +iounmap (ctx->vga_virt); +return -ENOMEM ; + } + +dev_dbg (ctx->dev,"VGA mapped at phys[%08x], size[%08x].\n" , + ctx->vga_phys, ctx->vga_size); + +return 0 ; +} + +static int aspeed_xdma_probe (struct platform_device *pdev) +{ +int irq; +int pcie_irq; +int rc; +enum versions vs = xdma_ast2500; +struct device *dev = &pdev->dev; +struct aspeed_xdma *ctx =devm_kzalloc (dev,sizeof (*ctx),GFP_KERNEL ); +const void *md =of_device_get_match_data (dev); + +if (!ctx) +return -ENOMEM ; + +if (md) + vs = (enum versions )md; + +switch (vs) { +default : +case xdma_ast2500: + ctx->version = xdma_ast2500; + ctx->control =XDMA_AST2500_CTRL_US_COMP | +XDMA_AST2500_CTRL_DS_COMP | +XDMA_AST2500_CTRL_DS_DIRTY | +FIELD_PREP (XDMA_AST2500_CTRL_DS_SIZE , +XDMA_DS_PCIE_REQ_SIZE_256 ) | +XDMA_AST2500_CTRL_DS_TIMEOUT | +XDMA_AST2500_CTRL_DS_CHECK_ID ;
drivers/soc/aspeed/aspeed-xdma.c line 718
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ ctx->queue_entry_size =XDMA_AST2500_QUEUE_ENTRY_SIZE ; + ctx->regs.bmc_cmdq_addr =XDMA_AST2500_BMC_CMDQ_ADDR ; + ctx->regs.bmc_cmdq_endp =XDMA_AST2500_BMC_CMDQ_ENDP ; + ctx->regs.bmc_cmdq_writep =XDMA_AST2500_BMC_CMDQ_WRITEP ; + ctx->regs.bmc_cmdq_readp =XDMA_AST2500_BMC_CMDQ_READP ; + ctx->regs.control =XDMA_AST2500_CTRL ; + ctx->regs.status =XDMA_AST2500_STATUS ; + ctx->status_bits.us_comp =XDMA_AST2500_STATUS_US_COMP ; + ctx->status_bits.ds_comp =XDMA_AST2500_STATUS_DS_COMP ; + ctx->status_bits.ds_dirty =XDMA_AST2500_STATUS_DS_DIRTY ;
Why not include all this in the match data?
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c new file +8
-0+break ; +case xdma_ast2600: + ctx->version = xdma_ast2600; + ctx->control =XDMA_AST2600_CTRL_US_COMP | +XDMA_AST2600_CTRL_DS_COMP | +XDMA_AST2600_CTRL_DS_DIRTY | +FIELD_PREP (XDMA_AST2600_CTRL_DS_SIZE , +XDMA_DS_PCIE_REQ_SIZE_256 );
drivers/soc/aspeed/aspeed-xdma.c line 736
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ ctx->queue_entry_size =XDMA_AST2600_QUEUE_ENTRY_SIZE ; + ctx->regs.bmc_cmdq_addr =XDMA_AST2600_BMC_CMDQ_ADDR ; + ctx->regs.bmc_cmdq_endp =XDMA_AST2600_BMC_CMDQ_ENDP ; + ctx->regs.bmc_cmdq_writep =XDMA_AST2600_BMC_CMDQ_WRITEP ; + ctx->regs.bmc_cmdq_readp =XDMA_AST2600_BMC_CMDQ_READP ; + ctx->regs.control =XDMA_AST2600_CTRL ; + ctx->regs.status =XDMA_AST2600_STATUS ; + ctx->status_bits.us_comp =XDMA_AST2600_STATUS_US_COMP ; + ctx->status_bits.ds_comp =XDMA_AST2600_STATUS_DS_COMP ; + ctx->status_bits.ds_dirty =XDMA_AST2600_STATUS_DS_DIRTY ;
Same query as above
Quoted 39 lines
drivers/soc/aspeed/aspeed-xdma.c new file +39
-0+break ; + }; + + ctx->dev = dev; +platform_set_drvdata (pdev, ctx); +mutex_init (&ctx->start_lock); +INIT_DELAYED_WORK (&ctx->reset_work, aspeed_xdma_reset_work); +spin_lock_init (&ctx->client_lock); +spin_lock_init (&ctx->reset_lock); +init_waitqueue_head (&ctx->wait); + + ctx->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (ctx->base)) { +dev_err (dev,"Unable to ioremap registers.\n" ); +return PTR_ERR (ctx->base); + } + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) { +dev_err (dev,"Unable to find IRQ.\n" ); +return -ENODEV ; + } + + rc =devm_request_irq (dev, irq, aspeed_xdma_irq,IRQF_SHARED , +DEVICE_NAME , ctx); +if (rc <0 ) { +dev_err (dev,"Unable to request IRQ %d.\n" , irq); +return rc; + } + + ctx->clock =devm_clk_get (dev,NULL ); +if (IS_ERR (ctx->clock)) { +dev_err (dev,"Unable to request clock.\n" ); +return PTR_ERR (ctx->clock); + } + + ctx->reset =devm_reset_control_get_exclusive (dev,NULL ); +if (IS_ERR (ctx->reset)) { +dev_err (dev,"Unable to request reset control.\n" );
drivers/soc/aspeed/aspeed-xdma.c line 785
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+return PTR_ERR (ctx->reset); + } + + ctx->vga_pool =devm_gen_pool_create (dev,ilog2 (PAGE_SIZE ),-1 ,NULL ); +if (!ctx->vga_pool) { +dev_err (dev,"Unable to setup genalloc pool.\n" ); +return -ENOMEM ; + } + +clk_prepare_enable (ctx->clock);
Check for errors
drivers/soc/aspeed/aspeed-xdma.c line 788
Quoted 3 lines
drivers/soc/aspeed/aspeed-xdma.c new file +3
-0+msleep (XDMA_RESET_TIME_MS ); + +reset_control_deassert (ctx->reset);
Check for errors.
Quoted 24 lines
drivers/soc/aspeed/aspeed-xdma.c new file +24
-0+msleep (XDMA_RESET_TIME_MS ); + + rc =aspeed_xdma_init (ctx); +if (rc) { +reset_control_assert (ctx->reset); +clk_disable_unprepare (ctx->clock); +return rc; + } + +aspeed_xdma_init_eng (ctx); + +/* +* This interrupt could fire immediately so only request it once the +* engine and driver are initialized. +*/ + pcie_irq =platform_get_irq (pdev,1 ); +if (pcie_irq <0 ) { +dev_warn (dev,"Unable to find PCI-E IRQ.\n" ); + }else { + rc =devm_request_irq (dev, pcie_irq, aspeed_xdma_pcie_irq, +IRQF_SHARED ,DEVICE_NAME , ctx); +if (rc <0 ) +dev_warn (dev,"Unable to request PCI-E IRQ %d.\n" , rc); + }
drivers/soc/aspeed/aspeed-xdma.c line 822
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ +return 0 ; +} + +static int aspeed_xdma_remove (struct platform_device *pdev) +{ +struct aspeed_xdma *ctx =platform_get_drvdata (pdev); + +gen_pool_free (ctx->vga_pool, (unsigned long )ctx->cmdq_vga_virt, +XDMA_CMDQ_SIZE );
You've used devm_gen_pool_create(), so no need to explicitly free it.
drivers/soc/aspeed/aspeed-xdma.c line 823
Quoted 1 line
drivers/soc/aspeed/aspeed-xdma.c new file +1
-0+iounmap (ctx->vga_virt);
This is unnecessary if we use devm_ioremap() as suggested above.
drivers/soc/aspeed/aspeed-xdma.c line 834
Quoted 11 lines
drivers/soc/aspeed/aspeed-xdma.c new file +11
-0+ +reset_control_assert (ctx->reset); +clk_disable_unprepare (ctx->clock); + +return 0 ; +} + +static const struct of_device_id aspeed_xdma_match[] = { + { + .compatible ="aspeed,ast2500-xdma" , + .data = (void *)xdma_ast2500,
I'd prefer you create a struct as discussed throughout.
Quoted 55 lines
drivers/soc/aspeed/aspeed-xdma.c new file +22
-0+ }, + { + .compatible = "aspeed,ast2600-xdma", + .data = (void *)xdma_ast2600, + }, + { }, +}; + +static struct platform_driver aspeed_xdma_driver = { + .probe = aspeed_xdma_probe, + .remove = aspeed_xdma_remove, + .driver = { + .name =DEVICE_NAME , + .of_match_table = aspeed_xdma_match, + }, +}; + +module_platform_driver (aspeed_xdma_driver); + +MODULE_AUTHOR ("Eddie James" ); +MODULE_DESCRIPTION ("Aspeed XDMA Engine Driver" ); +MODULE_LICENSE ("GPL v2" );include/uapi/linux/aspeed-xdma.h new file +27
-0@@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* Copyright IBM Corp 2019 */ + +#ifndef _UAPI_LINUX_ASPEED_XDMA_H_ +#define _UAPI_LINUX_ASPEED_XDMA_H_ + +#include <linux/types.h> + +/* +* aspeed_xdma_direction +* +* ASPEED_XDMA_DIRECTION_DOWNSTREAM: transfers data from the host to the BMC +* +* ASPEED_XDMA_DIRECTION_UPSTREAM: transfers data from the BMC to the host +* +* ASPEED_XDMA_DIRECTION_RESET: resets the XDMA engine +*/ +enum aspeed_xdma_direction { +ASPEED_XDMA_DIRECTION_DOWNSTREAM =0 , +ASPEED_XDMA_DIRECTION_UPSTREAM , +ASPEED_XDMA_DIRECTION_RESET , +}; + +/* +* aspeed_xdma_op +* +* host_addr: the DMA address on the host side, typically configured by PCI
include/uapi/linux/aspeed-xdma.h line 37
Quoted 10 lines
include/uapi/linux/aspeed-xdma.h new file +10
-0+* subsystem +* +* len: the size of the transfer in bytes +* +* direction: an enumerator indicating the direction of the DMA operation; see +* enum aspeed_xdma_direction +* +* bmc_addr: the virtual address to DMA on the BMC side; this parameter is +* unused on current platforms since the XDMA engine is restricted to +* accessing the VGA memory space
This doesn't make sense to me - if it's a virtual address then talking about the VGA space doesn't make sense to me as where the memory lives is an implementation detail. If the parameter is a physical address then it makes sense, but we'd always want it specified regardless?
Andrew
Quoted 16 lines
include/uapi/linux/aspeed-xdma.h new file +12
-0+* +* reserved: for natural alignment purposes only +*/ +struct aspeed_xdma_op { +__u64 host_addr; +__u32 len; +__u32 direction; +__u32 bmc_addr; +__u32 reserved; +}; + +#endif /* _UAPI_LINUX_ASPEED_XDMA_H_ */ Signature · 1 line
1.8.3.1
Re: [PATCH 07/12] drivers/soc: xdma: Add user interface
In reply to Eddie JamesQuoted 39 lines · Eddie James
This commits adds a miscdevice to provide a user interface to the XDMA engine. The interface provides the write operation to start DMA operations. The DMA parameters are passed as the data to the write call. The actual data to transfer is NOT passed through write. Note that both directions of DMA operation are accomplished through the write command; BMC to host and host to BMC.
The XDMA engine is restricted to only accessing the reserved memory space on the AST2500, typically used by the VGA. For this reason, the VGA memory space is pooled and allocated with genalloc. Users calling mmap allocate pages from this pool for their usage. The space allocated by a client will be the space used in the DMA operation. For an "upstream" (BMC to host) operation, the data in the client's area will be transferred to the host. For a "downstream" (host to BMC) operation, the host data will be placed in the client's memory area.
Poll is also provided in order to determine when the DMA operation is complete for non-blocking IO.
Signed-off-by Eddie James <[email protected]>--- drivers/soc/aspeed/aspeed-xdma.c | 223 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+)drivers/soc/aspeed/aspeed-xdma.c +3
-0@@ -64,6 +64,9 @@#define XDMA_CMDQ_SIZE PAGE_SIZE#define XDMA_NUM_CMDS \ (XDMA_CMDQ_SIZE / sizeof(struct aspeed_xdma_cmd)) +#define XDMA_OP_SIZE_MAX sizeof(struct aspeed_xdma_op) +#define XDMA_OP_SIZE_MIN \ + (sizeof(struct aspeed_xdma_op) - sizeof(u64))/* Aspeed specification requires 10ms after switching the reset line */ #define XDMA_RESET_TIME_MS 10
drivers/soc/aspeed/aspeed-xdma.c struct aspeed_xdma { · line 222
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c +1
-0@@ -216,6 +219,7 @@ struct aspeed_xdma {bool in_reset;bool upstream;unsigned int cmd_idx; +struct mutex file_lock;
Please add documentation about what data file_lock is protecting.
Quoted 22 lines
drivers/soc/aspeed/aspeed-xdma.c +7
-0struct mutex start_lock;struct delayed_work reset_work;spinlock_t client_lock;@@ -230,6 +234,8 @@ struct aspeed_xdma {dma_addr_t cmdq_vga_phys;void *cmdq_vga_virt;struct gen_pool *vga_pool; + +struct miscdevice misc; };struct aspeed_xdma_client {@@ -557,6 +563,204 @@ static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg)return IRQ_HANDLED ; } +static ssize_t aspeed_xdma_write (struct file *file,const char __user *buf, +size_t len,loff_t *offset) +{ +int rc; +struct aspeed_xdma_op op;
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, · line 581
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; +u32 offs = client->phys ? (client->phys - ctx->vga_phys) : +XDMA_CMDQ_SIZE ; + +if (len <XDMA_OP_SIZE_MIN ) +return -EINVAL ; + +if (len >XDMA_OP_SIZE_MAX ) + len =XDMA_OP_SIZE_MAX ;
Isn't this an EINVAL case as well?
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 586
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c +6
-0+ + rc =copy_from_user (&op, buf, len); +if (rc) +return rc; + +if (op.direction ==ASPEED_XDMA_DIRECTION_RESET ) {
Seems a bit abusive to use the direction field to issue a reset.
Quoted 13 lines
drivers/soc/aspeed/aspeed-xdma.c +13
-0+mutex_lock (&ctx->start_lock); + +if (aspeed_xdma_reset_start (ctx)) { +msleep (XDMA_RESET_TIME_MS ); + +aspeed_xdma_reset_finish (ctx); + } + +mutex_unlock (&ctx->start_lock); + +return len; + }else if (op.direction >ASPEED_XDMA_DIRECTION_RESET ) { +return -EINVAL ;
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 609
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+ } + +if (op.len > ctx->vga_size - offs) +return -EINVAL ; + +if (file->f_flags &O_NONBLOCK ) { +if (!mutex_trylock (&ctx->file_lock)) +return -EAGAIN ; + +if (ctx->in_progress || ctx->in_reset) {
ctx->in_progress was protected by a lock that isn't file_lock, so this looks wrong.
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 617
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c +8
-0+mutex_unlock (&ctx->file_lock); +return -EAGAIN ; + } + }else { +mutex_lock (&ctx->file_lock); + + rc =wait_event_interruptible (ctx->wait, !ctx->in_progress && + !ctx->in_reset);
As above.
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c +7
-0+if (rc) { +mutex_unlock (&ctx->file_lock); +return -EINTR ; + } + } + +aspeed_xdma_start (ctx, &op, ctx->vga_phys + offs, client);
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 634
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+ +mutex_unlock (&ctx->file_lock); + +if (!(file->f_flags &O_NONBLOCK )) { + rc =wait_event_interruptible (ctx->wait, !ctx->in_progress); +if (rc) +return -EINTR ; + +if (client->error) +return -EIO ;
What's the client->error value? Can it be more informative?
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 597
Quoted 3 lines
drivers/soc/aspeed/aspeed-xdma.c +3
-0+ } + +return len;
We've potentially truncated len above (in the len > XDMA_OP_SIZE_MAX), which leads to some ambiguity with the write() syscall given that it can potentially return less than the requested length. This is one such case, but the caller probably shouldn't attempt a follow-up write.
This would go away if we make the len > XDMA_OP_SIZE_MAX an EINVAL case as suggested agove.
Quoted 48 lines
drivers/soc/aspeed/aspeed-xdma.c +48
-0+} + +static __poll_t aspeed_xdma_poll (struct file *file, +struct poll_table_struct *wait) +{ +__poll_t mask =0 ; +__poll_t req =poll_requested_events (wait); +struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; + +if (req & (EPOLLIN |EPOLLRDNORM )) { +if (client->in_progress) +poll_wait (file, &ctx->wait, wait); + +if (!client->in_progress) { +if (client->error) + mask |=EPOLLERR ; +else + mask |=EPOLLIN |EPOLLRDNORM ; + } + } + +if (req & (EPOLLOUT |EPOLLWRNORM )) { +if (ctx->in_progress) +poll_wait (file, &ctx->wait, wait); + +if (!ctx->in_progress) + mask |=EPOLLOUT |EPOLLWRNORM ; + } + +return mask; +} + +static void aspeed_xdma_vma_close (struct vm_area_struct *vma) +{ +struct aspeed_xdma_client *client = vma->vm_private_data; + +gen_pool_free (client->ctx->vga_pool, (unsigned long )client->virt, + client->size); + + client->virt =NULL ; + client->phys =0 ; + client->size =0 ; +} + +static const struct vm_operations_struct aspeed_xdma_vm_ops = { + .close = aspeed_xdma_vma_close, +};
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 695
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+ +static int aspeed_xdma_mmap (struct file *file,struct vm_area_struct *vma) +{ +int rc; +struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; + +/* restrict file to one mapping */ +if (client->size) +return -ENOMEM ;
Can we do better with the error code here?
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 706
Quoted 11 lines
drivers/soc/aspeed/aspeed-xdma.c +11
-0+ + client->size = vma->vm_end - vma->vm_start; + client->virt =gen_pool_dma_alloc (ctx->vga_pool, client->size, + &client->phys); +if (!client->virt) { + client->phys =0 ; + client->size =0 ; +return -ENOMEM ; + } + + vma->vm_pgoff = (client->phys - ctx->vga_phys) >>PAGE_SHIFT ;
Where does client->phys get set?
Andrew
Re: [PATCH 06/12] drivers/soc: Add Aspeed XDMA Engine Driver
In reply to Andrew JefferyQuoted 9 lines
drivers/soc/aspeed/aspeed-xdma.c line 822
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+static int aspeed_xdma_remove (struct platform_device *pdev) +{ +struct aspeed_xdma *ctx =platform_get_drvdata (pdev); + +gen_pool_free (ctx->vga_pool, (unsigned long )ctx->cmdq_vga_virt, +XDMA_CMDQ_SIZE );You've used
devm_gen_pool_create(), so no need to explicitly free it.
Sorry, disregard that, brain-fart.
Andrew
Re: [PATCH 06/12] drivers/soc: Add Aspeed XDMA Engine Driver
In reply to Andrew JefferyQuoted 68 lines · Andrew Jeffery
Quoted 63 lines · Eddie James
The XDMA engine embedded in the AST2500 and AST2600 SOCs performs PCI DMA operations between the SOC (acting as a BMC) and a host processor in a server.
This commit adds a driver to control the XDMA engine and adds functions to initialize the hardware and memory and start DMA operations.
Signed-off-by Eddie James <[email protected]>--- MAINTAINERS | 2 + drivers/soc/aspeed/Kconfig | 8 + drivers/soc/aspeed/Makefile | 1 + drivers/soc/aspeed/aspeed-xdma.c | 856 +++++++++++++++++++++++++++++++++++++++ include/uapi/linux/aspeed-xdma.h | 49 +++ 5 files changed, 916 insertions(+)create mode 100644
drivers/soc/aspeed/aspeed-xdma.ccreate mode 100644include/uapi/linux/aspeed-xdma.hMAINTAINERS +2
-0@@ -2696,6 +2696,8 @@ M: Eddie James <[email protected]> L: linux-aspeed at lists.ozlabs.org (moderated for non-subscribers) S: Maintained F: Documentation/devicetree/bindings/soc/aspeed/xdma.txt +F: drivers/soc/aspeed/aspeed-xdma.c +F: include/uapi/linux/aspeed-xdma.h ASUS NOTEBOOKS AND EEEPC ACPI/WMI EXTRAS DRIVERS M: Corentin Chary <[email protected]>drivers/soc/aspeed/Kconfig +8
-0@@ -29,4 +29,12 @@ config ASPEED_P2A_CTRL ioctl()s, the driver also provides an interface for userspace mappings to a pre-defined region. +config ASPEED_XDMA + tristate "Aspeed XDMA Engine Driver" + depends on SOC_ASPEED && REGMAP && MFD_SYSCON && HAS_DMA + help + Enable support for the Aspeed XDMA Engine found on the Aspeed AST2XXX + SOCs. The XDMA engine can perform automatic PCI DMA operations + between the AST2XXX (acting as a BMC) and a host processor. + endmenudrivers/soc/aspeed/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_ASPEED_LPC_CTRL) += aspeed-lpc-ctrl.o obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o obj-$(CONFIG_ASPEED_P2A_CTRL) += aspeed-p2a-ctrl.o +obj-$(CONFIG_ASPEED_XDMA) += aspeed-xdma.odrivers/soc/aspeed/aspeed-xdma.c new file +0
-0drivers/soc/aspeed/aspeed-xdma.c line 1
Quoted 1 line
drivers/soc/aspeed/aspeed-xdma.c new file +1
-0@@ -0,0 +1,856 @@ +// SPDX-License-Identifier: GPL-2.0+ This should be "GPL-2.0-or-later" (https://spdx.org/licenses/)
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c line 4
Quoted 3 lines
drivers/soc/aspeed/aspeed-xdma.c new file +3
-0+// Copyright IBM Corp 2019 + +#include <linux/aspeed-xdma.h> A device-specific header in this include path seems a little strange to me.
It's under uapi... do I need to specify a different path?
Quoted 55 lines
Quoted 22 lines
drivers/soc/aspeed/aspeed-xdma.c new file +21
-0+#include <linux/bitfield.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/fs.h> +#include <linux/genalloc.h> +#include <linux/interrupt.h> +#include <linux/jiffies.h> +#include <linux/mfd/syscon.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/poll.h> +#include <linux/regmap.h> +#include <linux/reset.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/string.h> drivers/soc/aspeed/aspeed-xdma.c line 35
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+#include <linux/uaccess.h> +#include <linux/wait.h> +#include <linux/workqueue.h> + +#define DEVICE_NAME "aspeed-xdma" + +#define SCU_AST2500_STRAP 0x070 +#define SCU_AST2500_STRAP_VGA_MEM GENMASK(3, 2) +#define SCU_AST2600_STRAP 0x500 +#define SCU_AST2600_STRAP_VGA_MEM GENMASK(14, 13)It could be easier to review if you add support for one SoC at a time.
Quoted 21 lines
drivers/soc/aspeed/aspeed-xdma.c new file +21
-0+ +#define SCU_AST2500_PCIE_CONF 0x180 +#define SCU_AST2600_PCIE_CONF 0xc20 +#define SCU_PCIE_CONF_VGA_EN BIT(0) +#define SCU_PCIE_CONF_VGA_EN_MMIO BIT(1) +#define SCU_PCIE_CONF_VGA_EN_LPC BIT(2) +#define SCU_PCIE_CONF_VGA_EN_MSI BIT(3) +#define SCU_PCIE_CONF_VGA_EN_MCTP BIT(4) +#define SCU_PCIE_CONF_VGA_EN_IRQ BIT(5) +#define SCU_PCIE_CONF_VGA_EN_DMA BIT(6) +#define SCU_PCIE_CONF_BMC_EN BIT(8) +#define SCU_PCIE_CONF_BMC_EN_MMIO BIT(9) +#define SCU_PCIE_CONF_BMC_EN_MSI BIT(11) +#define SCU_PCIE_CONF_BMC_EN_MCTP BIT(12) +#define SCU_PCIE_CONF_BMC_EN_IRQ BIT(13) +#define SCU_PCIE_CONF_BMC_EN_DMA BIT(14) + +#define SCU_AST2500_BMC_CLASS_REV 0x19c +#define SCU_AST2600_BMC_CLASS_REV 0xc4c +#define SCU_BMC_CLASS_REV_XDMA 0xff000001 +
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 62
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+#define SDMC_BASE 0x1e6e0000 +#define SDMC_CONF 0x004 +#define SDMC_CONF_MEM GENMASK(1, 0) +#define SDMC_REMAP 0x008 +#define SDMC_AST2500_REMAP_MAGIC (BIT(16) | BIT(17)) +#define SDMC_AST2600_REMAP_MAGIC BIT(18)Can we have something more descriptive than "MAGIC"? What these bits are doing is well documented and defined.
Maybe I missed it then... I wasn't able to correspond these necessary bits to what is actually happening. The doc indicates it remaps "REQs" to the highest memory space. What do the REQs correspond to, and why is it these bits for these SOCs?
Quoted 46 lines
Quoted 46 lines
drivers/soc/aspeed/aspeed-xdma.c new file +45
-0+ +#define XDMA_CMDQ_SIZE PAGE_SIZE +#define XDMA_NUM_CMDS \ + (XDMA_CMDQ_SIZE / sizeof(struct aspeed_xdma_cmd)) + +/* Aspeed specification requires 10ms after switching the reset line */ +#define XDMA_RESET_TIME_MS 10 + +#define XDMA_DS_PCIE_REQ_SIZE_128 0 +#define XDMA_DS_PCIE_REQ_SIZE_256 1 +#define XDMA_DS_PCIE_REQ_SIZE_512 2 +#define XDMA_DS_PCIE_REQ_SIZE_1K 3 +#define XDMA_DS_PCIE_REQ_SIZE_2K 4 +#define XDMA_DS_PCIE_REQ_SIZE_4K 5 + +#define XDMA_CMD_AST2500_PITCH_SHIFT 3 +#define XDMA_CMD_AST2500_PITCH_BMC GENMASK_ULL(62, 51) +#define XDMA_CMD_AST2500_PITCH_HOST GENMASK_ULL(46, 35) +#define XDMA_CMD_AST2500_PITCH_UPSTREAM BIT_ULL(31) +#define XDMA_CMD_AST2500_PITCH_ADDR GENMASK_ULL(29, 4) +#define XDMA_CMD_AST2500_PITCH_ID BIT_ULL(0) +#define XDMA_CMD_AST2500_CMD_IRQ_EN BIT_ULL(31) +#define XDMA_CMD_AST2500_CMD_LINE_NO GENMASK_ULL(27, 16) +#define XDMA_CMD_AST2500_CMD_IRQ_BMC BIT_ULL(15) +#define XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT 4 +#define XDMA_CMD_AST2500_CMD_LINE_SIZE \ + GENMASK_ULL(14, XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT) +#define XDMA_CMD_AST2500_CMD_ID BIT_ULL(1) + +#define XDMA_CMD_AST2600_PITCH_BMC GENMASK_ULL(62, 48) +#define XDMA_CMD_AST2600_PITCH_HOST GENMASK_ULL(46, 32) +#define XDMA_CMD_AST2600_PITCH_ADDR GENMASK_ULL(30, 0) +#define XDMA_CMD_AST2600_CMD_64_EN BIT_ULL(40) +#define XDMA_CMD_AST2600_CMD_IRQ_BMC BIT_ULL(37) +#define XDMA_CMD_AST2600_CMD_IRQ_HOST BIT_ULL(36) +#define XDMA_CMD_AST2600_CMD_UPSTREAM BIT_ULL(32) +#define XDMA_CMD_AST2600_CMD_LINE_NO GENMASK_ULL(27, 16) +#define XDMA_CMD_AST2600_CMD_LINE_SIZE GENMASK_ULL(14, 0) +#define XDMA_CMD_AST2600_CMD_MULTILINE_SIZE GENMASK_ULL(14, 12) + +#define XDMA_AST2500_QUEUE_ENTRY_SIZE 4 +#define XDMA_AST2500_HOST_CMDQ_ADDR0 0x00 +#define XDMA_AST2500_HOST_CMDQ_ENDP 0x04 +#define XDMA_AST2500_HOST_CMDQ_WRITEP 0x08 +#define XDMA_AST2500_HOST_CMDQ_READP 0x0c
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 112
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c new file +5
-0+#define XDMA_AST2500_BMC_CMDQ_ADDR 0x10 +#define XDMA_AST2500_BMC_CMDQ_ENDP 0x14 +#define XDMA_AST2500_BMC_CMDQ_WRITEP 0x18 +#define XDMA_AST2500_BMC_CMDQ_READP 0x1c +#define XDMA_BMC_CMDQ_READP_MAGIC 0xee882266What's this about? Using a macro to abstract a magic number and then using the word "magic" in the name isn't very helpful. I think it should be renamed or documented, or both.
Sure. It's the value to write to reset the read pointer.
Quoted 106 lines
Quoted 106 lines
drivers/soc/aspeed/aspeed-xdma.c new file +105
-0+#define XDMA_AST2500_CTRL 0x20 +#define XDMA_AST2500_CTRL_US_COMP BIT(4) +#define XDMA_AST2500_CTRL_DS_COMP BIT(5) +#define XDMA_AST2500_CTRL_DS_DIRTY BIT(6) +#define XDMA_AST2500_CTRL_DS_SIZE GENMASK(19, 17) +#define XDMA_AST2500_CTRL_DS_TIMEOUT BIT(28) +#define XDMA_AST2500_CTRL_DS_CHECK_ID BIT(29) +#define XDMA_AST2500_STATUS 0x24 +#define XDMA_AST2500_STATUS_US_COMP BIT(4) +#define XDMA_AST2500_STATUS_DS_COMP BIT(5) +#define XDMA_AST2500_STATUS_DS_DIRTY BIT(6) +#define XDMA_AST2500_INPRG_DS_CMD1 0x38 +#define XDMA_AST2500_INPRG_DS_CMD2 0x3c +#define XDMA_AST2500_INPRG_US_CMD00 0x40 +#define XDMA_AST2500_INPRG_US_CMD01 0x44 +#define XDMA_AST2500_INPRG_US_CMD10 0x48 +#define XDMA_AST2500_INPRG_US_CMD11 0x4c +#define XDMA_AST2500_INPRG_US_CMD20 0x50 +#define XDMA_AST2500_INPRG_US_CMD21 0x54 +#define XDMA_AST2500_HOST_CMDQ_ADDR1 0x60 +#define XDMA_AST2500_VGA_CMDQ_ADDR0 0x64 +#define XDMA_AST2500_VGA_CMDQ_ENDP 0x68 +#define XDMA_AST2500_VGA_CMDQ_WRITEP 0x6c +#define XDMA_AST2500_VGA_CMDQ_READP 0x70 +#define XDMA_AST2500_VGA_CMD_STATUS 0x74 +#define XDMA_AST2500_VGA_CMDQ_ADDR1 0x78 + +#define XDMA_AST2600_QUEUE_ENTRY_SIZE 2 +#define XDMA_AST2600_HOST_CMDQ_ADDR0 0x00 +#define XDMA_AST2600_HOST_CMDQ_ADDR1 0x04 +#define XDMA_AST2600_HOST_CMDQ_ENDP 0x08 +#define XDMA_AST2600_HOST_CMDQ_WRITEP 0x0c +#define XDMA_AST2600_HOST_CMDQ_READP 0x10 +#define XDMA_AST2600_BMC_CMDQ_ADDR 0x14 +#define XDMA_AST2600_BMC_CMDQ_ENDP 0x18 +#define XDMA_AST2600_BMC_CMDQ_WRITEP 0x1c +#define XDMA_AST2600_BMC_CMDQ_READP 0x20 +#define XDMA_AST2600_VGA_CMDQ_ADDR0 0x24 +#define XDMA_AST2600_VGA_CMDQ_ADDR1 0x28 +#define XDMA_AST2600_VGA_CMDQ_ENDP 0x2c +#define XDMA_AST2600_VGA_CMDQ_WRITEP 0x30 +#define XDMA_AST2600_VGA_CMDQ_READP 0x34 +#define XDMA_AST2600_CTRL 0x38 +#define XDMA_AST2600_CTRL_US_COMP BIT(16) +#define XDMA_AST2600_CTRL_DS_COMP BIT(17) +#define XDMA_AST2600_CTRL_DS_DIRTY BIT(18) +#define XDMA_AST2600_CTRL_DS_SIZE GENMASK(22, 20) +#define XDMA_AST2600_STATUS 0x3c +#define XDMA_AST2600_STATUS_US_COMP BIT(16) +#define XDMA_AST2600_STATUS_DS_COMP BIT(17) +#define XDMA_AST2600_STATUS_DS_DIRTY BIT(18) +#define XDMA_AST2600_INPRG_DS_CMD00 0x40 +#define XDMA_AST2600_INPRG_DS_CMD01 0x44 +#define XDMA_AST2600_INPRG_DS_CMD10 0x48 +#define XDMA_AST2600_INPRG_DS_CMD11 0x4c +#define XDMA_AST2600_INPRG_DS_CMD20 0x50 +#define XDMA_AST2600_INPRG_DS_CMD21 0x54 +#define XDMA_AST2600_INPRG_US_CMD00 0x60 +#define XDMA_AST2600_INPRG_US_CMD01 0x64 +#define XDMA_AST2600_INPRG_US_CMD10 0x68 +#define XDMA_AST2600_INPRG_US_CMD11 0x6c +#define XDMA_AST2600_INPRG_US_CMD20 0x70 +#define XDMA_AST2600_INPRG_US_CMD21 0x74 + +enum versions { xdma_ast2500, xdma_ast2600 }; + +struct aspeed_xdma_cmd { +u64 host_addr; +u64 pitch; +u64 cmd; +u64 reserved; +}; + +struct aspeed_xdma_regs { +u8 bmc_cmdq_addr; +u8 bmc_cmdq_endp; +u8 bmc_cmdq_writep; +u8 bmc_cmdq_readp; +u8 control; +u8 status; +}; + +struct aspeed_xdma_status_bits { +u32 us_comp; +u32 ds_comp; +u32 ds_dirty; +}; + +struct aspeed_xdma_client ; + +struct aspeed_xdma { +enum versions version; +u32 control; +unsigned int queue_entry_size; +struct aspeed_xdma_regs regs; +struct aspeed_xdma_status_bits status_bits; + +struct device *dev; +void __iomem *base; +struct clk *clock; +struct reset_control *reset; + +bool in_progress; +bool in_reset; +bool upstream;
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 222
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c new file +5
-0+unsigned int cmd_idx; +struct mutex start_lock; +struct delayed_work reset_work; +spinlock_t client_lock; +spinlock_t reset_lock;What data are each of these locks protecting? Please add documentation about how you intend to use them. Try to group the locks with the data they protect if this is not already the case.
Sure, though I feel the names are fairly descriptive.
Quoted 29 lines
Quoted 29 lines
drivers/soc/aspeed/aspeed-xdma.c new file +28
-0+wait_queue_head_t wait; +struct aspeed_xdma_client *current_client; + +u32 vga_phys; +u32 vga_size; +void *cmdq; +void __iomem *vga_virt; +dma_addr_t cmdq_vga_phys; +void *cmdq_vga_virt; +struct gen_pool *vga_pool; +}; + +struct aspeed_xdma_client { +struct aspeed_xdma *ctx; + +bool error; +bool in_progress; +void *virt; +dma_addr_t phys; +u32 size; +}; + +static u32 aspeed_xdma_readl (struct aspeed_xdma *ctx,u8 reg) +{ +u32 v =readl (ctx->base + reg); + +dev_dbg (ctx->dev,"read %02x[%08x]\n" , reg, v); +return v;
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 256
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+} + +static void aspeed_xdma_writel (struct aspeed_xdma *ctx,u8 reg,u32 val) +{ +writel (val, ctx->base + reg); +dev_dbg (ctx->dev,"write %02x[%08x]\n" , reg,readl (ctx->base + reg));That
readl()seems a bit paranoid, and is probably evaluated whether or not thisdev_dbg()is enabled. What drove this approach?
There is some tricky masking of writes of many of the engine registers, so it was helpful to see what the actual result is. I could drop it.
Quoted 41 lines
Quoted 41 lines
drivers/soc/aspeed/aspeed-xdma.c new file +40
-0+} + +static void aspeed_xdma_init_eng (struct aspeed_xdma *ctx) +{ +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_endp, + ctx->queue_entry_size *XDMA_NUM_CMDS ); +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_readp, +XDMA_BMC_CMDQ_READP_MAGIC ); +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_writep,0 ); +aspeed_xdma_writel (ctx, ctx->regs.control, ctx->control); +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_addr, ctx->cmdq_vga_phys); + + ctx->cmd_idx =0 ; + ctx->in_progress = false; +} + +static unsigned int aspeed_xdma_ast2500_set_cmd (struct aspeed_xdma *ctx, +struct aspeed_xdma_op *op, +u32 bmc_addr) +{ +u64 cmd =XDMA_CMD_AST2500_CMD_IRQ_EN |XDMA_CMD_AST2500_CMD_IRQ_BMC | +XDMA_CMD_AST2500_CMD_ID ; +u64 cmd_pitch = (op->direction ?XDMA_CMD_AST2500_PITCH_UPSTREAM :0 ) | +XDMA_CMD_AST2500_PITCH_ID ; +unsigned int line_size; +unsigned int nidx = (ctx->cmd_idx +1 ) %XDMA_NUM_CMDS ; +unsigned int line_no =1 ; +unsigned int pitch =1 ; +struct aspeed_xdma_cmd *ncmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[ctx->cmd_idx]); + +dev_dbg (ctx->dev,"xdma %s ast2500: bmc[%08x] len[%08x] host[%08x]\n" , + op->direction ?"upstream" :"downstream" , bmc_addr, op->len, + (u32 )op->host_addr); + +if (op->len >XDMA_CMD_AST2500_CMD_LINE_SIZE ) { +unsigned int rem; +unsigned int total; + + line_no = op->len /XDMA_CMD_AST2500_CMD_LINE_SIZE ;
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 302
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+ total =XDMA_CMD_AST2500_CMD_LINE_SIZE * line_no; + rem = (op->len - total) >> +XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT ; + line_size =XDMA_CMD_AST2500_CMD_LINE_SIZE ; + pitch = line_size >>XDMA_CMD_AST2500_PITCH_SHIFT ; + line_size >>=XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT ;Can we clean up the configuration of
line_sizeand pitch here? They are set to constants in this case.
I think this is as clean as it gets. They're used later on so unless I have more if statements it makes sense to set them here.
Quoted 123 lines
Quoted 123 lines
drivers/soc/aspeed/aspeed-xdma.c new file +122
-0+ +if (rem) { +u32 rbmc = bmc_addr + total; +struct aspeed_xdma_cmd *rcmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[nidx]); + + rcmd->host_addr = op->host_addr + (u64 )total; + rcmd->pitch = cmd_pitch | + ((u64 )rbmc &XDMA_CMD_AST2500_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_HOST ,1 ) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_BMC ,1 ); + rcmd->cmd = cmd | +FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_NO ,1 ) | +FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_SIZE , + rem); + +print_hex_dump_debug ("xdma rem" ,DUMP_PREFIX_OFFSET , +16 ,1 , rcmd,sizeof (*rcmd), true); + + cmd &= ~(XDMA_CMD_AST2500_CMD_IRQ_EN | +XDMA_CMD_AST2500_CMD_IRQ_BMC ); + + nidx = (nidx +1 ) %XDMA_NUM_CMDS ; + } + }else { + line_size = op->len >>XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT ; + } + + ncmd->host_addr = op->host_addr; + ncmd->pitch = cmd_pitch | + ((u64 )bmc_addr &XDMA_CMD_AST2500_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_HOST , pitch) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_BMC , pitch); + ncmd->cmd = cmd |FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_NO , line_no) | +FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_SIZE , line_size); + +print_hex_dump_debug ("xdma cmd" ,DUMP_PREFIX_OFFSET ,16 ,1 , ncmd, +sizeof (*ncmd), true); + +return nidx; +} + +static unsigned int aspeed_xdma_ast2600_set_cmd (struct aspeed_xdma *ctx, +struct aspeed_xdma_op *op, +u32 bmc_addr) +{ +u64 cmd =XDMA_CMD_AST2600_CMD_IRQ_BMC | + (op->direction ?XDMA_CMD_AST2600_CMD_UPSTREAM :0 ); +unsigned int line_size; +unsigned int nidx = (ctx->cmd_idx +1 ) %XDMA_NUM_CMDS ; +unsigned int line_no =1 ; +unsigned int pitch =1 ; +struct aspeed_xdma_cmd *ncmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[ctx->cmd_idx]); + +if ((op->host_addr + op->len) &0xffffffff00000000ULL ) + cmd |=XDMA_CMD_AST2600_CMD_64_EN ; + +dev_dbg (ctx->dev,"xdma %s ast2600: bmc[%08x] len[%08x] " +"host[%016llx]\n" , op->direction ?"upstream" :"downstream" , + bmc_addr, op->len, op->host_addr); + +if (op->len >XDMA_CMD_AST2600_CMD_LINE_SIZE ) { +unsigned int rem; +unsigned int total; + + line_no = op->len /XDMA_CMD_AST2600_CMD_MULTILINE_SIZE ; + total =XDMA_CMD_AST2600_CMD_MULTILINE_SIZE * line_no; + rem = op->len - total; + line_size =XDMA_CMD_AST2600_CMD_MULTILINE_SIZE ; + pitch = line_size; + +if (rem) { +u32 rbmc = bmc_addr + total; +struct aspeed_xdma_cmd *rcmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[nidx]); + + rcmd->host_addr = op->host_addr + (u64 )total; + rcmd->pitch = + ((u64 )rbmc &XDMA_CMD_AST2600_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_HOST ,1 ) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_BMC ,1 ); + rcmd->cmd = cmd | +FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_NO ,1 ) | +FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_SIZE , + rem); + +print_hex_dump_debug ("xdma rem" ,DUMP_PREFIX_OFFSET , +16 ,1 , rcmd,sizeof (*rcmd), true); + + cmd &= ~XDMA_CMD_AST2600_CMD_IRQ_BMC ; + + nidx = (nidx +1 ) %XDMA_NUM_CMDS ; + } + }else { + line_size = op->len; + } + + ncmd->host_addr = op->host_addr; + ncmd->pitch = ((u64 )bmc_addr &XDMA_CMD_AST2600_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_HOST , pitch) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_BMC , pitch); + ncmd->cmd = cmd |FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_NO , line_no) | +FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_SIZE , line_size); + +print_hex_dump_debug ("xdma cmd" ,DUMP_PREFIX_OFFSET ,16 ,1 , ncmd, +sizeof (*ncmd), true); + +return nidx; +} + +static void aspeed_xdma_start (struct aspeed_xdma *ctx, +struct aspeed_xdma_op *op,u32 bmc_addr, +struct aspeed_xdma_client *client) +{ +unsigned int nidx; + +mutex_lock (&ctx->start_lock); + +switch (ctx->version) { +default : +case xdma_ast2500:
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 430
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+ nidx =aspeed_xdma_ast2500_set_cmd (ctx, op, bmc_addr); +break ; +case xdma_ast2600: + nidx =aspeed_xdma_ast2600_set_cmd (ctx, op, bmc_addr); +break ; + }What was the trade-off between the enum and function pointers? Is the enum approach strictly better for some reason?
No, I just decided to go with the switch.
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c line 437
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+ +memcpy (ctx->cmdq_vga_virt, ctx->cmdq,XDMA_CMDQ_SIZE ); + + client->in_progress = true; + ctx->current_client = client; + + ctx->in_progress = true;Do we need
ctx->in_progressvs just using the NULL state ofctx->current_client? Is it possible forctx->current_clientto be set and not have a transfer in progress?
Good point, could probably drop that.
Quoted 18 lines
Quoted 18 lines
drivers/soc/aspeed/aspeed-xdma.c new file +17
-0+ ctx->upstream = op->direction ? true : false; + +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_writep, + nidx * ctx->queue_entry_size); + + ctx->cmd_idx = nidx; + +mutex_unlock (&ctx->start_lock); +} + +static void aspeed_xdma_done (struct aspeed_xdma *ctx,bool error) +{ +unsigned long flags; + +/* +* Lock to make sure simultaneous reset and transfer complete don't +* leave the client with the wrong error state.
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 458
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c new file +4
-0+*/ +spin_lock_irqsave (&ctx->client_lock, flags); + +if (ctx->current_client) {You're testing
ctx->current_clientunderctx->client_lockhere, butctx->current_clientis set underctx->start_lockinaspeed_xdma_start(), which does not takectx->client_lock. What data is protected byctx->client_lock? What data is protected byctx->client_lock?
client_lock is making sure the client.error and ctx.current_client are updated atomically, as indicated by the comment. It's impossible to be starting a transfer at the same time, since ctx.in_progress would be true.
Quoted 12 lines
drivers/soc/aspeed/aspeed-xdma.c line 466
Quoted 9 lines
drivers/soc/aspeed/aspeed-xdma.c new file +8
-0+ ctx->current_client->error = error; + ctx->current_client->in_progress = false; + ctx->current_client =NULL ; + } + +spin_unlock_irqrestore (&ctx->client_lock, flags); + + ctx->in_progress = false;You set
ctx->in_progressunderctx->start_lockinaspeed_xdma_start()but you do not takectx->start_lockwhen setting it here. What data isctx->start_lockprotecting?
start_lock is making sure that the hardware register state, command queue, and data associated with the current transfer are updated atomically in the start function. It shouldn't be necessary to lock just to reset in_progress
Quoted 51 lines
Quoted 51 lines
drivers/soc/aspeed/aspeed-xdma.c new file +50
-0+wake_up_interruptible_all (&ctx->wait); +} + +static irqreturn_t aspeed_xdma_irq (int irq,void *arg) +{ +struct aspeed_xdma *ctx = arg; +u32 status =aspeed_xdma_readl (ctx, ctx->regs.status); + +if (status & ctx->status_bits.ds_dirty) { +aspeed_xdma_done (ctx, true); + }else { +if (status & ctx->status_bits.us_comp) { +if (ctx->upstream) +aspeed_xdma_done (ctx, false); + } + +if (status & ctx->status_bits.ds_comp) { +if (!ctx->upstream) +aspeed_xdma_done (ctx, false); + } + } + +aspeed_xdma_writel (ctx, ctx->regs.status, status); + +return IRQ_HANDLED ; +} + +static void aspeed_xdma_reset_finish (struct aspeed_xdma *ctx) +{ +unsigned long flags; + +spin_lock_irqsave (&ctx->reset_lock, flags); + + ctx->in_reset = false; +reset_control_deassert (ctx->reset); + +spin_unlock_irqrestore (&ctx->reset_lock, flags); + +msleep (XDMA_RESET_TIME_MS ); + +aspeed_xdma_init_eng (ctx); +aspeed_xdma_done (ctx, true); +} + +static bool aspeed_xdma_reset_start (struct aspeed_xdma *ctx) +{ +bool rc = true; +unsigned long flags; + +spin_lock_irqsave (&ctx->reset_lock, flags);
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 523
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+ +if (ctx->in_reset) { + rc = false; + }else { + ctx->in_reset = true; +reset_control_assert (ctx->reset); + }Do start and finish need to be split in this way?
Yes, in order to prevent waiting for 10ms in interrupt context during the reset.
Quoted 10 lines
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +9
-0+ +spin_unlock_irqrestore (&ctx->reset_lock, flags); + +return rc; +} + +static void aspeed_xdma_reset_work (struct work_struct *work) +{ +struct delayed_work *dwork =to_delayed_work (work);
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 538
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+ struct aspeed_xdma *ctx = container_of(dwork, struct aspeed_xdma, + reset_work); + +/* +* Lock to make sure operations aren't started while the engine is +* in an undefined state coming out of reset and waiting to init. Shouldn't we be holding it across both
aspeed_xdma_reset_start()andaspeed_xdma_reset_finish()?
No, it isn't necessary and also start_lock is a mutex which can't be locked in interrupt context. It isn't necessary because a reset before, during, or after starting a transfer will simply cause the transfer to do nothing until the reset completes, when it will be put into an error state.
Quoted 29 lines
Quoted 29 lines
drivers/soc/aspeed/aspeed-xdma.c new file +28
-0+*/ +mutex_lock (&ctx->start_lock); + +aspeed_xdma_reset_finish (ctx); + +mutex_unlock (&ctx->start_lock); +} + +static irqreturn_t aspeed_xdma_pcie_irq (int irq,void *arg) +{ +struct aspeed_xdma *ctx = arg; + +dev_dbg (ctx->dev,"pcie reset\n" ); + +if (aspeed_xdma_reset_start (ctx)) +schedule_delayed_work (&ctx->reset_work, +msecs_to_jiffies (XDMA_RESET_TIME_MS )); + +return IRQ_HANDLED ; +} + +static int aspeed_xdma_init (struct aspeed_xdma *ctx) +{ +int rc; +struct regmap *scu; +u32 conf; +u32 mem_size; +u32 remap;
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+u32 scu_bmc_class; +u32 scu_pcie_conf; +u32 scu_strap; +u32 sdmc_remap_magic; +u32 strap =0 ; +const u32 bmc =SCU_PCIE_CONF_BMC_EN |SCU_PCIE_CONF_BMC_EN_MSI | +SCU_PCIE_CONF_BMC_EN_MCTP Do we need MCTP here?
I don't know, I used the default value which has MCTP enabled.
Quoted 96 lines
|
SCU_PCIE_CONF_BMC_EN_IRQ|drivers/soc/aspeed/aspeed-xdma.c
Quoted 3 lines
drivers/soc/aspeed/aspeed-xdma.c new file +3
-0+SCU_PCIE_CONF_BMC_EN_DMA ; +const u32 vga =SCU_PCIE_CONF_VGA_EN |SCU_PCIE_CONF_VGA_EN_MSI | +SCU_PCIE_CONF_VGA_EN_MCTP Do we need MCTP here?
|
SCU_PCIE_CONF_VGA_EN_IRQ|drivers/soc/aspeed/aspeed-xdma.c line 580
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c new file +4
-0+SCU_PCIE_CONF_VGA_EN_DMA ; +u32 mem_sizes[4 ] = {0x8000000 ,0x10000000 ,0x20000000 ,0x40000000 }; +const u32 vga_sizes[4 ] = {0x800000 ,0x1000000 ,0x2000000 ,0x4000000 }; +void __iomem *sdmc_base =ioremap (SDMC_BASE ,0x100 );Surely this should be a phandle from the devicetree? And what about conflicts with a potential SDMC driver? I don't think what you have is the right approach.
drivers/soc/aspeed/aspeed-xdma.c line 593
Quoted 13 lines
drivers/soc/aspeed/aspeed-xdma.c new file +13
-0+ +if (!sdmc_base) { +dev_err (ctx->dev,"Failed to ioremap mem controller regs.\n" ); +return -ENOMEM ; + } + +switch (ctx->version) { +default : +case xdma_ast2500: + scu_bmc_class =SCU_AST2500_BMC_CLASS_REV ; + scu_pcie_conf =SCU_AST2500_PCIE_CONF ; + scu_strap =SCU_AST2500_STRAP ; + sdmc_remap_magic =SDMC_AST2500_REMAP_MAGIC ;Can't this be described statically? The values should be derived from the devicetree compatible.
drivers/soc/aspeed/aspeed-xdma.c line 595
Quoted 2 lines
drivers/soc/aspeed/aspeed-xdma.c new file +2
-0+ + scu =syscon_regmap_lookup_by_compatible ("aspeed,ast2500-scu" );I think we should do this via phandle in the devicetree.
drivers/soc/aspeed/aspeed-xdma.c line 601
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+break ; +case xdma_ast2600: + scu_bmc_class =SCU_AST2600_BMC_CLASS_REV ; + scu_pcie_conf =SCU_AST2600_PCIE_CONF ; + scu_strap =SCU_AST2600_STRAP ; + sdmc_remap_magic =SDMC_AST2600_REMAP_MAGIC ;Can't this be described statically? The values should be derived from the devicetree compatible.
drivers/soc/aspeed/aspeed-xdma.c line 606
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c new file +5
-0+ + mem_sizes[0 ] *=2 ; + mem_sizes[1 ] *=2 ; + mem_sizes[2 ] *=2 ; + mem_sizes[3 ] *=2 ;Same query as above.
drivers/soc/aspeed/aspeed-xdma.c line 608
Quoted 2 lines
drivers/soc/aspeed/aspeed-xdma.c new file +2
-0+ + scu =syscon_regmap_lookup_by_compatible ("aspeed,ast2600-scu" );I think we should do this via phandle in the devicetree.
drivers/soc/aspeed/aspeed-xdma.c line 619
Quoted 11 lines
drivers/soc/aspeed/aspeed-xdma.c new file +11
-0+break ; + }; + +if (!scu) { +dev_err (ctx->dev,"Failed to grab SCU regs.\n" ); +return -ENOMEM ; + } + +/* Set SOC to use the BMC PCIe device and set the device class code */ +regmap_update_bits (scu, scu_pcie_conf, bmc | vga, bmc); +regmap_write (scu, scu_bmc_class,SCU_BMC_CLASS_REV_XDMA );This should be selectable, probably via the devicetree.
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+ +/* +* Calculate the VGA memory size and physical address from the SCU and +* memory controller registers. +*/ +regmap_read (scu, scu_strap, &strap);drivers/soc/aspeed/aspeed-xdma.c line 635
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ +switch (ctx->version) { +case xdma_ast2500: + ctx->vga_size = vga_sizes[FIELD_GET (SCU_AST2500_STRAP_VGA_MEM , + strap)]; +break ; +case xdma_ast2600: + ctx->vga_size = vga_sizes[FIELD_GET (SCU_AST2600_STRAP_VGA_MEM , + strap)]; +break ;Can't this be described statically? The values should be derived from the devicetree compatible.
drivers/soc/aspeed/aspeed-xdma.c line 642
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+ } + + conf =readl (sdmc_base +SDMC_CONF ); + remap =readl (sdmc_base +SDMC_REMAP ); + remap |= sdmc_remap_magic; +writel (remap, sdmc_base +SDMC_REMAP ); + mem_size = mem_sizes[conf &SDMC_CONF_MEM ];See previous objection to this.
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c line 646
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c new file +4
-0+ +iounmap (sdmc_base); + + ctx->vga_phys = (mem_size - ctx->vga_size) +0x80000000 ;RAM base should be extracted from the devicetree. Better yet, the VGA space should be extracted from the devicetree and this calculation avoided altogether.
Ok, I'll use the devicetree for all this instead.
Quoted 20 lines
drivers/soc/aspeed/aspeed-xdma.c line 654
Quoted 9 lines
drivers/soc/aspeed/aspeed-xdma.c new file +8
-0+ + ctx->cmdq =devm_kzalloc (ctx->dev,XDMA_CMDQ_SIZE ,GFP_KERNEL ); +if (!ctx->cmdq) { +dev_err (ctx->dev,"Failed to allocate command queue.\n" ); +return -ENOMEM ; + } + + ctx->vga_virt =ioremap (ctx->vga_phys, ctx->vga_size);Use
devm_ioremap()to avoid the cleanup.Quoted 9 lines
drivers/soc/aspeed/aspeed-xdma.c new file +9
-0+if (!ctx->vga_virt) { +dev_err (ctx->dev,"Failed to ioremap VGA memory.\n" ); +return -ENOMEM ; + } + + rc =gen_pool_add_virt (ctx->vga_pool, (unsigned long )ctx->vga_virt, + ctx->vga_phys, ctx->vga_size,-1 ); +if (rc) { +dev_err (ctx->dev,"Failed to add memory to genalloc pool.\n" );
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 669
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+iounmap (ctx->vga_virt); +return rc; + } + + ctx->cmdq_vga_virt =gen_pool_dma_alloc (ctx->vga_pool,XDMA_CMDQ_SIZE , + &ctx->cmdq_vga_phys);Can you educate me on this a little? Why is a command queue being allocated in memory writable by the host? Aren't we opening ourselves up to potential corruption?
In it's current configuration, the engine can't access anything except the VGA memory. That includes the location for the command queue. Not sure much can be done about this. What path can the host use to access this memory though?
Quoted 43 lines
Quoted 43 lines
drivers/soc/aspeed/aspeed-xdma.c new file +42
-0+if (!ctx->cmdq_vga_virt) { +dev_err (ctx->dev,"Failed to genalloc cmdq.\n" ); +iounmap (ctx->vga_virt); +return -ENOMEM ; + } + +dev_dbg (ctx->dev,"VGA mapped at phys[%08x], size[%08x].\n" , + ctx->vga_phys, ctx->vga_size); + +return 0 ; +} + +static int aspeed_xdma_probe (struct platform_device *pdev) +{ +int irq; +int pcie_irq; +int rc; +enum versions vs = xdma_ast2500; +struct device *dev = &pdev->dev; +struct aspeed_xdma *ctx =devm_kzalloc (dev,sizeof (*ctx),GFP_KERNEL ); +const void *md =of_device_get_match_data (dev); + +if (!ctx) +return -ENOMEM ; + +if (md) + vs = (enum versions )md; + +switch (vs) { +default : +case xdma_ast2500: + ctx->version = xdma_ast2500; + ctx->control =XDMA_AST2500_CTRL_US_COMP | +XDMA_AST2500_CTRL_DS_COMP | +XDMA_AST2500_CTRL_DS_DIRTY | +FIELD_PREP (XDMA_AST2500_CTRL_DS_SIZE , +XDMA_DS_PCIE_REQ_SIZE_256 ) | +XDMA_AST2500_CTRL_DS_TIMEOUT | +XDMA_AST2500_CTRL_DS_CHECK_ID ; + ctx->queue_entry_size =XDMA_AST2500_QUEUE_ENTRY_SIZE ; + ctx->regs.bmc_cmdq_addr =XDMA_AST2500_BMC_CMDQ_ADDR ; + ctx->regs.bmc_cmdq_endp =XDMA_AST2500_BMC_CMDQ_ENDP ;
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 718
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+ ctx->regs.bmc_cmdq_writep =XDMA_AST2500_BMC_CMDQ_WRITEP ; + ctx->regs.bmc_cmdq_readp =XDMA_AST2500_BMC_CMDQ_READP ; + ctx->regs.control =XDMA_AST2500_CTRL ; + ctx->regs.status =XDMA_AST2500_STATUS ; + ctx->status_bits.us_comp =XDMA_AST2500_STATUS_US_COMP ; + ctx->status_bits.ds_comp =XDMA_AST2500_STATUS_DS_COMP ; + ctx->status_bits.ds_dirty =XDMA_AST2500_STATUS_DS_DIRTY ;Why not include all this in the match data?
Sure.
Quoted 190 lines
Quoted 9 lines
drivers/soc/aspeed/aspeed-xdma.c new file +8
-0+break ; +case xdma_ast2600: + ctx->version = xdma_ast2600; + ctx->control =XDMA_AST2600_CTRL_US_COMP | +XDMA_AST2600_CTRL_DS_COMP | +XDMA_AST2600_CTRL_DS_DIRTY | +FIELD_PREP (XDMA_AST2600_CTRL_DS_SIZE , +XDMA_DS_PCIE_REQ_SIZE_256 );drivers/soc/aspeed/aspeed-xdma.c line 736
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ ctx->queue_entry_size =XDMA_AST2600_QUEUE_ENTRY_SIZE ; + ctx->regs.bmc_cmdq_addr =XDMA_AST2600_BMC_CMDQ_ADDR ; + ctx->regs.bmc_cmdq_endp =XDMA_AST2600_BMC_CMDQ_ENDP ; + ctx->regs.bmc_cmdq_writep =XDMA_AST2600_BMC_CMDQ_WRITEP ; + ctx->regs.bmc_cmdq_readp =XDMA_AST2600_BMC_CMDQ_READP ; + ctx->regs.control =XDMA_AST2600_CTRL ; + ctx->regs.status =XDMA_AST2600_STATUS ; + ctx->status_bits.us_comp =XDMA_AST2600_STATUS_US_COMP ; + ctx->status_bits.ds_comp =XDMA_AST2600_STATUS_DS_COMP ; + ctx->status_bits.ds_dirty =XDMA_AST2600_STATUS_DS_DIRTY ;Same query as above
Quoted 39 lines
drivers/soc/aspeed/aspeed-xdma.c new file +39
-0+break ; + }; + + ctx->dev = dev; +platform_set_drvdata (pdev, ctx); +mutex_init (&ctx->start_lock); +INIT_DELAYED_WORK (&ctx->reset_work, aspeed_xdma_reset_work); +spin_lock_init (&ctx->client_lock); +spin_lock_init (&ctx->reset_lock); +init_waitqueue_head (&ctx->wait); + + ctx->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (ctx->base)) { +dev_err (dev,"Unable to ioremap registers.\n" ); +return PTR_ERR (ctx->base); + } + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) { +dev_err (dev,"Unable to find IRQ.\n" ); +return -ENODEV ; + } + + rc =devm_request_irq (dev, irq, aspeed_xdma_irq,IRQF_SHARED , +DEVICE_NAME , ctx); +if (rc <0 ) { +dev_err (dev,"Unable to request IRQ %d.\n" , irq); +return rc; + } + + ctx->clock =devm_clk_get (dev,NULL ); +if (IS_ERR (ctx->clock)) { +dev_err (dev,"Unable to request clock.\n" ); +return PTR_ERR (ctx->clock); + } + + ctx->reset =devm_reset_control_get_exclusive (dev,NULL ); +if (IS_ERR (ctx->reset)) { +dev_err (dev,"Unable to request reset control.\n" );drivers/soc/aspeed/aspeed-xdma.c line 785
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+return PTR_ERR (ctx->reset); + } + + ctx->vga_pool =devm_gen_pool_create (dev,ilog2 (PAGE_SIZE ),-1 ,NULL ); +if (!ctx->vga_pool) { +dev_err (dev,"Unable to setup genalloc pool.\n" ); +return -ENOMEM ; + } + +clk_prepare_enable (ctx->clock);Check for errors
drivers/soc/aspeed/aspeed-xdma.c line 788
Quoted 3 lines
drivers/soc/aspeed/aspeed-xdma.c new file +3
-0+msleep (XDMA_RESET_TIME_MS ); + +reset_control_deassert (ctx->reset);Check for errors.
Quoted 24 lines
drivers/soc/aspeed/aspeed-xdma.c new file +24
-0+msleep (XDMA_RESET_TIME_MS ); + + rc =aspeed_xdma_init (ctx); +if (rc) { +reset_control_assert (ctx->reset); +clk_disable_unprepare (ctx->clock); +return rc; + } + +aspeed_xdma_init_eng (ctx); + +/* +* This interrupt could fire immediately so only request it once the +* engine and driver are initialized. +*/ + pcie_irq =platform_get_irq (pdev,1 ); +if (pcie_irq <0 ) { +dev_warn (dev,"Unable to find PCI-E IRQ.\n" ); + }else { + rc =devm_request_irq (dev, pcie_irq, aspeed_xdma_pcie_irq, +IRQF_SHARED ,DEVICE_NAME , ctx); +if (rc <0 ) +dev_warn (dev,"Unable to request PCI-E IRQ %d.\n" , rc); + }drivers/soc/aspeed/aspeed-xdma.c line 822
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ +return 0 ; +} + +static int aspeed_xdma_remove (struct platform_device *pdev) +{ +struct aspeed_xdma *ctx =platform_get_drvdata (pdev); + +gen_pool_free (ctx->vga_pool, (unsigned long )ctx->cmdq_vga_virt, +XDMA_CMDQ_SIZE );You've used
devm_gen_pool_create(), so no need to explicitly free it.drivers/soc/aspeed/aspeed-xdma.c line 823
Quoted 1 line
drivers/soc/aspeed/aspeed-xdma.c new file +1
-0+iounmap (ctx->vga_virt);This is unnecessary if we use
devm_ioremap()as suggested above.drivers/soc/aspeed/aspeed-xdma.c line 834
Quoted 11 lines
drivers/soc/aspeed/aspeed-xdma.c new file +11
-0+ +reset_control_assert (ctx->reset); +clk_disable_unprepare (ctx->clock); + +return 0 ; +} + +static const struct of_device_id aspeed_xdma_match[] = { + { + .compatible ="aspeed,ast2500-xdma" , + .data = (void *)xdma_ast2500,I'd prefer you create a struct as discussed throughout.
Quoted 61 lines
drivers/soc/aspeed/aspeed-xdma.c new file +22
-0+ }, + { + .compatible = "aspeed,ast2600-xdma", + .data = (void *)xdma_ast2600, + }, + { }, +}; + +static struct platform_driver aspeed_xdma_driver = { + .probe = aspeed_xdma_probe, + .remove = aspeed_xdma_remove, + .driver = { + .name =DEVICE_NAME , + .of_match_table = aspeed_xdma_match, + }, +}; + +module_platform_driver (aspeed_xdma_driver); + +MODULE_AUTHOR ("Eddie James" ); +MODULE_DESCRIPTION ("Aspeed XDMA Engine Driver" ); +MODULE_LICENSE ("GPL v2" );include/uapi/linux/aspeed-xdma.h new file +33
-0@@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* Copyright IBM Corp 2019 */ + +#ifndef _UAPI_LINUX_ASPEED_XDMA_H_ +#define _UAPI_LINUX_ASPEED_XDMA_H_ + +#include <linux/types.h> + +/* +* aspeed_xdma_direction +* +* ASPEED_XDMA_DIRECTION_DOWNSTREAM: transfers data from the host to the BMC +* +* ASPEED_XDMA_DIRECTION_UPSTREAM: transfers data from the BMC to the host +* +* ASPEED_XDMA_DIRECTION_RESET: resets the XDMA engine +*/ +enum aspeed_xdma_direction { +ASPEED_XDMA_DIRECTION_DOWNSTREAM =0 , +ASPEED_XDMA_DIRECTION_UPSTREAM , +ASPEED_XDMA_DIRECTION_RESET , +}; + +/* +* aspeed_xdma_op +* +* host_addr: the DMA address on the host side, typically configured by PCI +* subsystem +* +* len: the size of the transfer in bytes +* +* direction: an enumerator indicating the direction of the DMA operation; see +* enum aspeed_xdma_direction
Quoted 8 lines
include/uapi/linux/aspeed-xdma.h line 37
Quoted 4 lines
include/uapi/linux/aspeed-xdma.h new file +4
-0+* +* bmc_addr: the virtual address to DMA on the BMC side; this parameter is +* unused on current platforms since the XDMA engine is restricted to +* accessing the VGA memory space This doesn't make sense to me - if it's a virtual address then talking about the VGA space doesn't make sense to me as where the memory lives is an implementation detail. If the parameter is a physical address then it makes sense, but we'd always want it specified regardless?
As the comment says, it's unused. I added the parameter to future-proof the API in case the engine is configured differently, allowing arbitrary memory access by the engine. In that case, the user would pass the virtual address of their data.
Thanks for the review!
Eddie
Quoted 19 lines
Andrew
Quoted 16 lines
include/uapi/linux/aspeed-xdma.h new file +12
-0+* +* reserved: for natural alignment purposes only +*/ +struct aspeed_xdma_op { +__u64 host_addr; +__u32 len; +__u32 direction; +__u32 bmc_addr; +__u32 reserved; +}; + +#endif /* _UAPI_LINUX_ASPEED_XDMA_H_ */ Signature · 1 line
1.8.3.1
Re: [PATCH 07/12] drivers/soc: xdma: Add user interface
In reply to Andrew JefferyQuoted 64 lines · Andrew Jeffery
Quoted 39 lines · Eddie James
This commits adds a miscdevice to provide a user interface to the XDMA engine. The interface provides the write operation to start DMA operations. The DMA parameters are passed as the data to the write call. The actual data to transfer is NOT passed through write. Note that both directions of DMA operation are accomplished through the write command; BMC to host and host to BMC.
The XDMA engine is restricted to only accessing the reserved memory space on the AST2500, typically used by the VGA. For this reason, the VGA memory space is pooled and allocated with genalloc. Users calling mmap allocate pages from this pool for their usage. The space allocated by a client will be the space used in the DMA operation. For an "upstream" (BMC to host) operation, the data in the client's area will be transferred to the host. For a "downstream" (host to BMC) operation, the host data will be placed in the client's memory area.
Poll is also provided in order to determine when the DMA operation is complete for non-blocking IO.
Signed-off-by Eddie James <[email protected]>--- drivers/soc/aspeed/aspeed-xdma.c | 223 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+)drivers/soc/aspeed/aspeed-xdma.c +3
-0@@ -64,6 +64,9 @@#define XDMA_CMDQ_SIZE PAGE_SIZE#define XDMA_NUM_CMDS \ (XDMA_CMDQ_SIZE / sizeof(struct aspeed_xdma_cmd)) +#define XDMA_OP_SIZE_MAX sizeof(struct aspeed_xdma_op) +#define XDMA_OP_SIZE_MIN \ + (sizeof(struct aspeed_xdma_op) - sizeof(u64))/* Aspeed specification requires 10ms after switching the reset line */ #define XDMA_RESET_TIME_MS 10drivers/soc/aspeed/aspeed-xdma.c struct aspeed_xdma { · line 222
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c +1
-0@@ -216,6 +219,7 @@ struct aspeed_xdma {bool in_reset;bool upstream;unsigned int cmd_idx; +struct mutex file_lock;Please add documentation about what data
file_lockis protecting.Quoted 17 lines
drivers/soc/aspeed/aspeed-xdma.c +2
-0struct mutex start_lock;struct delayed_work reset_work;spinlock_t client_lock;@@ -230,6 +234,8 @@ struct aspeed_xdma {dma_addr_t cmdq_vga_phys;void *cmdq_vga_virt;struct gen_pool *vga_pool; + +struct miscdevice misc; };struct aspeed_xdma_client {@@ -557,6 +563,204 @@ static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg)return IRQ_HANDLED ; }
Quoted 16 lines
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c +5
-0+static ssize_t aspeed_xdma_write (struct file *file,const char __user *buf, +size_t len,loff_t *offset) +{ +int rc; +struct aspeed_xdma_op op;drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 580
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; +u32 offs = client->phys ? (client->phys - ctx->vga_phys) : +XDMA_CMDQ_SIZE ; + +if (len <XDMA_OP_SIZE_MIN ) +return -EINVAL ; + +if (len >XDMA_OP_SIZE_MAX ) + len =XDMA_OP_SIZE_MAX ;Isn't this an EINVAL case as well?
Perhaps so.
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 586
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c +6
-0+ + rc =copy_from_user (&op, buf, len); +if (rc) +return rc; + +if (op.direction ==ASPEED_XDMA_DIRECTION_RESET ) {Seems a bit abusive to use the direction field to issue a reset.
What would you recommend instead?
Quoted 17 lines
Quoted 17 lines
drivers/soc/aspeed/aspeed-xdma.c +16
-0+mutex_lock (&ctx->start_lock); + +if (aspeed_xdma_reset_start (ctx)) { +msleep (XDMA_RESET_TIME_MS ); + +aspeed_xdma_reset_finish (ctx); + } + +mutex_unlock (&ctx->start_lock); + +return len; + }else if (op.direction >ASPEED_XDMA_DIRECTION_RESET ) { +return -EINVAL ; + } + +if (op.len > ctx->vga_size - offs)
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 609
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c +7
-0+return -EINVAL ; + +if (file->f_flags &O_NONBLOCK ) { +if (!mutex_trylock (&ctx->file_lock)) +return -EAGAIN ; + +if (ctx->in_progress || ctx->in_reset) {
ctx->in_progresswas protected by a lock that isn'tfile_lock, so this looks wrong.
file_lock isn't protecting in_progress. It's protecting access to the whole engine while a transfer is in progress. in_progress isn't protected at all, it's just better to lock before waiting for in_progress so that multiple clients don't all see in_progress go false and have to wait for a mutex (particularly in the nonblocking case).
Quoted 21 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 617
Quoted 9 lines
drivers/soc/aspeed/aspeed-xdma.c +8
-0+mutex_unlock (&ctx->file_lock); +return -EAGAIN ; + } + }else { +mutex_lock (&ctx->file_lock); + + rc =wait_event_interruptible (ctx->wait, !ctx->in_progress && + !ctx->in_reset);As above.
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+if (rc) { +mutex_unlock (&ctx->file_lock); +return -EINTR ; + } + } + +aspeed_xdma_start (ctx, &op, ctx->vga_phys + offs, client); + +mutex_unlock (&ctx->file_lock); +
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 634
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c +7
-0+if (!(file->f_flags &O_NONBLOCK )) { + rc =wait_event_interruptible (ctx->wait, !ctx->in_progress); +if (rc) +return -EINTR ; + +if (client->error) +return -EIO ;What's the
client->errorvalue? Can it be more informative?
Not really. There isn't much error information available. Basically the only way to get an error is if the engine is reset (user or PCIE initiated) while the transfer is on-going.
Quoted 11 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 597
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c +3
-0+ } + +return len;We've potentially truncated len above (in the len >
XDMA_OP_SIZE_MAX), which leads to some ambiguity with thewrite()syscall given that it can potentially return less than the requested length. This is one such case, but the caller probably shouldn't attempt a follow-up write.This would go away if we make the len >
XDMA_OP_SIZE_MAXan EINVAL case as suggested agove.
Sure.
Quoted 52 lines
Quoted 52 lines
drivers/soc/aspeed/aspeed-xdma.c +51
-0+} + +static __poll_t aspeed_xdma_poll (struct file *file, +struct poll_table_struct *wait) +{ +__poll_t mask =0 ; +__poll_t req =poll_requested_events (wait); +struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; + +if (req & (EPOLLIN |EPOLLRDNORM )) { +if (client->in_progress) +poll_wait (file, &ctx->wait, wait); + +if (!client->in_progress) { +if (client->error) + mask |=EPOLLERR ; +else + mask |=EPOLLIN |EPOLLRDNORM ; + } + } + +if (req & (EPOLLOUT |EPOLLWRNORM )) { +if (ctx->in_progress) +poll_wait (file, &ctx->wait, wait); + +if (!ctx->in_progress) + mask |=EPOLLOUT |EPOLLWRNORM ; + } + +return mask; +} + +static void aspeed_xdma_vma_close (struct vm_area_struct *vma) +{ +struct aspeed_xdma_client *client = vma->vm_private_data; + +gen_pool_free (client->ctx->vga_pool, (unsigned long )client->virt, + client->size); + + client->virt =NULL ; + client->phys =0 ; + client->size =0 ; +} + +static const struct vm_operations_struct aspeed_xdma_vm_ops = { + .close = aspeed_xdma_vma_close, +}; + +static int aspeed_xdma_mmap (struct file *file,struct vm_area_struct *vma) +{
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 695
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c +7
-0+int rc; +struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; + +/* restrict file to one mapping */ +if (client->size) +return -ENOMEM ;Can we do better with the error code here?
Maybe? I'm open to suggestions...
Quoted 13 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 706
Quoted 12 lines
drivers/soc/aspeed/aspeed-xdma.c +11
-0+ + client->size = vma->vm_end - vma->vm_start; + client->virt =gen_pool_dma_alloc (ctx->vga_pool, client->size, + &client->phys); +if (!client->virt) { + client->phys =0 ; + client->size =0 ; +return -ENOMEM ; + } + + vma->vm_pgoff = (client->phys - ctx->vga_phys) >>PAGE_SHIFT ;Where does
client->physget set?
gen_pool_dma_alloc sets it.
Thanks for the review!
Eddie
Quoted 2 lines
Andrew
Re: [PATCH 06/12] drivers/soc: Add Aspeed XDMA Engine Driver
In reply to Eddie JamesQuoted 70 lines · Eddie James
Quoted 68 lines · Andrew Jeffery
Quoted 63 lines · Eddie James
The XDMA engine embedded in the AST2500 and AST2600 SOCs performs PCI DMA operations between the SOC (acting as a BMC) and a host processor in a server.
This commit adds a driver to control the XDMA engine and adds functions to initialize the hardware and memory and start DMA operations.
Signed-off-by Eddie James <[email protected]>--- MAINTAINERS | 2 + drivers/soc/aspeed/Kconfig | 8 + drivers/soc/aspeed/Makefile | 1 + drivers/soc/aspeed/aspeed-xdma.c | 856 +++++++++++++++++++++++++++++++++++++++ include/uapi/linux/aspeed-xdma.h | 49 +++ 5 files changed, 916 insertions(+)create mode 100644
drivers/soc/aspeed/aspeed-xdma.ccreate mode 100644include/uapi/linux/aspeed-xdma.hMAINTAINERS +2
-0@@ -2696,6 +2696,8 @@ M: Eddie James <[email protected]> L: [email protected] (moderated for non-subscribers) S: Maintained F: Documentation/devicetree/bindings/soc/aspeed/xdma.txt +F: drivers/soc/aspeed/aspeed-xdma.c +F: include/uapi/linux/aspeed-xdma.h ASUS NOTEBOOKS AND EEEPC ACPI/WMI EXTRAS DRIVERS M: Corentin Chary <[email protected]>drivers/soc/aspeed/Kconfig +8
-0@@ -29,4 +29,12 @@ config ASPEED_P2A_CTRL ioctl()s, the driver also provides an interface for userspace mappings to a pre-defined region. +config ASPEED_XDMA + tristate "Aspeed XDMA Engine Driver" + depends on SOC_ASPEED && REGMAP && MFD_SYSCON && HAS_DMA + help + Enable support for the Aspeed XDMA Engine found on the Aspeed AST2XXX + SOCs. The XDMA engine can perform automatic PCI DMA operations + between the AST2XXX (acting as a BMC) and a host processor. + endmenudrivers/soc/aspeed/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_ASPEED_LPC_CTRL) += aspeed-lpc-ctrl.o obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o obj-$(CONFIG_ASPEED_P2A_CTRL) += aspeed-p2a-ctrl.o +obj-$(CONFIG_ASPEED_XDMA) += aspeed-xdma.odrivers/soc/aspeed/aspeed-xdma.c new file +0
-0drivers/soc/aspeed/aspeed-xdma.c line 1
Quoted 1 line
drivers/soc/aspeed/aspeed-xdma.c new file +1
-0@@ -0,0 +1,856 @@ +// SPDX-License-Identifier: GPL-2.0+ This should be "GPL-2.0-or-later" (https://spdx.org/licenses/)
Quoted 7 lines
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c line 4
Quoted 3 lines
drivers/soc/aspeed/aspeed-xdma.c new file +3
-0+// Copyright IBM Corp 2019 + +#include <linux/aspeed-xdma.h> A device-specific header in this include path seems a little strange to me.
It's under uapi... do I need to specify a different path?
No, I didn't circle around to removing the comment. Should be fine for uapi.
Quoted 67 lines
Quoted 57 lines
Quoted 24 lines
drivers/soc/aspeed/aspeed-xdma.c new file +21
-0+#include <linux/bitfield.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/fs.h> +#include <linux/genalloc.h> +#include <linux/interrupt.h> +#include <linux/jiffies.h> +#include <linux/mfd/syscon.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/poll.h> +#include <linux/regmap.h> +#include <linux/reset.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/string.h> drivers/soc/aspeed/aspeed-xdma.c line 35
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+#include <linux/uaccess.h> +#include <linux/wait.h> +#include <linux/workqueue.h> + +#define DEVICE_NAME "aspeed-xdma" + +#define SCU_AST2500_STRAP 0x070 +#define SCU_AST2500_STRAP_VGA_MEM GENMASK(3, 2) +#define SCU_AST2600_STRAP 0x500 +#define SCU_AST2600_STRAP_VGA_MEM GENMASK(14, 13)It could be easier to review if you add support for one SoC at a time.
Quoted 21 lines
drivers/soc/aspeed/aspeed-xdma.c new file +21
-0+ +#define SCU_AST2500_PCIE_CONF 0x180 +#define SCU_AST2600_PCIE_CONF 0xc20 +#define SCU_PCIE_CONF_VGA_EN BIT(0) +#define SCU_PCIE_CONF_VGA_EN_MMIO BIT(1) +#define SCU_PCIE_CONF_VGA_EN_LPC BIT(2) +#define SCU_PCIE_CONF_VGA_EN_MSI BIT(3) +#define SCU_PCIE_CONF_VGA_EN_MCTP BIT(4) +#define SCU_PCIE_CONF_VGA_EN_IRQ BIT(5) +#define SCU_PCIE_CONF_VGA_EN_DMA BIT(6) +#define SCU_PCIE_CONF_BMC_EN BIT(8) +#define SCU_PCIE_CONF_BMC_EN_MMIO BIT(9) +#define SCU_PCIE_CONF_BMC_EN_MSI BIT(11) +#define SCU_PCIE_CONF_BMC_EN_MCTP BIT(12) +#define SCU_PCIE_CONF_BMC_EN_IRQ BIT(13) +#define SCU_PCIE_CONF_BMC_EN_DMA BIT(14) + +#define SCU_AST2500_BMC_CLASS_REV 0x19c +#define SCU_AST2600_BMC_CLASS_REV 0xc4c +#define SCU_BMC_CLASS_REV_XDMA 0xff000001 +Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 62
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+#define SDMC_BASE 0x1e6e0000 +#define SDMC_CONF 0x004 +#define SDMC_CONF_MEM GENMASK(1, 0) +#define SDMC_REMAP 0x008 +#define SDMC_AST2500_REMAP_MAGIC (BIT(16) | BIT(17)) +#define SDMC_AST2600_REMAP_MAGIC BIT(18)Can we have something more descriptive than "MAGIC"? What these bits are doing is well documented and defined.
Quoted 4 lines
Maybe I missed it then... I wasn't able to correspond these necessary bits to what is actually happening. The doc indicates it remaps "REQs" to the highest memory space. What do the REQs correspond to, and why is it these bits for these SOCs?
The REQ index corresponds to arbiter access priorities for each device. As the REQ table describes all the devices the remapping register simply reuses the REQ indexes to capture the remapping state for each device by mapping the REQ index to a bit index for the remap word.
I suggest you do something like:
#define SDMC_AST2500_REMAP_PCIE_ACCESS BIT(16)
#define SDMC_AST2500_REMAP_XDMA_ACCESS BIT(17)
#define SDMC_AST2600_REMAP_XDMA1_ACCESS BIT(18)
Quoted 58 lines
Quoted 48 lines
Quoted 48 lines
drivers/soc/aspeed/aspeed-xdma.c new file +45
-0+ +#define XDMA_CMDQ_SIZE PAGE_SIZE +#define XDMA_NUM_CMDS \ + (XDMA_CMDQ_SIZE / sizeof(struct aspeed_xdma_cmd)) + +/* Aspeed specification requires 10ms after switching the reset line */ +#define XDMA_RESET_TIME_MS 10 + +#define XDMA_DS_PCIE_REQ_SIZE_128 0 +#define XDMA_DS_PCIE_REQ_SIZE_256 1 +#define XDMA_DS_PCIE_REQ_SIZE_512 2 +#define XDMA_DS_PCIE_REQ_SIZE_1K 3 +#define XDMA_DS_PCIE_REQ_SIZE_2K 4 +#define XDMA_DS_PCIE_REQ_SIZE_4K 5 + +#define XDMA_CMD_AST2500_PITCH_SHIFT 3 +#define XDMA_CMD_AST2500_PITCH_BMC GENMASK_ULL(62, 51) +#define XDMA_CMD_AST2500_PITCH_HOST GENMASK_ULL(46, 35) +#define XDMA_CMD_AST2500_PITCH_UPSTREAM BIT_ULL(31) +#define XDMA_CMD_AST2500_PITCH_ADDR GENMASK_ULL(29, 4) +#define XDMA_CMD_AST2500_PITCH_ID BIT_ULL(0) +#define XDMA_CMD_AST2500_CMD_IRQ_EN BIT_ULL(31) +#define XDMA_CMD_AST2500_CMD_LINE_NO GENMASK_ULL(27, 16) +#define XDMA_CMD_AST2500_CMD_IRQ_BMC BIT_ULL(15) +#define XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT 4 +#define XDMA_CMD_AST2500_CMD_LINE_SIZE \ + GENMASK_ULL(14, XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT) +#define XDMA_CMD_AST2500_CMD_ID BIT_ULL(1) + +#define XDMA_CMD_AST2600_PITCH_BMC GENMASK_ULL(62, 48) +#define XDMA_CMD_AST2600_PITCH_HOST GENMASK_ULL(46, 32) +#define XDMA_CMD_AST2600_PITCH_ADDR GENMASK_ULL(30, 0) +#define XDMA_CMD_AST2600_CMD_64_EN BIT_ULL(40) +#define XDMA_CMD_AST2600_CMD_IRQ_BMC BIT_ULL(37) +#define XDMA_CMD_AST2600_CMD_IRQ_HOST BIT_ULL(36) +#define XDMA_CMD_AST2600_CMD_UPSTREAM BIT_ULL(32) +#define XDMA_CMD_AST2600_CMD_LINE_NO GENMASK_ULL(27, 16) +#define XDMA_CMD_AST2600_CMD_LINE_SIZE GENMASK_ULL(14, 0) +#define XDMA_CMD_AST2600_CMD_MULTILINE_SIZE GENMASK_ULL(14, 12) + +#define XDMA_AST2500_QUEUE_ENTRY_SIZE 4 +#define XDMA_AST2500_HOST_CMDQ_ADDR0 0x00 +#define XDMA_AST2500_HOST_CMDQ_ENDP 0x04 +#define XDMA_AST2500_HOST_CMDQ_WRITEP 0x08 +#define XDMA_AST2500_HOST_CMDQ_READP 0x0cQuoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 112
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c new file +5
-0+#define XDMA_AST2500_BMC_CMDQ_ADDR 0x10 +#define XDMA_AST2500_BMC_CMDQ_ENDP 0x14 +#define XDMA_AST2500_BMC_CMDQ_WRITEP 0x18 +#define XDMA_AST2500_BMC_CMDQ_READP 0x1c +#define XDMA_BMC_CMDQ_READP_MAGIC 0xee882266What's this about? Using a macro to abstract a magic number and then using the word "magic" in the name isn't very helpful. I think it should be renamed or documented, or both.
Quoted 1 line
Sure. It's the value to write to reset the read pointer.
maybe s/MAGIC/RESET/ then?
Quoted 118 lines
Quoted 108 lines
Quoted 108 lines
drivers/soc/aspeed/aspeed-xdma.c new file +105
-0+#define XDMA_AST2500_CTRL 0x20 +#define XDMA_AST2500_CTRL_US_COMP BIT(4) +#define XDMA_AST2500_CTRL_DS_COMP BIT(5) +#define XDMA_AST2500_CTRL_DS_DIRTY BIT(6) +#define XDMA_AST2500_CTRL_DS_SIZE GENMASK(19, 17) +#define XDMA_AST2500_CTRL_DS_TIMEOUT BIT(28) +#define XDMA_AST2500_CTRL_DS_CHECK_ID BIT(29) +#define XDMA_AST2500_STATUS 0x24 +#define XDMA_AST2500_STATUS_US_COMP BIT(4) +#define XDMA_AST2500_STATUS_DS_COMP BIT(5) +#define XDMA_AST2500_STATUS_DS_DIRTY BIT(6) +#define XDMA_AST2500_INPRG_DS_CMD1 0x38 +#define XDMA_AST2500_INPRG_DS_CMD2 0x3c +#define XDMA_AST2500_INPRG_US_CMD00 0x40 +#define XDMA_AST2500_INPRG_US_CMD01 0x44 +#define XDMA_AST2500_INPRG_US_CMD10 0x48 +#define XDMA_AST2500_INPRG_US_CMD11 0x4c +#define XDMA_AST2500_INPRG_US_CMD20 0x50 +#define XDMA_AST2500_INPRG_US_CMD21 0x54 +#define XDMA_AST2500_HOST_CMDQ_ADDR1 0x60 +#define XDMA_AST2500_VGA_CMDQ_ADDR0 0x64 +#define XDMA_AST2500_VGA_CMDQ_ENDP 0x68 +#define XDMA_AST2500_VGA_CMDQ_WRITEP 0x6c +#define XDMA_AST2500_VGA_CMDQ_READP 0x70 +#define XDMA_AST2500_VGA_CMD_STATUS 0x74 +#define XDMA_AST2500_VGA_CMDQ_ADDR1 0x78 + +#define XDMA_AST2600_QUEUE_ENTRY_SIZE 2 +#define XDMA_AST2600_HOST_CMDQ_ADDR0 0x00 +#define XDMA_AST2600_HOST_CMDQ_ADDR1 0x04 +#define XDMA_AST2600_HOST_CMDQ_ENDP 0x08 +#define XDMA_AST2600_HOST_CMDQ_WRITEP 0x0c +#define XDMA_AST2600_HOST_CMDQ_READP 0x10 +#define XDMA_AST2600_BMC_CMDQ_ADDR 0x14 +#define XDMA_AST2600_BMC_CMDQ_ENDP 0x18 +#define XDMA_AST2600_BMC_CMDQ_WRITEP 0x1c +#define XDMA_AST2600_BMC_CMDQ_READP 0x20 +#define XDMA_AST2600_VGA_CMDQ_ADDR0 0x24 +#define XDMA_AST2600_VGA_CMDQ_ADDR1 0x28 +#define XDMA_AST2600_VGA_CMDQ_ENDP 0x2c +#define XDMA_AST2600_VGA_CMDQ_WRITEP 0x30 +#define XDMA_AST2600_VGA_CMDQ_READP 0x34 +#define XDMA_AST2600_CTRL 0x38 +#define XDMA_AST2600_CTRL_US_COMP BIT(16) +#define XDMA_AST2600_CTRL_DS_COMP BIT(17) +#define XDMA_AST2600_CTRL_DS_DIRTY BIT(18) +#define XDMA_AST2600_CTRL_DS_SIZE GENMASK(22, 20) +#define XDMA_AST2600_STATUS 0x3c +#define XDMA_AST2600_STATUS_US_COMP BIT(16) +#define XDMA_AST2600_STATUS_DS_COMP BIT(17) +#define XDMA_AST2600_STATUS_DS_DIRTY BIT(18) +#define XDMA_AST2600_INPRG_DS_CMD00 0x40 +#define XDMA_AST2600_INPRG_DS_CMD01 0x44 +#define XDMA_AST2600_INPRG_DS_CMD10 0x48 +#define XDMA_AST2600_INPRG_DS_CMD11 0x4c +#define XDMA_AST2600_INPRG_DS_CMD20 0x50 +#define XDMA_AST2600_INPRG_DS_CMD21 0x54 +#define XDMA_AST2600_INPRG_US_CMD00 0x60 +#define XDMA_AST2600_INPRG_US_CMD01 0x64 +#define XDMA_AST2600_INPRG_US_CMD10 0x68 +#define XDMA_AST2600_INPRG_US_CMD11 0x6c +#define XDMA_AST2600_INPRG_US_CMD20 0x70 +#define XDMA_AST2600_INPRG_US_CMD21 0x74 + +enum versions { xdma_ast2500, xdma_ast2600 }; + +struct aspeed_xdma_cmd { +u64 host_addr; +u64 pitch; +u64 cmd; +u64 reserved; +}; + +struct aspeed_xdma_regs { +u8 bmc_cmdq_addr; +u8 bmc_cmdq_endp; +u8 bmc_cmdq_writep; +u8 bmc_cmdq_readp; +u8 control; +u8 status; +}; + +struct aspeed_xdma_status_bits { +u32 us_comp; +u32 ds_comp; +u32 ds_dirty; +}; + +struct aspeed_xdma_client ; + +struct aspeed_xdma { +enum versions version; +u32 control; +unsigned int queue_entry_size; +struct aspeed_xdma_regs regs; +struct aspeed_xdma_status_bits status_bits; + +struct device *dev; +void __iomem *base; +struct clk *clock; +struct reset_control *reset; + +bool in_progress; +bool in_reset; +bool upstream;Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 222
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c new file +5
-0+unsigned int cmd_idx; +struct mutex start_lock; +struct delayed_work reset_work; +spinlock_t client_lock; +spinlock_t reset_lock;What data are each of these locks protecting? Please add documentation about how you intend to use them. Try to group the locks with the data they protect if this is not already the case.
Quoted 1 line
Sure, though I feel the names are fairly descriptive.
Not descriptive enough for me. Please add documentation.
Quoted 41 lines
Quoted 31 lines
Quoted 31 lines
drivers/soc/aspeed/aspeed-xdma.c new file +28
-0+wait_queue_head_t wait; +struct aspeed_xdma_client *current_client; + +u32 vga_phys; +u32 vga_size; +void *cmdq; +void __iomem *vga_virt; +dma_addr_t cmdq_vga_phys; +void *cmdq_vga_virt; +struct gen_pool *vga_pool; +}; + +struct aspeed_xdma_client { +struct aspeed_xdma *ctx; + +bool error; +bool in_progress; +void *virt; +dma_addr_t phys; +u32 size; +}; + +static u32 aspeed_xdma_readl (struct aspeed_xdma *ctx,u8 reg) +{ +u32 v =readl (ctx->base + reg); + +dev_dbg (ctx->dev,"read %02x[%08x]\n" , reg, v); +return v;Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 256
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+} + +static void aspeed_xdma_writel (struct aspeed_xdma *ctx,u8 reg,u32 val) +{ +writel (val, ctx->base + reg); +dev_dbg (ctx->dev,"write %02x[%08x]\n" , reg,readl (ctx->base + reg));That
readl()seems a bit paranoid, and is probably evaluated whether or not thisdev_dbg()is enabled. What drove this approach?
Quoted 2 lines
There is some tricky masking of writes of many of the engine registers, so it was helpful to see what the actual result is. I could drop it.
Wouldn't you want to record what you were attempting to write vs the value that stuck then?
Quoted 53 lines
Quoted 43 lines
Quoted 43 lines
drivers/soc/aspeed/aspeed-xdma.c new file +40
-0+} + +static void aspeed_xdma_init_eng (struct aspeed_xdma *ctx) +{ +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_endp, + ctx->queue_entry_size *XDMA_NUM_CMDS ); +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_readp, +XDMA_BMC_CMDQ_READP_MAGIC ); +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_writep,0 ); +aspeed_xdma_writel (ctx, ctx->regs.control, ctx->control); +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_addr, ctx->cmdq_vga_phys); + + ctx->cmd_idx =0 ; + ctx->in_progress = false; +} + +static unsigned int aspeed_xdma_ast2500_set_cmd (struct aspeed_xdma *ctx, +struct aspeed_xdma_op *op, +u32 bmc_addr) +{ +u64 cmd =XDMA_CMD_AST2500_CMD_IRQ_EN |XDMA_CMD_AST2500_CMD_IRQ_BMC | +XDMA_CMD_AST2500_CMD_ID ; +u64 cmd_pitch = (op->direction ?XDMA_CMD_AST2500_PITCH_UPSTREAM :0 ) | +XDMA_CMD_AST2500_PITCH_ID ; +unsigned int line_size; +unsigned int nidx = (ctx->cmd_idx +1 ) %XDMA_NUM_CMDS ; +unsigned int line_no =1 ; +unsigned int pitch =1 ; +struct aspeed_xdma_cmd *ncmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[ctx->cmd_idx]); + +dev_dbg (ctx->dev,"xdma %s ast2500: bmc[%08x] len[%08x] host[%08x]\n" , + op->direction ?"upstream" :"downstream" , bmc_addr, op->len, + (u32 )op->host_addr); + +if (op->len >XDMA_CMD_AST2500_CMD_LINE_SIZE ) { +unsigned int rem; +unsigned int total; + + line_no = op->len /XDMA_CMD_AST2500_CMD_LINE_SIZE ;Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 302
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+ total =XDMA_CMD_AST2500_CMD_LINE_SIZE * line_no; + rem = (op->len - total) >> +XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT ; + line_size =XDMA_CMD_AST2500_CMD_LINE_SIZE ; + pitch = line_size >>XDMA_CMD_AST2500_PITCH_SHIFT ; + line_size >>=XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT ;Can we clean up the configuration of
line_sizeand pitch here? They are set to constants in this case.
Quoted 2 lines
I think this is as clean as it gets. They're used later on so unless I have more if statements it makes sense to set them here.
No worries, was just curious.
Quoted 135 lines
Quoted 125 lines
Quoted 125 lines
drivers/soc/aspeed/aspeed-xdma.c new file +122
-0+ +if (rem) { +u32 rbmc = bmc_addr + total; +struct aspeed_xdma_cmd *rcmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[nidx]); + + rcmd->host_addr = op->host_addr + (u64 )total; + rcmd->pitch = cmd_pitch | + ((u64 )rbmc &XDMA_CMD_AST2500_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_HOST ,1 ) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_BMC ,1 ); + rcmd->cmd = cmd | +FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_NO ,1 ) | +FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_SIZE , + rem); + +print_hex_dump_debug ("xdma rem" ,DUMP_PREFIX_OFFSET , +16 ,1 , rcmd,sizeof (*rcmd), true); + + cmd &= ~(XDMA_CMD_AST2500_CMD_IRQ_EN | +XDMA_CMD_AST2500_CMD_IRQ_BMC ); + + nidx = (nidx +1 ) %XDMA_NUM_CMDS ; + } + }else { + line_size = op->len >>XDMA_CMD_AST2500_CMD_LINE_SIZE_SHIFT ; + } + + ncmd->host_addr = op->host_addr; + ncmd->pitch = cmd_pitch | + ((u64 )bmc_addr &XDMA_CMD_AST2500_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_HOST , pitch) | +FIELD_PREP (XDMA_CMD_AST2500_PITCH_BMC , pitch); + ncmd->cmd = cmd |FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_NO , line_no) | +FIELD_PREP (XDMA_CMD_AST2500_CMD_LINE_SIZE , line_size); + +print_hex_dump_debug ("xdma cmd" ,DUMP_PREFIX_OFFSET ,16 ,1 , ncmd, +sizeof (*ncmd), true); + +return nidx; +} + +static unsigned int aspeed_xdma_ast2600_set_cmd (struct aspeed_xdma *ctx, +struct aspeed_xdma_op *op, +u32 bmc_addr) +{ +u64 cmd =XDMA_CMD_AST2600_CMD_IRQ_BMC | + (op->direction ?XDMA_CMD_AST2600_CMD_UPSTREAM :0 ); +unsigned int line_size; +unsigned int nidx = (ctx->cmd_idx +1 ) %XDMA_NUM_CMDS ; +unsigned int line_no =1 ; +unsigned int pitch =1 ; +struct aspeed_xdma_cmd *ncmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[ctx->cmd_idx]); + +if ((op->host_addr + op->len) &0xffffffff00000000ULL ) + cmd |=XDMA_CMD_AST2600_CMD_64_EN ; + +dev_dbg (ctx->dev,"xdma %s ast2600: bmc[%08x] len[%08x] " +"host[%016llx]\n" , op->direction ?"upstream" :"downstream" , + bmc_addr, op->len, op->host_addr); + +if (op->len >XDMA_CMD_AST2600_CMD_LINE_SIZE ) { +unsigned int rem; +unsigned int total; + + line_no = op->len /XDMA_CMD_AST2600_CMD_MULTILINE_SIZE ; + total =XDMA_CMD_AST2600_CMD_MULTILINE_SIZE * line_no; + rem = op->len - total; + line_size =XDMA_CMD_AST2600_CMD_MULTILINE_SIZE ; + pitch = line_size; + +if (rem) { +u32 rbmc = bmc_addr + total; +struct aspeed_xdma_cmd *rcmd = + &(((struct aspeed_xdma_cmd *)ctx->cmdq)[nidx]); + + rcmd->host_addr = op->host_addr + (u64 )total; + rcmd->pitch = + ((u64 )rbmc &XDMA_CMD_AST2600_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_HOST ,1 ) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_BMC ,1 ); + rcmd->cmd = cmd | +FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_NO ,1 ) | +FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_SIZE , + rem); + +print_hex_dump_debug ("xdma rem" ,DUMP_PREFIX_OFFSET , +16 ,1 , rcmd,sizeof (*rcmd), true); + + cmd &= ~XDMA_CMD_AST2600_CMD_IRQ_BMC ; + + nidx = (nidx +1 ) %XDMA_NUM_CMDS ; + } + }else { + line_size = op->len; + } + + ncmd->host_addr = op->host_addr; + ncmd->pitch = ((u64 )bmc_addr &XDMA_CMD_AST2600_PITCH_ADDR ) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_HOST , pitch) | +FIELD_PREP (XDMA_CMD_AST2600_PITCH_BMC , pitch); + ncmd->cmd = cmd |FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_NO , line_no) | +FIELD_PREP (XDMA_CMD_AST2600_CMD_LINE_SIZE , line_size); + +print_hex_dump_debug ("xdma cmd" ,DUMP_PREFIX_OFFSET ,16 ,1 , ncmd, +sizeof (*ncmd), true); + +return nidx; +} + +static void aspeed_xdma_start (struct aspeed_xdma *ctx, +struct aspeed_xdma_op *op,u32 bmc_addr, +struct aspeed_xdma_client *client) +{ +unsigned int nidx; + +mutex_lock (&ctx->start_lock); + +switch (ctx->version) { +default : +case xdma_ast2500:Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 430
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+ nidx =aspeed_xdma_ast2500_set_cmd (ctx, op, bmc_addr); +break ; +case xdma_ast2600: + nidx =aspeed_xdma_ast2600_set_cmd (ctx, op, bmc_addr); +break ; + }What was the trade-off between the enum and function pointers? Is the enum approach strictly better for some reason?
Quoted 1 line
No, I just decided to go with the switch.
I think this will go away with better use of the of match data.
Quoted 45 lines
Quoted 12 lines
drivers/soc/aspeed/aspeed-xdma.c line 437
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+ +memcpy (ctx->cmdq_vga_virt, ctx->cmdq,XDMA_CMDQ_SIZE ); + + client->in_progress = true; + ctx->current_client = client; + + ctx->in_progress = true;Do we need
ctx->in_progressvs just using the NULL state ofctx->current_client? Is it possible forctx->current_clientto be set and not have a transfer in progress?Good point, could probably drop that.
Quoted 18 lines
Quoted 18 lines
drivers/soc/aspeed/aspeed-xdma.c new file +17
-0+ ctx->upstream = op->direction ? true : false; + +aspeed_xdma_writel (ctx, ctx->regs.bmc_cmdq_writep, + nidx * ctx->queue_entry_size); + + ctx->cmd_idx = nidx; + +mutex_unlock (&ctx->start_lock); +} + +static void aspeed_xdma_done (struct aspeed_xdma *ctx,bool error) +{ +unsigned long flags; + +/* +* Lock to make sure simultaneous reset and transfer complete don't +* leave the client with the wrong error state. Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 458
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c new file +4
-0+*/ +spin_lock_irqsave (&ctx->client_lock, flags); + +if (ctx->current_client) {You're testing
ctx->current_clientunderctx->client_lockhere, butctx->current_clientis set underctx->start_lockinaspeed_xdma_start(), which does not takectx->client_lock. What data is protected byctx->client_lock? What data is protected byctx->client_lock?
Quoted 2 lines
client_lockis making sure the client.error and ctx.current_client are updated atomically, as indicated by the comment.
But you need to use a consistent lock, otherwise it's pointless.
Quoted 18 lines
It's impossible to be
starting a transfer at the same time, since ctx.in_progress would be true.Quoted 12 lines
drivers/soc/aspeed/aspeed-xdma.c line 466
Quoted 9 lines
drivers/soc/aspeed/aspeed-xdma.c new file +8
-0+ ctx->current_client->error = error; + ctx->current_client->in_progress = false; + ctx->current_client =NULL ; + } + +spin_unlock_irqrestore (&ctx->client_lock, flags); + + ctx->in_progress = false;You set
ctx->in_progressunderctx->start_lockinaspeed_xdma_start()but you do not takectx->start_lockwhen setting it here. What data isctx->start_lockprotecting?
Quoted 4 lines
start_lockis making sure that the hardware register state, command queue, and data associated with the current transfer are updated atomically in the start function. It shouldn't be necessary to lock just to resetin_progress
Then why is it set under start_lock in aspeed_xdma_start()?
These questions are why I asked you to document what locks are protecting which struct members above.
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
drivers/soc/aspeed/aspeed-xdma.c new file +26
-0+wake_up_interruptible_all (&ctx->wait); +} + +static irqreturn_t aspeed_xdma_irq (int irq,void *arg) +{ +struct aspeed_xdma *ctx = arg; +u32 status =aspeed_xdma_readl (ctx, ctx->regs.status); + +if (status & ctx->status_bits.ds_dirty) { +aspeed_xdma_done (ctx, true); + }else { +if (status & ctx->status_bits.us_comp) { +if (ctx->upstream) +aspeed_xdma_done (ctx, false); + } + +if (status & ctx->status_bits.ds_comp) { +if (!ctx->upstream) +aspeed_xdma_done (ctx, false); + } + } + +aspeed_xdma_writel (ctx, ctx->regs.status, status); + +return IRQ_HANDLED ; +}
Quoted 8 lines
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 500
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c new file +8
-0+ +static void aspeed_xdma_reset_finish (struct aspeed_xdma *ctx) +{ +unsigned long flags; + +spin_lock_irqsave (&ctx->reset_lock, flags); + + ctx->in_reset = false;
Looking back at this, I'd interpret in_reset as answering the question "is the device unusable?" In which case, it's not usable until after we've completed the sleep below, so I'd hold off on clearing the in_reset state until after the sleep completes.
I'm not sure that having in_reset represent the literal reset state of the device (given the additional constraints) as it stands is useful.
Quoted 26 lines
Quoted 16 lines
Quoted 16 lines
drivers/soc/aspeed/aspeed-xdma.c new file +16
-0+reset_control_deassert (ctx->reset); + +spin_unlock_irqrestore (&ctx->reset_lock, flags); + +msleep (XDMA_RESET_TIME_MS ); + +aspeed_xdma_init_eng (ctx); +aspeed_xdma_done (ctx, true); +} + +static bool aspeed_xdma_reset_start (struct aspeed_xdma *ctx) +{ +bool rc = true; +unsigned long flags; + +spin_lock_irqsave (&ctx->reset_lock, flags);Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 523
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+ +if (ctx->in_reset) { + rc = false; + }else { + ctx->in_reset = true; +reset_control_assert (ctx->reset); + }Do start and finish need to be split in this way?
Quoted 2 lines
Yes, in order to prevent waiting for 10ms in interrupt context during the reset.
Do we absolutely need to kick the reset off from interrupt context? Why not just queue the entire reset job from interrupt context?
Quoted 22 lines
Quoted 12 lines
Quoted 12 lines
drivers/soc/aspeed/aspeed-xdma.c new file +9
-0+ +spin_unlock_irqrestore (&ctx->reset_lock, flags); + +return rc; +} + +static void aspeed_xdma_reset_work (struct work_struct *work) +{ +struct delayed_work *dwork =to_delayed_work (work);Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 538
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+ struct aspeed_xdma *ctx = container_of(dwork, struct aspeed_xdma, + reset_work); + +/* +* Lock to make sure operations aren't started while the engine is +* in an undefined state coming out of reset and waiting to init. Shouldn't we be holding it across both
aspeed_xdma_reset_start()andaspeed_xdma_reset_finish()?
Quoted 5 lines
No, it isn't necessary and also
start_lockis a mutex which can't be locked in interrupt context. It isn't necessary because a reset before, during, or after starting a transfer will simply cause the transfer to do nothing until the reset completes, when it will be put into an error state.
So why do we lock it at all?
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/soc/aspeed/aspeed-xdma.c new file +9
-0+*/ +mutex_lock (&ctx->start_lock); + +aspeed_xdma_reset_finish (ctx); + +mutex_unlock (&ctx->start_lock); +} + +static irqreturn_t aspeed_xdma_pcie_irq (int irq,void *arg)
Quoted 8 lines
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 555
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c new file +8
-0+{ +struct aspeed_xdma *ctx = arg; + +dev_dbg (ctx->dev,"pcie reset\n" ); + +if (aspeed_xdma_reset_start (ctx)) +schedule_delayed_work (&ctx->reset_work, +msecs_to_jiffies (XDMA_RESET_TIME_MS ));
With the suggestion above, instead of having aspeed_xdma_reset_start() / aspeed_xdma_reset_finish() and the existing implementation of aspeed_xdma_reset_work(), we'd have just aspeed_xdma_reset(), and aspeed_xdma_reset_work() would look like:
static void aspeed_xdma_reset_work(struct work_struct *work)
{
struct delayed_work *dwork = to_delayed_work(work);
struct aspeed_xdma *ctx = container_of(dwork, struct aspeed_xdma, reset_work);
mutex_lock(&ctx->start_lock);aspeed_xdma_reset(ctx)mutex_unlock(&ctx->start_lock);
}
and aspeed_xdma_pcie_irq() becomes:
static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) {
struct aspeed_xdma *ctx = arg;
unsigned long flags;
dev_dbg(ctx->dev, "pcie reset\n");spin_lock_irqsave(&ctx->reset_lock, flags);
if (ctx->in_reset) {
spin_unlock_irqrestore(&ctx->reset_lock, flags);
return IRQ_HANDLED;
}ctx->in_reset = true;spin_unlock_irqrestore(&ctx->reset_lock, flags); schedule_delayed_work(&ctx->reset_work, msecs_to_jiffies(XDMA_RESET_TIME_MS)); return IRQ_HANDLED;
}
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+return IRQ_HANDLED ; +} + +static int aspeed_xdma_init (struct aspeed_xdma *ctx) +{ +int rc; +struct regmap *scu; +u32 conf; +u32 mem_size; +u32 remap;Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+u32 scu_bmc_class; +u32 scu_pcie_conf; +u32 scu_strap; +u32 sdmc_remap_magic; +u32 strap =0 ; +const u32 bmc =SCU_PCIE_CONF_BMC_EN |SCU_PCIE_CONF_BMC_EN_MSI | +SCU_PCIE_CONF_BMC_EN_MCTP Do we need MCTP here?
Quoted 1 line
I don't know, I used the default value which has MCTP enabled.
Ok. I'd tend to clear it, but it probably doesn't matter.
Quoted 139 lines
Quoted 98 lines
|
SCU_PCIE_CONF_BMC_EN_IRQ|drivers/soc/aspeed/aspeed-xdma.c
Quoted 3 lines
drivers/soc/aspeed/aspeed-xdma.c new file +3
-0+SCU_PCIE_CONF_BMC_EN_DMA ; +const u32 vga =SCU_PCIE_CONF_VGA_EN |SCU_PCIE_CONF_VGA_EN_MSI | +SCU_PCIE_CONF_VGA_EN_MCTP Do we need MCTP here?
|
SCU_PCIE_CONF_VGA_EN_IRQ|drivers/soc/aspeed/aspeed-xdma.c line 580
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c new file +4
-0+SCU_PCIE_CONF_VGA_EN_DMA ; +u32 mem_sizes[4 ] = {0x8000000 ,0x10000000 ,0x20000000 ,0x40000000 }; +const u32 vga_sizes[4 ] = {0x800000 ,0x1000000 ,0x2000000 ,0x4000000 }; +void __iomem *sdmc_base =ioremap (SDMC_BASE ,0x100 );Surely this should be a phandle from the devicetree? And what about conflicts with a potential SDMC driver? I don't think what you have is the right approach.
drivers/soc/aspeed/aspeed-xdma.c line 593
Quoted 13 lines
drivers/soc/aspeed/aspeed-xdma.c new file +13
-0+ +if (!sdmc_base) { +dev_err (ctx->dev,"Failed to ioremap mem controller regs.\n" ); +return -ENOMEM ; + } + +switch (ctx->version) { +default : +case xdma_ast2500: + scu_bmc_class =SCU_AST2500_BMC_CLASS_REV ; + scu_pcie_conf =SCU_AST2500_PCIE_CONF ; + scu_strap =SCU_AST2500_STRAP ; + sdmc_remap_magic =SDMC_AST2500_REMAP_MAGIC ;Can't this be described statically? The values should be derived from the devicetree compatible.
drivers/soc/aspeed/aspeed-xdma.c line 595
Quoted 2 lines
drivers/soc/aspeed/aspeed-xdma.c new file +2
-0+ + scu =syscon_regmap_lookup_by_compatible ("aspeed,ast2500-scu" );I think we should do this via phandle in the devicetree.
drivers/soc/aspeed/aspeed-xdma.c line 601
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+break ; +case xdma_ast2600: + scu_bmc_class =SCU_AST2600_BMC_CLASS_REV ; + scu_pcie_conf =SCU_AST2600_PCIE_CONF ; + scu_strap =SCU_AST2600_STRAP ; + sdmc_remap_magic =SDMC_AST2600_REMAP_MAGIC ;Can't this be described statically? The values should be derived from the devicetree compatible.
drivers/soc/aspeed/aspeed-xdma.c line 606
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c new file +5
-0+ + mem_sizes[0 ] *=2 ; + mem_sizes[1 ] *=2 ; + mem_sizes[2 ] *=2 ; + mem_sizes[3 ] *=2 ;Same query as above.
drivers/soc/aspeed/aspeed-xdma.c line 608
Quoted 2 lines
drivers/soc/aspeed/aspeed-xdma.c new file +2
-0+ + scu =syscon_regmap_lookup_by_compatible ("aspeed,ast2600-scu" );I think we should do this via phandle in the devicetree.
drivers/soc/aspeed/aspeed-xdma.c line 619
Quoted 11 lines
drivers/soc/aspeed/aspeed-xdma.c new file +11
-0+break ; + }; + +if (!scu) { +dev_err (ctx->dev,"Failed to grab SCU regs.\n" ); +return -ENOMEM ; + } + +/* Set SOC to use the BMC PCIe device and set the device class code */ +regmap_update_bits (scu, scu_pcie_conf, bmc | vga, bmc); +regmap_write (scu, scu_bmc_class,SCU_BMC_CLASS_REV_XDMA );This should be selectable, probably via the devicetree.
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+ +/* +* Calculate the VGA memory size and physical address from the SCU and +* memory controller registers. +*/ +regmap_read (scu, scu_strap, &strap);drivers/soc/aspeed/aspeed-xdma.c line 635
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ +switch (ctx->version) { +case xdma_ast2500: + ctx->vga_size = vga_sizes[FIELD_GET (SCU_AST2500_STRAP_VGA_MEM , + strap)]; +break ; +case xdma_ast2600: + ctx->vga_size = vga_sizes[FIELD_GET (SCU_AST2600_STRAP_VGA_MEM , + strap)]; +break ;Can't this be described statically? The values should be derived from the devicetree compatible.
drivers/soc/aspeed/aspeed-xdma.c line 642
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+ } + + conf =readl (sdmc_base +SDMC_CONF ); + remap =readl (sdmc_base +SDMC_REMAP ); + remap |= sdmc_remap_magic; +writel (remap, sdmc_base +SDMC_REMAP ); + mem_size = mem_sizes[conf &SDMC_CONF_MEM ];See previous objection to this.
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c line 646
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c new file +4
-0+ +iounmap (sdmc_base); + + ctx->vga_phys = (mem_size - ctx->vga_size) +0x80000000 ;RAM base should be extracted from the devicetree. Better yet, the VGA space should be extracted from the devicetree and this calculation avoided altogether.
Ok, I'll use the devicetree for all this instead.
Quoted 20 lines
drivers/soc/aspeed/aspeed-xdma.c line 654
Quoted 9 lines
drivers/soc/aspeed/aspeed-xdma.c new file +8
-0+ + ctx->cmdq =devm_kzalloc (ctx->dev,XDMA_CMDQ_SIZE ,GFP_KERNEL ); +if (!ctx->cmdq) { +dev_err (ctx->dev,"Failed to allocate command queue.\n" ); +return -ENOMEM ; + } + + ctx->vga_virt =ioremap (ctx->vga_phys, ctx->vga_size);Use
devm_ioremap()to avoid the cleanup.Quoted 9 lines
drivers/soc/aspeed/aspeed-xdma.c new file +9
-0+if (!ctx->vga_virt) { +dev_err (ctx->dev,"Failed to ioremap VGA memory.\n" ); +return -ENOMEM ; + } + + rc =gen_pool_add_virt (ctx->vga_pool, (unsigned long )ctx->vga_virt, + ctx->vga_phys, ctx->vga_size,-1 ); +if (rc) { +dev_err (ctx->dev,"Failed to add memory to genalloc pool.\n" );Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 669
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c new file +6
-0+iounmap (ctx->vga_virt); +return rc; + } + + ctx->cmdq_vga_virt =gen_pool_dma_alloc (ctx->vga_pool,XDMA_CMDQ_SIZE , + &ctx->cmdq_vga_phys);Can you educate me on this a little? Why is a command queue being allocated in memory writable by the host? Aren't we opening ourselves up to potential corruption?
Quoted 3 lines
In it's current configuration, the engine can't access anything except the VGA memory. That includes the location for the command queue. Not sure much can be done about this.
Okay, yes, not much can be done about that.
Quoted 1 line
What path can the host use to access this memory though?
The host can drive DMAs to the VGA region as well, "independent" of the BMC.
Quoted 258 lines
Quoted 45 lines
Quoted 45 lines
drivers/soc/aspeed/aspeed-xdma.c new file +42
-0+if (!ctx->cmdq_vga_virt) { +dev_err (ctx->dev,"Failed to genalloc cmdq.\n" ); +iounmap (ctx->vga_virt); +return -ENOMEM ; + } + +dev_dbg (ctx->dev,"VGA mapped at phys[%08x], size[%08x].\n" , + ctx->vga_phys, ctx->vga_size); + +return 0 ; +} + +static int aspeed_xdma_probe (struct platform_device *pdev) +{ +int irq; +int pcie_irq; +int rc; +enum versions vs = xdma_ast2500; +struct device *dev = &pdev->dev; +struct aspeed_xdma *ctx =devm_kzalloc (dev,sizeof (*ctx),GFP_KERNEL ); +const void *md =of_device_get_match_data (dev); + +if (!ctx) +return -ENOMEM ; + +if (md) + vs = (enum versions )md; + +switch (vs) { +default : +case xdma_ast2500: + ctx->version = xdma_ast2500; + ctx->control =XDMA_AST2500_CTRL_US_COMP | +XDMA_AST2500_CTRL_DS_COMP | +XDMA_AST2500_CTRL_DS_DIRTY | +FIELD_PREP (XDMA_AST2500_CTRL_DS_SIZE , +XDMA_DS_PCIE_REQ_SIZE_256 ) | +XDMA_AST2500_CTRL_DS_TIMEOUT | +XDMA_AST2500_CTRL_DS_CHECK_ID ; + ctx->queue_entry_size =XDMA_AST2500_QUEUE_ENTRY_SIZE ; + ctx->regs.bmc_cmdq_addr =XDMA_AST2500_BMC_CMDQ_ADDR ; + ctx->regs.bmc_cmdq_endp =XDMA_AST2500_BMC_CMDQ_ENDP ;Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c line 718
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c new file +7
-0+ ctx->regs.bmc_cmdq_writep =XDMA_AST2500_BMC_CMDQ_WRITEP ; + ctx->regs.bmc_cmdq_readp =XDMA_AST2500_BMC_CMDQ_READP ; + ctx->regs.control =XDMA_AST2500_CTRL ; + ctx->regs.status =XDMA_AST2500_STATUS ; + ctx->status_bits.us_comp =XDMA_AST2500_STATUS_US_COMP ; + ctx->status_bits.ds_comp =XDMA_AST2500_STATUS_DS_COMP ; + ctx->status_bits.ds_dirty =XDMA_AST2500_STATUS_DS_DIRTY ;Why not include all this in the match data?
Sure.
Quoted 190 lines
Quoted 9 lines
drivers/soc/aspeed/aspeed-xdma.c new file +8
-0+break ; +case xdma_ast2600: + ctx->version = xdma_ast2600; + ctx->control =XDMA_AST2600_CTRL_US_COMP | +XDMA_AST2600_CTRL_DS_COMP | +XDMA_AST2600_CTRL_DS_DIRTY | +FIELD_PREP (XDMA_AST2600_CTRL_DS_SIZE , +XDMA_DS_PCIE_REQ_SIZE_256 );drivers/soc/aspeed/aspeed-xdma.c line 736
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ ctx->queue_entry_size =XDMA_AST2600_QUEUE_ENTRY_SIZE ; + ctx->regs.bmc_cmdq_addr =XDMA_AST2600_BMC_CMDQ_ADDR ; + ctx->regs.bmc_cmdq_endp =XDMA_AST2600_BMC_CMDQ_ENDP ; + ctx->regs.bmc_cmdq_writep =XDMA_AST2600_BMC_CMDQ_WRITEP ; + ctx->regs.bmc_cmdq_readp =XDMA_AST2600_BMC_CMDQ_READP ; + ctx->regs.control =XDMA_AST2600_CTRL ; + ctx->regs.status =XDMA_AST2600_STATUS ; + ctx->status_bits.us_comp =XDMA_AST2600_STATUS_US_COMP ; + ctx->status_bits.ds_comp =XDMA_AST2600_STATUS_DS_COMP ; + ctx->status_bits.ds_dirty =XDMA_AST2600_STATUS_DS_DIRTY ;Same query as above
Quoted 39 lines
drivers/soc/aspeed/aspeed-xdma.c new file +39
-0+break ; + }; + + ctx->dev = dev; +platform_set_drvdata (pdev, ctx); +mutex_init (&ctx->start_lock); +INIT_DELAYED_WORK (&ctx->reset_work, aspeed_xdma_reset_work); +spin_lock_init (&ctx->client_lock); +spin_lock_init (&ctx->reset_lock); +init_waitqueue_head (&ctx->wait); + + ctx->base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (ctx->base)) { +dev_err (dev,"Unable to ioremap registers.\n" ); +return PTR_ERR (ctx->base); + } + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) { +dev_err (dev,"Unable to find IRQ.\n" ); +return -ENODEV ; + } + + rc =devm_request_irq (dev, irq, aspeed_xdma_irq,IRQF_SHARED , +DEVICE_NAME , ctx); +if (rc <0 ) { +dev_err (dev,"Unable to request IRQ %d.\n" , irq); +return rc; + } + + ctx->clock =devm_clk_get (dev,NULL ); +if (IS_ERR (ctx->clock)) { +dev_err (dev,"Unable to request clock.\n" ); +return PTR_ERR (ctx->clock); + } + + ctx->reset =devm_reset_control_get_exclusive (dev,NULL ); +if (IS_ERR (ctx->reset)) { +dev_err (dev,"Unable to request reset control.\n" );drivers/soc/aspeed/aspeed-xdma.c line 785
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+return PTR_ERR (ctx->reset); + } + + ctx->vga_pool =devm_gen_pool_create (dev,ilog2 (PAGE_SIZE ),-1 ,NULL ); +if (!ctx->vga_pool) { +dev_err (dev,"Unable to setup genalloc pool.\n" ); +return -ENOMEM ; + } + +clk_prepare_enable (ctx->clock);Check for errors
drivers/soc/aspeed/aspeed-xdma.c line 788
Quoted 3 lines
drivers/soc/aspeed/aspeed-xdma.c new file +3
-0+msleep (XDMA_RESET_TIME_MS ); + +reset_control_deassert (ctx->reset);Check for errors.
Quoted 24 lines
drivers/soc/aspeed/aspeed-xdma.c new file +24
-0+msleep (XDMA_RESET_TIME_MS ); + + rc =aspeed_xdma_init (ctx); +if (rc) { +reset_control_assert (ctx->reset); +clk_disable_unprepare (ctx->clock); +return rc; + } + +aspeed_xdma_init_eng (ctx); + +/* +* This interrupt could fire immediately so only request it once the +* engine and driver are initialized. +*/ + pcie_irq =platform_get_irq (pdev,1 ); +if (pcie_irq <0 ) { +dev_warn (dev,"Unable to find PCI-E IRQ.\n" ); + }else { + rc =devm_request_irq (dev, pcie_irq, aspeed_xdma_pcie_irq, +IRQF_SHARED ,DEVICE_NAME , ctx); +if (rc <0 ) +dev_warn (dev,"Unable to request PCI-E IRQ %d.\n" , rc); + }drivers/soc/aspeed/aspeed-xdma.c line 822
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c new file +10
-0+ +return 0 ; +} + +static int aspeed_xdma_remove (struct platform_device *pdev) +{ +struct aspeed_xdma *ctx =platform_get_drvdata (pdev); + +gen_pool_free (ctx->vga_pool, (unsigned long )ctx->cmdq_vga_virt, +XDMA_CMDQ_SIZE );You've used
devm_gen_pool_create(), so no need to explicitly free it.drivers/soc/aspeed/aspeed-xdma.c line 822
Quoted 1 line
drivers/soc/aspeed/aspeed-xdma.c new file +1
-0+iounmap (ctx->vga_virt);This is unnecessary if we use
devm_ioremap()as suggested above.drivers/soc/aspeed/aspeed-xdma.c line 834
Quoted 11 lines
drivers/soc/aspeed/aspeed-xdma.c new file +11
-0+ +reset_control_assert (ctx->reset); +clk_disable_unprepare (ctx->clock); + +return 0 ; +} + +static const struct of_device_id aspeed_xdma_match[] = { + { + .compatible ="aspeed,ast2500-xdma" , + .data = (void *)xdma_ast2500,I'd prefer you create a struct as discussed throughout.
Quoted 61 lines
drivers/soc/aspeed/aspeed-xdma.c new file +22
-0+ }, + { + .compatible = "aspeed,ast2600-xdma", + .data = (void *)xdma_ast2600, + }, + { }, +}; + +static struct platform_driver aspeed_xdma_driver = { + .probe = aspeed_xdma_probe, + .remove = aspeed_xdma_remove, + .driver = { + .name =DEVICE_NAME , + .of_match_table = aspeed_xdma_match, + }, +}; + +module_platform_driver (aspeed_xdma_driver); + +MODULE_AUTHOR ("Eddie James" ); +MODULE_DESCRIPTION ("Aspeed XDMA Engine Driver" ); +MODULE_LICENSE ("GPL v2" );include/uapi/linux/aspeed-xdma.h new file +33
-0@@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* Copyright IBM Corp 2019 */ + +#ifndef _UAPI_LINUX_ASPEED_XDMA_H_ +#define _UAPI_LINUX_ASPEED_XDMA_H_ + +#include <linux/types.h> + +/* +* aspeed_xdma_direction +* +* ASPEED_XDMA_DIRECTION_DOWNSTREAM: transfers data from the host to the BMC +* +* ASPEED_XDMA_DIRECTION_UPSTREAM: transfers data from the BMC to the host +* +* ASPEED_XDMA_DIRECTION_RESET: resets the XDMA engine +*/ +enum aspeed_xdma_direction { +ASPEED_XDMA_DIRECTION_DOWNSTREAM =0 , +ASPEED_XDMA_DIRECTION_UPSTREAM , +ASPEED_XDMA_DIRECTION_RESET , +}; + +/* +* aspeed_xdma_op +* +* host_addr: the DMA address on the host side, typically configured by PCI +* subsystem +* +* len: the size of the transfer in bytes +* +* direction: an enumerator indicating the direction of the DMA operation; see +* enum aspeed_xdma_direction Quoted 8 lines
include/uapi/linux/aspeed-xdma.h line 37
Quoted 4 lines
include/uapi/linux/aspeed-xdma.h new file +4
-0+* +* bmc_addr: the virtual address to DMA on the BMC side; this parameter is +* unused on current platforms since the XDMA engine is restricted to +* accessing the VGA memory space This doesn't make sense to me - if it's a virtual address then talking about the VGA space doesn't make sense to me as where the memory lives is an implementation detail. If the parameter is a physical address then it makes sense, but we'd always want it specified regardless?
Quoted 4 lines
As the comment says, it's unused. I added the parameter to future-proof the API in case the engine is configured differently, allowing arbitrary memory access by the engine. In that case, the user would pass the virtual address of their data.
Hmm. Wouldn't we still use the mmap() interface and derive the addresses that way regardless of where the backing memory is located? What do you think the model of interaction would be if we made use of this parameter?
Andrew
Re: [PATCH 07/12] drivers/soc: xdma: Add user interface
In reply to Eddie JamesQuoted 97 lines · Eddie James
Quoted 64 lines · Andrew Jeffery
Quoted 39 lines · Eddie James
This commits adds a miscdevice to provide a user interface to the XDMA engine. The interface provides the write operation to start DMA operations. The DMA parameters are passed as the data to the write call. The actual data to transfer is NOT passed through write. Note that both directions of DMA operation are accomplished through the write command; BMC to host and host to BMC.
The XDMA engine is restricted to only accessing the reserved memory space on the AST2500, typically used by the VGA. For this reason, the VGA memory space is pooled and allocated with genalloc. Users calling mmap allocate pages from this pool for their usage. The space allocated by a client will be the space used in the DMA operation. For an "upstream" (BMC to host) operation, the data in the client's area will be transferred to the host. For a "downstream" (host to BMC) operation, the host data will be placed in the client's memory area.
Poll is also provided in order to determine when the DMA operation is complete for non-blocking IO.
Signed-off-by Eddie James <[email protected]>--- drivers/soc/aspeed/aspeed-xdma.c | 223 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+)drivers/soc/aspeed/aspeed-xdma.c +3
-0@@ -64,6 +64,9 @@#define XDMA_CMDQ_SIZE PAGE_SIZE#define XDMA_NUM_CMDS \ (XDMA_CMDQ_SIZE / sizeof(struct aspeed_xdma_cmd)) +#define XDMA_OP_SIZE_MAX sizeof(struct aspeed_xdma_op) +#define XDMA_OP_SIZE_MIN \ + (sizeof(struct aspeed_xdma_op) - sizeof(u64))/* Aspeed specification requires 10ms after switching the reset line */ #define XDMA_RESET_TIME_MS 10drivers/soc/aspeed/aspeed-xdma.c struct aspeed_xdma { · line 222
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c +1
-0@@ -216,6 +219,7 @@ struct aspeed_xdma {bool in_reset;bool upstream;unsigned int cmd_idx; +struct mutex file_lock;Please add documentation about what data
file_lockis protecting.Quoted 17 lines
drivers/soc/aspeed/aspeed-xdma.c +2
-0struct mutex start_lock;struct delayed_work reset_work;spinlock_t client_lock;@@ -230,6 +234,8 @@ struct aspeed_xdma {dma_addr_t cmdq_vga_phys;void *cmdq_vga_virt;struct gen_pool *vga_pool; + +struct miscdevice misc; };struct aspeed_xdma_client {@@ -557,6 +563,204 @@ static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg)return IRQ_HANDLED ; }Quoted 16 lines
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c +5
-0+static ssize_t aspeed_xdma_write (struct file *file,const char __user *buf, +size_t len,loff_t *offset) +{ +int rc; +struct aspeed_xdma_op op;drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 580
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; +u32 offs = client->phys ? (client->phys - ctx->vga_phys) : +XDMA_CMDQ_SIZE ; + +if (len <XDMA_OP_SIZE_MIN ) +return -EINVAL ; + +if (len >XDMA_OP_SIZE_MAX ) + len =XDMA_OP_SIZE_MAX ;Isn't this an EINVAL case as well?
Perhaps so.
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 586
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c +6
-0+ + rc =copy_from_user (&op, buf, len); +if (rc) +return rc; + +if (op.direction ==ASPEED_XDMA_DIRECTION_RESET ) {Seems a bit abusive to use the direction field to issue a reset.
Quoted 1 line
What would you recommend instead?
Looks like an ioctl() to me. But what need do we have to directly reset the device? Could we achieve the same by rebinding the driver if necessary? We should only need to reset it if the driver has bugs, or is there some errata that we need to deal with? Userspace shouldn't be handling that though?
Quoted 29 lines
Quoted 19 lines
Quoted 19 lines
drivers/soc/aspeed/aspeed-xdma.c +16
-0+mutex_lock (&ctx->start_lock); + +if (aspeed_xdma_reset_start (ctx)) { +msleep (XDMA_RESET_TIME_MS ); + +aspeed_xdma_reset_finish (ctx); + } + +mutex_unlock (&ctx->start_lock); + +return len; + }else if (op.direction >ASPEED_XDMA_DIRECTION_RESET ) { +return -EINVAL ; + } + +if (op.len > ctx->vga_size - offs)Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 609
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c +7
-0+return -EINVAL ; + +if (file->f_flags &O_NONBLOCK ) { +if (!mutex_trylock (&ctx->file_lock)) +return -EAGAIN ; + +if (ctx->in_progress || ctx->in_reset) {
ctx->in_progresswas protected by a lock that isn'tfile_lock, so this looks wrong.
Quoted 2 lines
file_lockisn't protectingin_progress. It's protecting access to the whole engine while a transfer is in progress.
Then when would we ever gain file_lock if in_progress was set? Shouldn't the current client hold file_lock until we'd set in_progress to false, in which case we wouldn't need to check in_progress if we now hold the lock?
Quoted 1 line
in_progressisn't protected at all,
Except it is, because you've acquired file_lock above before checking it (and in_reset).
And why is in_progress written to under ctx->start_lock (which is not file_lock) in aspeed_xdma_start() in the earlier patch if it's not protected?
Quoted 1 line
it's just better to lock
There's never a case of "it's just better to lock", as if it were optional. Either the variable needs to be protected against concurrent access or it doesn't. If it does, always access it under a consistent lock.
Quoted 3 lines
before waiting for
in_progressso that multiple clients don't all seein_progressgo false and have to wait for a mutex (particularly in the nonblocking case).
Yes, so what you're suggesting is that in_progress needs to be protected against concurrent access, so needs to be accessed under a consistent lock. Though as suggested above it might be enough to successfully acquire file_lock.
As far as I can see we have three events that we need to care about:
1. Submission of a DMA request
2. Completion of a DMA request
3. PCIe-driven reset
For 1, multiple concurrent submissions need to be serialised, so we need a mutex with the semantics of file_lock as you've described above.
2 should only occur if we have an event of type 1 outstanding. If 1 is outstanding then receiving 2 should cause the process that triggered 1 to wake and release the mutex.
3 can happen at any time which results in two cases that we need to care about:
3a. DMA request in progress (i.e. 1 but have not yet seen corresponding 2) 3b. DMA idle (no request in progress)
Events of type 1 need to be serialised against 3. 2 won't occur after 3 until 1 has occurred, so there's no need to consider it in the serialisation for 3.
In the case of 3a. we need to reset the device, then mark the current transfer failed, then wake the associated process. The woken process will release the mutex and allow any queued requests to proceed.
3b is much simpler, though we need to prevent events of type 1 concurrently accessing the device while the reset is in progress. So we need a spinlock to cover configuring the device.
So that's two locks - a mutex to serialise process-context access to the device, and a spinlock to serialise interrupts with respect to process-context access. Currently your implementation contains two mutexes (start_lock and file_lock) and two spinlocks (client_lock and reset_lock), all with fairly hazy definitions.
Quoted 116 lines
Quoted 23 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 617
Quoted 11 lines
drivers/soc/aspeed/aspeed-xdma.c +8
-0+mutex_unlock (&ctx->file_lock); +return -EAGAIN ; + } + }else { +mutex_lock (&ctx->file_lock); + + rc =wait_event_interruptible (ctx->wait, !ctx->in_progress && + !ctx->in_reset);As above.
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+if (rc) { +mutex_unlock (&ctx->file_lock); +return -EINTR ; + } + } + +aspeed_xdma_start (ctx, &op, ctx->vga_phys + offs, client); + +mutex_unlock (&ctx->file_lock); +Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 634
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c +7
-0+if (!(file->f_flags &O_NONBLOCK )) { + rc =wait_event_interruptible (ctx->wait, !ctx->in_progress); +if (rc) +return -EINTR ; + +if (client->error) +return -EIO ;What's the
client->errorvalue? Can it be more informative?Not really. There isn't much error information available. Basically the only way to get an error is if the engine is reset (user or PCIE initiated) while the transfer is on-going.
Quoted 11 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 597
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c +3
-0+ } + +return len;We've potentially truncated len above (in the len >
XDMA_OP_SIZE_MAX), which leads to some ambiguity with thewrite()syscall given that it can potentially return less than the requested length. This is one such case, but the caller probably shouldn't attempt a follow-up write.This would go away if we make the len >
XDMA_OP_SIZE_MAXan EINVAL case as suggested agove.Sure.
Quoted 52 lines
Quoted 52 lines
drivers/soc/aspeed/aspeed-xdma.c +51
-0+} + +static __poll_t aspeed_xdma_poll (struct file *file, +struct poll_table_struct *wait) +{ +__poll_t mask =0 ; +__poll_t req =poll_requested_events (wait); +struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; + +if (req & (EPOLLIN |EPOLLRDNORM )) { +if (client->in_progress) +poll_wait (file, &ctx->wait, wait); + +if (!client->in_progress) { +if (client->error) + mask |=EPOLLERR ; +else + mask |=EPOLLIN |EPOLLRDNORM ; + } + } + +if (req & (EPOLLOUT |EPOLLWRNORM )) { +if (ctx->in_progress) +poll_wait (file, &ctx->wait, wait); + +if (!ctx->in_progress) + mask |=EPOLLOUT |EPOLLWRNORM ; + } + +return mask; +} + +static void aspeed_xdma_vma_close (struct vm_area_struct *vma) +{ +struct aspeed_xdma_client *client = vma->vm_private_data; + +gen_pool_free (client->ctx->vga_pool, (unsigned long )client->virt, + client->size); + + client->virt =NULL ; + client->phys =0 ; + client->size =0 ; +} + +static const struct vm_operations_struct aspeed_xdma_vm_ops = { + .close = aspeed_xdma_vma_close, +}; + +static int aspeed_xdma_mmap (struct file *file,struct vm_area_struct *vma) +{Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 695
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c +7
-0+int rc; +struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; + +/* restrict file to one mapping */ +if (client->size) +return -ENOMEM ;Can we do better with the error code here?
Quoted 1 line
Maybe? I'm open to suggestions...
How about EBUSY?
Quoted 17 lines
Quoted 15 lines
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c +1
-0+drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 706
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+ client->size = vma->vm_end - vma->vm_start; + client->virt =gen_pool_dma_alloc (ctx->vga_pool, client->size, + &client->phys); +if (!client->virt) { + client->phys =0 ; + client->size =0 ; +return -ENOMEM ; + } + + vma->vm_pgoff = (client->phys - ctx->vga_phys) >>PAGE_SHIFT ;Where does
client->physget set?
Quoted 1 line
gen_pool_dma_allocsets it.
Ah, yes. Thanks.
Andrew
Eddie James
maintainerRe: [PATCH 07/12] drivers/soc: xdma: Add user interface
Quoted 91 lines · Andrew Jeffery
Quoted 90 lines · Eddie James
Quoted 63 lines · Andrew Jeffery
Quoted 39 lines · Eddie James
This commits adds a miscdevice to provide a user interface to the XDMA engine. The interface provides the write operation to start DMA operations. The DMA parameters are passed as the data to the write call. The actual data to transfer is NOT passed through write. Note that both directions of DMA operation are accomplished through the write command; BMC to host and host to BMC.
The XDMA engine is restricted to only accessing the reserved memory space on the AST2500, typically used by the VGA. For this reason, the VGA memory space is pooled and allocated with genalloc. Users calling mmap allocate pages from this pool for their usage. The space allocated by a client will be the space used in the DMA operation. For an "upstream" (BMC to host) operation, the data in the client's area will be transferred to the host. For a "downstream" (host to BMC) operation, the host data will be placed in the client's memory area.
Poll is also provided in order to determine when the DMA operation is complete for non-blocking IO.
Signed-off-by Eddie James<[email protected]>--- drivers/soc/aspeed/aspeed-xdma.c | 223 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+)drivers/soc/aspeed/aspeed-xdma.c +3
-0@@ -64,6 +64,9 @@#define XDMA_CMDQ_SIZE PAGE_SIZE#define XDMA_NUM_CMDS \ (XDMA_CMDQ_SIZE / sizeof(struct aspeed_xdma_cmd)) +#define XDMA_OP_SIZE_MAX sizeof(struct aspeed_xdma_op) +#define XDMA_OP_SIZE_MIN \ + (sizeof(struct aspeed_xdma_op) - sizeof(u64))/* Aspeed specification requires 10ms after switching the reset line */ #define XDMA_RESET_TIME_MS 10drivers/soc/aspeed/aspeed-xdma.c struct aspeed_xdma { · line 222
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c +1
-0@@ -216,6 +219,7 @@ struct aspeed_xdma {bool in_reset;bool upstream;unsigned int cmd_idx; +struct mutex file_lock;Please add documentation about what data
file_lockis protecting.Quoted 17 lines
drivers/soc/aspeed/aspeed-xdma.c +2
-0struct mutex start_lock;struct delayed_work reset_work;spinlock_t client_lock;@@ -230,6 +234,8 @@ struct aspeed_xdma {dma_addr_t cmdq_vga_phys;void *cmdq_vga_virt;struct gen_pool *vga_pool; + +struct miscdevice misc; };struct aspeed_xdma_client {@@ -557,6 +563,204 @@ static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg)return IRQ_HANDLED ; }Quoted 16 lines
Quoted 5 lines
drivers/soc/aspeed/aspeed-xdma.c +5
-0+static ssize_t aspeed_xdma_write (struct file *file,const char __user *buf, +size_t len,loff_t *offset) +{ +int rc; +struct aspeed_xdma_op op;drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 580
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; +u32 offs = client->phys ? (client->phys - ctx->vga_phys) : +XDMA_CMDQ_SIZE ; + +if (len <XDMA_OP_SIZE_MIN ) +return -EINVAL ; + +if (len >XDMA_OP_SIZE_MAX ) + len =XDMA_OP_SIZE_MAX ;Isn't this an EINVAL case as well?
Perhaps so.
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 586
Quoted 6 lines
drivers/soc/aspeed/aspeed-xdma.c +6
-0+ + rc =copy_from_user (&op, buf, len); +if (rc) +return rc; + +if (op.direction ==ASPEED_XDMA_DIRECTION_RESET ) {Seems a bit abusive to use the direction field to issue a reset.
Quoted 6 lines
Quoted 1 line
What would you recommend instead?
Looks like an
ioctl()to me. But what need do we have to directly reset the device? Could we achieve the same by rebinding the driver if necessary? We should only need to reset it if the driver has bugs, or is there some errata that we need to deal with? Userspace shouldn't be handling that though?
Well it could be necessary to reset if userspace messes up and sends a bad host address for example, so that's why I'd like to have it available to userspace.
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 13 lines
drivers/soc/aspeed/aspeed-xdma.c +13
-0+mutex_lock (&ctx->start_lock); + +if (aspeed_xdma_reset_start (ctx)) { +msleep (XDMA_RESET_TIME_MS ); + +aspeed_xdma_reset_finish (ctx); + } + +mutex_unlock (&ctx->start_lock); + +return len; + }else if (op.direction >ASPEED_XDMA_DIRECTION_RESET ) { +return -EINVAL ;drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 609
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+ } + +if (op.len > ctx->vga_size - offs) +return -EINVAL ; + +if (file->f_flags &O_NONBLOCK ) { +if (!mutex_trylock (&ctx->file_lock)) +return -EAGAIN ; + +if (ctx->in_progress || ctx->in_reset) {
ctx->in_progresswas protected by a lock that isn'tfile_lock, so this looks wrong.
Quoted 5 lines
Quoted 2 lines
file_lockisn't protectingin_progress. It's protecting access to the whole engine while a transfer is in progress.Then when would we ever gain
file_lockifin_progresswas set? Shouldn't the current client holdfile_lockuntil we'd setin_progressto false, in which case we wouldn't need to checkin_progressif we now hold the lock?
That doesn't work for non-blocking io.
Quoted 6 lines
Quoted 1 line
in_progressisn't protected at all,Except it is, because you've acquired
file_lockabove before checking it (andin_reset).And why is
in_progresswritten to underctx->start_lock(which is notfile_lock) inaspeed_xdma_start()in the earlier patch if it's not protected?
OK, I just didn't quite get what you meant by protected. Yes, multiple reads here of in_progress must be serialized so that only one thread sees it go false at once. This prevents multiple transfers from being started while one is in progress. But writing it doesn't require locking that I can see.
Quoted 4 lines
Quoted 1 line
it's just better to lock
There's never a case of "it's just better to lock", as if it were optional. Either the variable needs to be protected against concurrent access or it doesn't. If it does, always access it under a consistent lock.
Not what I meant, was trying to say better to lock before waiting (rather than after). However now that I think again, that wouldn't work to prevent multiple transfers being started while one is in progress.
Quoted 12 lines
Quoted 3 lines
before waiting for
in_progressso that multiple clients don't all seein_progressgo false and have to wait for a mutex (particularly in the nonblocking case).Yes, so what you're suggesting is that
in_progressneeds to be protected against concurrent access, so needs to be accessed under a consistent lock. Though as suggested above it might be enough to successfully acquirefile_lock. As far as I can see we have three events that we need to care about:1. Submission of a DMA request
2. Completion of a DMA request
3. PCIe-driven reset
Quoted 6 lines
For 1, multiple concurrent submissions need to be serialised, so we need a mutex with the semantics of
file_lockas you've described above.2 should only occur if we have an event of type 1 outstanding. If 1 is outstanding then receiving 2 should cause the process that triggered 1 to wake and release the mutex.
This gets more complicated than that because we need non-blocking io; the mutex can't be held while the client call exits with EAGAIN.
Quoted 126 lines
3 can happen at any time which results in two cases that we need to care about:
3a. DMA request in progress (i.e. 1 but have not yet seen corresponding 2) 3b. DMA idle (no request in progress)
Events of type 1 need to be serialised against 3. 2 won't occur after 3 until 1 has occurred, so there's no need to consider it in the serialisation for 3.
In the case of 3a. we need to reset the device, then mark the current transfer failed, then wake the associated process. The woken process will release the mutex and allow any queued requests to proceed.
3b is much simpler, though we need to prevent events of type 1 concurrently accessing the device while the reset is in progress. So we need a spinlock to cover configuring the device.
So that's two locks - a mutex to serialise process-context access to the device, and a spinlock to serialise interrupts with respect to process-context access. Currently your implementation contains two mutexes (
start_lockandfile_lock) and two spinlocks (client_lockandreset_lock), all with fairly hazy definitions.Quoted 105 lines
Quoted 20 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 617
Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c +8
-0+mutex_unlock (&ctx->file_lock); +return -EAGAIN ; + } + }else { +mutex_lock (&ctx->file_lock); + + rc =wait_event_interruptible (ctx->wait, !ctx->in_progress && + !ctx->in_reset);As above.
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+if (rc) { +mutex_unlock (&ctx->file_lock); +return -EINTR ; + } + } + +aspeed_xdma_start (ctx, &op, ctx->vga_phys + offs, client); + +mutex_unlock (&ctx->file_lock); +Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 634
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c +7
-0+if (!(file->f_flags &O_NONBLOCK )) { + rc =wait_event_interruptible (ctx->wait, !ctx->in_progress); +if (rc) +return -EINTR ; + +if (client->error) +return -EIO ;What's the
client->errorvalue? Can it be more informative?Not really. There isn't much error information available. Basically the only way to get an error is if the engine is reset (user or PCIE initiated) while the transfer is on-going.
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 597
Quoted 3 lines
drivers/soc/aspeed/aspeed-xdma.c +3
-0+ } + +return len;We've potentially truncated len above (in the len >
XDMA_OP_SIZE_MAX), which leads to some ambiguity with thewrite()syscall given that it can potentially return less than the requested length. This is one such case, but the caller probably shouldn't attempt a follow-up write.This would go away if we make the len >
XDMA_OP_SIZE_MAXan EINVAL case as suggested agove.Sure.
Quoted 59 lines
Quoted 48 lines
drivers/soc/aspeed/aspeed-xdma.c +48
-0+} + +static __poll_t aspeed_xdma_poll (struct file *file, +struct poll_table_struct *wait) +{ +__poll_t mask =0 ; +__poll_t req =poll_requested_events (wait); +struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; + +if (req & (EPOLLIN |EPOLLRDNORM )) { +if (client->in_progress) +poll_wait (file, &ctx->wait, wait); + +if (!client->in_progress) { +if (client->error) + mask |=EPOLLERR ; +else + mask |=EPOLLIN |EPOLLRDNORM ; + } + } + +if (req & (EPOLLOUT |EPOLLWRNORM )) { +if (ctx->in_progress) +poll_wait (file, &ctx->wait, wait); + +if (!ctx->in_progress) + mask |=EPOLLOUT |EPOLLWRNORM ; + } + +return mask; +} + +static void aspeed_xdma_vma_close (struct vm_area_struct *vma) +{ +struct aspeed_xdma_client *client = vma->vm_private_data; + +gen_pool_free (client->ctx->vga_pool, (unsigned long )client->virt, + client->size); + + client->virt =NULL ; + client->phys =0 ; + client->size =0 ; +} + +static const struct vm_operations_struct aspeed_xdma_vm_ops = { + .close = aspeed_xdma_vma_close, +};drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 695
Quoted 10 lines
drivers/soc/aspeed/aspeed-xdma.c +10
-0+ +static int aspeed_xdma_mmap (struct file *file,struct vm_area_struct *vma) +{ +int rc; +struct aspeed_xdma_client *client = file->private_data; +struct aspeed_xdma *ctx = client->ctx; + +/* restrict file to one mapping */ +if (client->size) +return -ENOMEM ;Can we do better with the error code here?
Quoted 2 lines
Quoted 1 line
Maybe? I'm open to suggestions...
How about EBUSY?
Sounds good.
Quoted 16 lines
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
drivers/soc/aspeed/aspeed-xdma.c +4
-0+ + client->size = vma->vm_end - vma->vm_start; + client->virt =gen_pool_dma_alloc (ctx->vga_pool, client->size, + &client->phys);Quoted 8 lines
drivers/soc/aspeed/aspeed-xdma.c static irqreturn_t aspeed_xdma_pcie_irq(int irq, void *arg) · line 706
Quoted 7 lines
drivers/soc/aspeed/aspeed-xdma.c +7
-0+if (!client->virt) { + client->phys =0 ; + client->size =0 ; +return -ENOMEM ; + } + + vma->vm_pgoff = (client->phys - ctx->vga_phys) >>PAGE_SHIFT ;Where does
client->physget set?Quoted 1 line
gen_pool_dma_allocsets it.Ah, yes. Thanks.
Andrew