tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: change MSI/MSI-X APIs



> On May 14, 2015, at 8:17 AM, Christos Zoulas <christos%zoulas.com@localhost> wrote:
> 
> On May 14,  7:40pm, k-nakahara%iij.ad.jp@localhost (Kengo NAKAHARA) wrote:
> -- Subject: Re: change MSI/MSI-X APIs
> 
> Thanks!
> 
> Here's a slightly modified version that gets rid of the flags and simplifies
> the more common case.
> 
> The following could be an enum:
> 
> typedef int pci_intr_type_t;
> 
> #define PCI_INTR_TYPE_INTX 0
> #define PCI_INTR_TYPE_MSI  1
> #define PCI_INTR_TYPE_MSIX 2
> #define PCI_INTR_TYPE_MAX  3
> 
> int
> pci_intr_alloc(const struct pci_attach_args *, pci_intr_handle_t **ihps,
>    int *counts, size_t ncounts);
> 
> If the counts[i] == 0, then you don't allocate, if it is -1, you allocate max,
> otherwise you allocate up to count.
> 
> NULL in the counts means do whatever you think is best.
> (I am passing the "ncounts" so that the API does not need to be versioned
> if there are more interrupt flavors added)
> 
> pci_intr_type_t pci_intr_type(pci_intr_handle_t *ihp);
> 
> xxxx_attach()
> {
> 
> We return a negative errno and a positive nintrs, so the common case where
> the driver does not care:
> 
> 	if  ((nintrs = pci_intr_alloc(*pa, &sc->sc_intrs, NULL, 0)) < 0) {
> 		error("foo %d\n", -nintrs);
> 		return;
> 	}
> 
> 	for (i = 0; i < nintrs; i++)
> 		sc->sc_ihs[i] = pci_intr_establish(pc, sc->sc_intrs[i], level,
> 		    func, arg);
> 
> Otherwise if we want to be selective:
> 
> 	int counts[PCI_INTR_TYPE_MAX];
> 	memset(counts, 0, sizeof(counts);
> 
> 	// Don't want msi, leave it 0
> 	counts[PCI_INTR_TYPE_MSIX] = -1;
> 	counts[PCI_INTR_TYPE_INTX] = -1;
> 
> 	if  ((nintrs = pci_intr_alloc(*pa, &sc->sc_intrs, counts,
> 	    PCI_INTR_TYPE_MAX)) < 0)
> 	    ....
> 
> What do you think?

Donâ??t you need a pci_intr_free(pc, sc->sc_intrs, nintrs); ?



Home | Main Index | Thread Index | Old Index