re: Trying to access the Expansion ROM of a video card

2021-10-23 Thread matthew green
> > a full dmesg might also be useful -- might help identify what
> > else has mapped this.  (perhaps vga@something.)
>
> Tha is probably I did not hava a bus_space_unmap in my code. And since
> the system finds two radeon devices one is (0x1002, 0x1309) and the
> other is (0x1002, 0x6604) it is passing the first one and failing in
> the second one.

you say "passing the first"?  does vga@pci attach instead?
that is very likely the reason it is double mapped, and it
may be that the PCI BARs for the other are not setup for
one or the other device.

a dmesg would be really useful -- even if just the parts for
both radeon cards.

> Is using rdev->pdev->pd_pa.pa_memt incorrect when mapping the bus space?

probably.

> What address should I write to the ROM BAR?

i think that you shouldn't do this, without coordination
with the whole PCI subsystem.  see the code that is behind
the PCI_CONFIGURE_NETBSD option - this is not a simple
task.

> Is using BUS_SPACE_MAP_PREFETCHABLE in the flags in the bus_space_map
> call correct? I saw this in the code for pci_map_rom, and thought that
> it might need that?

this part is probably going to be fine.


.mrg.


Re: Trying to access the Expansion ROM of a video card

2021-10-23 Thread Riza Dindir
Hello Matthew

On Sat, Oct 23, 2021 at 4:11 AM matthew green  wrote:
>
> > I am using NetBSD 9.2 (amd64). I have a laptop that has a radeon r7
> > m265 video card (vendor 0x1002, product 0x6604). The system does not
> > recognize this card. It fails with this message:
>
> are you booting uefi or bios?

I am using UEFI.

>
> sometimes modern systems don't work properly with bios and gpus,
> not being configured properly.  can you try booting uefi if not
> already?
>
> if that doesn't work, can you try booting a -current kernel?
>
> a full dmesg might also be useful -- might help identify what
> else has mapped this.  (perhaps vga@something.)

Tha is probably I did not hava a bus_space_unmap in my code. And since
the system finds two radeon devices one is (0x1002, 0x1309) and the
other is (0x1002, 0x6604) it is passing the first one and failing in
the second one.

Now based on that piece of information, I have changed the code to this.

  pci_conf_capture(rdev->pdev->pd_pa.pa_pc, rdev->pdev->pd_pa.pa_tag,
  );

  address = PCI_MAPREG_ROM_ADDR(conf.reg[12]);
  size = PCI_MAPREG_ROM_SIZE(address);
  DRM_INFO("rom addr: %x, rom size: %lu\n", address, size);

  pci_conf_write(rdev->pdev->pd_pa.pa_pc,
  rdev->pdev->pd_pa.pa_tag, PCI_MAPREG_ROM,
  address | PCI_MAPREG_ROM_ENABLE);

  result = bus_space_map(rdev->pdev->pd_pa.pa_memt,
  PCI_MAPREG_ROM_ADDR(address),
  size, BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE, );
  if (result != 0) {
DRM_INFO("result of bus_space_map(): %d\n", result);
return;
  }

  bios = (uint8_t *)bus_space_vaddr(rdev->pdev->pd_pa.pa_memt,
  romh);
  DRM_INFO("bios: %p\n", bios);
  if (bios != NULL) {
DRM_INFO("bios[0]: %x, bios[1]: %x\n", bios[0], bios[1]);
  }

  bus_space_unmap(rdev->pdev->pd_pa.pa_memt, romh, size);

This does map the bus space (to the pci devices memt bus_space_tag,
and gets a virtual address to the rom. But the data I read is 0xff,
0xff. I also read the first 256 bytes in that address and was getting
0xff.

The address returned is 0xe000 and the size is 113072 (128K). I
enable the rom decoder, by setting the 0th bit in the address to 1 and
writing this to the ROM BAR. Then map the bus space using the memt tag
to get a handle to the rom, which I get. After that I am getting the
virtual address using the rom handle.

Is using rdev->pdev->pd_pa.pa_memt incorrect when mapping the bus space?

What address should I write to the ROM BAR?

What address should I use with the bus_space_map call?

Is using BUS_SPACE_MAP_PREFETCHABLE in the flags in the bus_space_map
call correct? I saw this in the code for pci_map_rom, and thought that
it might need that?

>
>
> .mrg.

Regards,
Riza