Linux-ARM-Kernel Archive mirror
 help / color / mirror / Atom feed
From: Herve Codina <herve.codina@bootlin.com>
To: <Steen.Hegelund@microchip.com>
Cc: <tglx@linutronix.de>, <robh@kernel.org>, <krzk+dt@kernel.org>,
	<conor+dt@kernel.org>, <davem@davemloft.net>,
	<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>,
	<lee@kernel.org>, <arnd@arndb.de>, <Horatiu.Vultur@microchip.com>,
	<UNGLinuxDriver@microchip.com>, <andrew@lunn.ch>,
	<hkallweit1@gmail.com>, <linux@armlinux.org.uk>,
	<saravanak@google.com>, <bhelgaas@google.com>,
	<p.zabel@pengutronix.de>, <Lars.Povlsen@microchip.com>,
	<Daniel.Machon@microchip.com>, <alexandre.belloni@bootlin.com>,
	<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<netdev@vger.kernel.org>, <linux-pci@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<Allan.Nielsen@microchip.com>, <luca.ceresoli@bootlin.com>,
	<thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH 16/17] mfd: Add support for LAN966x PCI device
Date: Tue, 14 May 2024 14:55:18 +0200	[thread overview]
Message-ID: <20240514145518.3e989b83@bootlin.com> (raw)
In-Reply-To: <D1447AHUWV6C.13V6FOWZ80GH@microchip.com>

Hi Steen,

On Wed, 8 May 2024 08:20:04 +0000
<Steen.Hegelund@microchip.com> wrote:

...
> > +
> > +static irqreturn_t pci_dev_irq_handler(int irq, void *data)
> > +{
> > +       struct pci_dev_intr_ctrl *intr_ctrl = data;
> > +       int ret;
> > +
> > +       ret = generic_handle_domain_irq(intr_ctrl->irq_domain, 0);
> > +       return ret ? IRQ_NONE : IRQ_HANDLED;
> > +}
> > +
> > +static struct pci_dev_intr_ctrl *pci_dev_create_intr_ctrl(struct pci_dev *pdev)
> > +{
> > +       struct pci_dev_intr_ctrl *intr_ctrl;
> > +       struct fwnode_handle *fwnode;
> > +       int ret;
> > +
> > +       if (!pdev->irq)
> > +               return ERR_PTR(-EOPNOTSUPP);
> > +
> > +       fwnode = dev_fwnode(&pdev->dev);
> > +       if (!fwnode)
> > +               return ERR_PTR(-ENODEV);
> > +
> > +       intr_ctrl = kmalloc(sizeof(*intr_ctrl), GFP_KERNEL);
> > +       if (!intr_ctrl)
> > +               return ERR_PTR(-ENOMEM);
> > +
> > +       intr_ctrl->pci_dev = pdev;
> > +
> > +       intr_ctrl->irq_domain = irq_domain_create_linear(fwnode, 1, &pci_dev_irq_domain_ops,
> > +                                                        intr_ctrl);
> > +       if (!intr_ctrl->irq_domain) {
> > +               pci_err(pdev, "Failed to create irqdomain\n");
> > +               ret = -ENOMEM;
> > +               goto err_free_intr_ctrl;
> > +       }
> > +
> > +       ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_LEGACY);
> > +       if (ret < 0) {
> > +               pci_err(pdev, "Unable alloc irq vector (%d)\n", ret);
> > +               goto err_remove_domain;
> > +       }
> > +       intr_ctrl->irq = pci_irq_vector(pdev, 0);
> > +       ret = request_irq(intr_ctrl->irq, pci_dev_irq_handler, IRQF_SHARED,
> > +                         dev_name(&pdev->dev), intr_ctrl);
> > +       if (ret) {
> > +               pci_err(pdev, "Unable to request irq %d (%d)\n", intr_ctrl->irq, ret);
> > +               goto err_free_irq_vector;
> > +       }
> > +
> > +       return intr_ctrl;
> > +
> > +err_free_irq_vector:
> > +       pci_free_irq_vectors(pdev);
> > +err_remove_domain:
> > +       irq_domain_remove(intr_ctrl->irq_domain);
> > +err_free_intr_ctrl:
> > +       kfree(intr_ctrl);
> > +       return ERR_PTR(ret);
> > +}
> > +
> > +static void pci_dev_remove_intr_ctrl(struct pci_dev_intr_ctrl *intr_ctrl)
> > +{
> > +       free_irq(intr_ctrl->irq, intr_ctrl);
> > +       pci_free_irq_vectors(intr_ctrl->pci_dev);
> > +       irq_dispose_mapping(irq_find_mapping(intr_ctrl->irq_domain, 0));
> > +       irq_domain_remove(intr_ctrl->irq_domain);
> > +       kfree(intr_ctrl);
> > +}
> > +  
> 
> It looks like the two functions below (and their helper functions) are so
> generic that they could be part of the pci driver core support.
> Any plans for that?

Indeed, I tried to write them in a generic way.
Right now, at least for the next iteration of this series, I don't plan to
move them as part of the PCI code.
This piece of code did not get any feedback and I would prefer to keep them
here for the moment.

Of course, they could be move out of the LAN966x PCI driver later.

> 
> > +static void devm_pci_dev_remove_intr_ctrl(void *data)
> > +{
> > +       struct pci_dev_intr_ctrl *intr_ctrl = data;
> > +
> > +       pci_dev_remove_intr_ctrl(intr_ctrl);
> > +}
> > +
> > +static int devm_pci_dev_create_intr_ctrl(struct pci_dev *pdev)
> > +{
> > +       struct pci_dev_intr_ctrl *intr_ctrl;
> > +
> > +       intr_ctrl = pci_dev_create_intr_ctrl(pdev);
> > +
> > +       if (IS_ERR(intr_ctrl))
> > +               return PTR_ERR(intr_ctrl);
> > +
> > +       return devm_add_action_or_reset(&pdev->dev, devm_pci_dev_remove_intr_ctrl, intr_ctrl);
> > +}
> > +  
> 

Best regards,
Hervé

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2024-05-14 12:55 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30  8:37 [PATCH 00/17] Add support for the LAN966x PCI device using a DT overlay Herve Codina
2024-04-30  8:37 ` [PATCH 01/17] mfd: syscon: Add reference counting and device managed support Herve Codina
2024-04-30 20:34   ` Simon Horman
2024-05-02 13:29     ` Herve Codina
2024-04-30 21:55   ` kernel test robot
2024-04-30 22:07   ` kernel test robot
2024-04-30  8:37 ` [PATCH 02/17] reset: mchp: sparx5: Remove dependencies and allow building as a module Herve Codina
2024-04-30  8:37 ` [PATCH 03/17] reset: mchp: sparx5: Release syscon when not use anymore Herve Codina
2024-04-30  8:37 ` [PATCH 04/17] reset: core: add get_device()/put_device on rcdev Herve Codina
2024-04-30  8:37 ` [PATCH 05/17] reset: mchp: sparx5: set the dev member of the reset controller Herve Codina
2024-04-30  8:37 ` [PATCH 06/17] dt-bindings: net: mscc-miim: Add resets property Herve Codina
2024-04-30 13:55   ` Andrew Lunn
2024-04-30 15:40     ` Herve Codina
2024-04-30 16:31       ` Andrew Lunn
2024-05-02  9:50         ` Herve Codina
2024-05-02 10:31           ` Conor Dooley
2024-05-02 12:26             ` Andrew Lunn
2024-05-02 13:22               ` Alexandre Belloni
2024-05-03 14:21                 ` Herve Codina
2024-04-30  8:37 ` [PATCH 07/17] net: mdio: mscc-miim: Handle the switch reset Herve Codina
2024-04-30  9:21   ` Sai Krishna Gajula
2024-05-02 13:26     ` Herve Codina
2024-04-30 13:46   ` Andrew Lunn
2024-04-30 15:40     ` Herve Codina
2024-04-30  8:37 ` [PATCH 08/17] net: lan966x: remove debugfs directory in probe() error path Herve Codina
2024-04-30 13:57   ` Andrew Lunn
2024-04-30 14:01   ` Andrew Lunn
2024-04-30  8:37 ` [PATCH 09/17] dt-bindings: interrupt-controller: Add support for Microchip LAN966x OIC Herve Codina
2024-05-07 15:28   ` Rob Herring
2024-05-13 12:37     ` Herve Codina
2024-05-13 14:53       ` Rob Herring
2024-05-13 17:04         ` Herve Codina
2024-05-22 14:24   ` Rob Herring (Arm)
2024-04-30  8:37 ` [PATCH 10/17] irqdomain: Add missing parameter descriptions in docs Herve Codina
2024-05-02  0:03   ` Thomas Gleixner
2024-04-30  8:37 ` [PATCH 11/17] irqdomain: Introduce irq_domain_alloc() and irq_domain_publish() Herve Codina
2024-04-30  8:37 ` [PATCH 12/17] irqchip: Add support for LAN966x OIC Herve Codina
2024-04-30 20:24   ` Simon Horman
2024-05-02 13:24     ` Herve Codina
2024-05-01  1:17   ` kernel test robot
2024-05-08  8:08   ` Steen.Hegelund
2024-05-13 12:50     ` Herve Codina
2024-04-30  8:37 ` [PATCH 13/17] MAINTAINERS: Add the Microchip LAN966x OIC driver entry Herve Codina
2024-04-30  8:37 ` [PATCH 14/17] of: dynamic: Introduce of_changeset_add_prop_bool() Herve Codina
2024-05-08 18:03   ` Rob Herring
2024-04-30  8:37 ` [PATCH 15/17] pci: of_property: Add the interrupt-controller property in PCI device nodes Herve Codina
2024-05-01 17:38   ` Bjorn Helgaas
2024-05-03 14:40     ` Herve Codina
2024-04-30  8:37 ` [PATCH 16/17] mfd: Add support for LAN966x PCI device Herve Codina
2024-05-08  8:20   ` Steen.Hegelund
2024-05-14 12:55     ` Herve Codina [this message]
2024-04-30  8:37 ` [PATCH 17/17] MAINTAINERS: Add the Microchip LAN966x PCI driver entry Herve Codina
2024-04-30 13:40 ` [PATCH 00/17] Add support for the LAN966x PCI device using a DT overlay Andrew Lunn
2024-04-30 16:33   ` Herve Codina
2024-04-30 18:15     ` Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240514145518.3e989b83@bootlin.com \
    --to=herve.codina@bootlin.com \
    --cc=Allan.Nielsen@microchip.com \
    --cc=Daniel.Machon@microchip.com \
    --cc=Horatiu.Vultur@microchip.com \
    --cc=Lars.Povlsen@microchip.com \
    --cc=Steen.Hegelund@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andrew@lunn.ch \
    --cc=arnd@arndb.de \
    --cc=bhelgaas@google.com \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=luca.ceresoli@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=saravanak@google.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).