tech-kern archive

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

pci_mapreg_map and BAR from `Bus space tutorial'



Hello!
A very useful tutorial is available for newbies like me in

 <https://wiki.netbsd.org/tutorials/bus_space_tutorial/>
 <https://github.com/downloads/rkujawa/busspace-tutorial/bus_space_tutorial.pdf>

with a first introduction to kernel PCI drivers. I hope this is the
right ML to write to, despite the (possibly) elementary questions that
follow.

I created the driver according to all the instructions till slide 47,
but `dmesg' prints: `can't map the BAR'. Being it a test device
inside a Cobalt machine emulated by gxemul, I really am not able to
identify the problem.

The PCI device driver uses the file `src/sys/dev/pci/faareg.h' to define
the BAR position:

#ifndef FAAREG_H
#define FAAREG_H

#define FAA_MMREG_BAR   0x10
 
#endif

(I built the kernel this way, but am not sure about the position of
`#endif').

Then, the `attach' function in the driver main file
`src/sys/dev/pci/faa.c' acts this way:

static void
faa_attach(device_t parent, device_t self, void *aux)
{
        struct faa_softc *sc = device_private(self);
        const struct pci_attach_args *pa = aux;

        sc->sc_dev = self;

        pci_aprint_devinfo(pa, NULL);

        if (pci_mapreg_map(pa, FAA_MMREG_BAR, PCI_MAPREG_TYPE_MEM, 0, 
            &sc->sc_regt, &sc->sc_regh, &sc->sc_reg_pa, 0) != 0 ) {
            aprint_error_dev(sc->sc_dev, "can't map the BAR\n");
            return;
        }

        aprint_normal_dev(sc->sc_dev, "regs at 0x%08x\n", (uint32_t)
sc->sc_reg_pa);
}

IIUC from the slides and the manpages, `pci_mapreg_map' (PCI-specific
way of mapping a memory space) invokes `bus_space_map' (generic
bus_space way of mapping a memory space).

My doubts are:

- What does exactly do `pci_mapreg_map'? Does it map the physical address
  contained in FAA_MMREG_BAR to a kernel virtual address?

- FAA_MMREG_BAR may contain the beginning address of a space to be
  mapped. But how does `pci_mapreg_map' know the extension of such a map?

- According to pci(9), the ``physical address of the mapping is in''
  FAA_MMREG_BAR. But this assumes that someone previously wrote
  FAA_MMREG_BAR with the physical address assigned to that specific PCI
  device. As regards a NetBSD system, who knows that physical address
  and who is supposed to write it on this PCI device's BAR, before it
  can be used in `pci_mapreg_map'? That is: does the OS rely on the BIOS
  configuration, or does the OS configure the BARs by itself?

It's not always simple to gather some introductory information and I'm
sorry if my questions are trivial or somewhat naive. If anyone knows
about some documentation (not included in the final references of the
mentioned tutorial), I would check it out.
As well, if anyone knows another simple way to emulate a basic PCI
device for test/educational purposes on NetBSD, it's definitely welcome.
Thank you even just for having read.

Rocky


Home | Main Index | Thread Index | Old Index