Fishwaldo commented on code in PR #19745:
URL: https://github.com/apache/nuttx/pull/19745#discussion_r3788718789
##########
drivers/usbhost/usbhost_xhci_pci.c:
##########
@@ -532,4391 +122,133 @@ static struct pci_driver_s g_pci_xhci_drv =
* Private Functions
****************************************************************************/
-/* Every register accessor below forces the value through a register with
- * an empty asm. Access width is part of the register interface: xHCI
- * requires aligned accesses of the register's own size, and a controller
- * may ignore anything narrower (QEMU's does). A volatile load does not
- * pin the width; GCC 16 at -Os narrows "load 32, test bit 0" to a byte
- * load. A value demanded in a register can only come from the full-width
- * access. The same constraint on stores stops a load-modify-store being
- * folded back into one instruction.
- */
-
-/****************************************************************************
- * Name: xhci_capa_getreg
- *
- * Description:
- * Get register (USB Legacy Support Capability)
- *
- ****************************************************************************/
-
-static uint32_t xhci_capa_getreg(FAR struct usbhost_xhci_s *priv,
- unsigned int offset)
-{
- uintptr_t addr = priv->capa_base + offset;
- uint32_t regval = *((FAR volatile uint32_t *)addr);
-
- __asm__ __volatile__("" : "+r"(regval));
- return regval;
-}
-
-/****************************************************************************
- * Name: xhci_capa_getreg_1b
- *
- * Description:
- * Get 1B register (USB Legacy Support Capability)
- *
- ****************************************************************************/
-
-static uint8_t xhci_capa_getreg_1b(FAR struct usbhost_xhci_s *priv,
- unsigned int offset)
-{
- uintptr_t addr = priv->capa_base + offset;
- uint8_t regval = *((FAR volatile uint8_t *)addr);
-
- __asm__ __volatile__("" : "+r"(regval));
- return regval;
-}
-
-/****************************************************************************
- * Name: xhci_capa_putreg_1b
- *
- * Description:
- * Put 1B register (USB Legacy Support Capability)
- *
- ****************************************************************************/
-
-static void xhci_capa_putreg_1b(FAR struct usbhost_xhci_s *priv,
- unsigned int offset,
- uint8_t value)
-{
- uintptr_t addr = priv->capa_base + offset;
-
- __asm__ __volatile__("" : "+r"(value));
- *((FAR volatile uint8_t *)addr) = value;
-}
-
-/****************************************************************************
- * Name: xhci_oper_getreg
- *
- * Description:
- * Get register (Host Controller Operational Registers)
- *
- ****************************************************************************/
-
-static uint32_t xhci_oper_getreg(FAR struct usbhost_xhci_s *priv,
- unsigned int offset)
-{
- uintptr_t addr = priv->oper_base + offset;
- uint32_t regval = *((FAR volatile uint32_t *)addr);
-
- __asm__ __volatile__("" : "+r"(regval));
- return regval;
-}
-
-/****************************************************************************
- * Name: xhci_oper_putreg
- *
- * Description:
- * Put register (Host Controller Operational Registers)
- *
- ****************************************************************************/
-
-static void xhci_oper_putreg(FAR struct usbhost_xhci_s *priv,
- unsigned int offset,
- uint32_t value)
-{
- uintptr_t addr = priv->oper_base + offset;
-
- __asm__ __volatile__("" : "+r"(value));
- *((FAR volatile uint32_t *)addr) = value;
-}
-
/****************************************************************************
- * Name: xhci_oper_putreg_8b
+ * Name: pci_xhci_irq_attach
*
* Description:
- * Put register (Host Controller Operational Registers)
+ * Give the controller an interrupt. On PCI that means asking for a
+ * message rather than finding a wire, so the vector is allocated here and
+ * only then attached.
*
****************************************************************************/
-static void xhci_oper_putreg_8b(FAR struct usbhost_xhci_s *priv,
- unsigned int offset,
- uint64_t value)
+static int pci_xhci_irq_attach(FAR void *arg, xcpt_t handler, FAR void *priv)
{
- uintptr_t addr = priv->oper_base + offset;
-
- __asm__ __volatile__("" : "+r"(value));
- *((FAR volatile uint64_t *)addr) = value;
-}
+ FAR struct pci_xhci_s *pcix = arg;
+ int ret;
-/****************************************************************************
- * Name: xhci_runt_getreg
- *
- * Description:
- * Get register (Host Controller Runtime Registers)
- *
- ****************************************************************************/
+ ret = pci_alloc_irq(pcix->dev, &pcix->irq, 1);
+ if (ret != 1)
+ {
+ pcierr("Failed to allocate MSI %d\n", ret);
+ return ret;
+ }
-static uint32_t xhci_runt_getreg(FAR struct usbhost_xhci_s *priv,
- unsigned int offset)
-{
- uintptr_t addr = priv->runt_base + offset;
- uint32_t regval = *((FAR volatile uint32_t *)addr);
+ irq_attach(pcix->irq, handler, priv);
- __asm__ __volatile__("" : "+r"(regval));
- return regval;
-}
+ ret = pci_connect_irq(pcix->dev, &pcix->irq, 1);
+ if (ret != OK)
+ {
+ pcierr("Failed to connect MSI %d\n", ret);
+ pci_release_irq(pcix->dev, &pcix->irq, 1);
-/****************************************************************************
- * Name: xhci_runt_putreg
- *
- * Description:
- * Put register (Host Controller Runtime Registers)
- *
- ****************************************************************************/
+ return -ENOTSUP;
+ }
-static void xhci_runt_putreg(FAR struct usbhost_xhci_s *priv,
- unsigned int offset,
- uint32_t value)
-{
- uintptr_t addr = priv->runt_base + offset;
+ up_enable_irq(pcix->irq);
- __asm__ __volatile__("" : "+r"(value));
- *((FAR volatile uint32_t *)addr) = value;
+ return OK;
}
/****************************************************************************
- * Name: xhci_runt_putreg_8b
- *
- * Description:
- * Put register (Host Controller Runtime Registers)
- *
+ * Name: pci_xhci_irq_detach
****************************************************************************/
-static void xhci_runt_putreg_8b(FAR struct usbhost_xhci_s *priv,
- unsigned int offset,
- uint64_t value)
+static void pci_xhci_irq_detach(FAR void *arg)
{
- uintptr_t addr = priv->runt_base + offset;
+ FAR struct pci_xhci_s *pcix = arg;
- __asm__ __volatile__("" : "+r"(value));
- *((FAR volatile uint64_t *)addr) = value;
+ pci_release_irq(pcix->dev, &pcix->irq, 1);
Review Comment:
Fixed. Thanks for that catch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]