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

2021-11-12 Thread Riza Dindir
Hello All,

I am replying to this thread here, including all that have
participated in the message thread. I do not know if that is
appropriate, or if I should open another thread...

Anyways, I am trying to make the radeon r7 m265 device run on NetBSD
9.2 (amd64). When inspecting the dmesg output, atht ehvery beginning I
have this:

[ 1.00] timecounter: Timecounter "i8254" frequency 1193182 Hz
quality 100
[ 1.03] efi: systbl at pa 8f6bef18
[ 1.03] Acer Aspire E5-551G (V1.08)
[ 1.03] mainbus0 (root)
[ 1.03] ACPI: RSDP 0x8FBFE014 24 (v02 ACRSYS)
[ 1.03] ACPI: XSDT 0x8FBFE120 C4 (v01 ACRSYS
ACRPRDCT 0001  0113)
[ 1.03] ACPI: FACP 0x8FBFC000 00010C (v05 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: DSDT 0x8FBEB000 00C377 (v01 ACRSYS
ACRPRDCT F000 1025 0004)
[ 1.03] ACPI: FACS 0x8FB65000 40
[ 1.03] ACPI: UEFI 0x8FBFD000 000236 (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: HPET 0x8FBFB000 38 (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: APIC 0x8FBFA000 90 (v03 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: MCFG 0x8FBF9000 3C (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: ASF! 0x8FBF8000 A5 (v32 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: BOOT 0x8FBEA000 28 (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: WDRT 0x8FBE9000 47 (v01 ACRSYS
ACRPRDCT  1025 0004)
[ 1.03] ACPI: WDAT 0x8FBE8000 0001AC (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: FPDT 0x8FBE6000 44 (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: MSDM 0x8FBE5000 55 (v03 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: SSDT 0x8FBE4000 000B9C (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: SSDT 0x8FBDA000 009AC7 (v02 ACRSYS
ACRPRDCT 0002 1025 0004)
[ 1.03] ACPI: CRAT 0x8FBD9000 0005A0 (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: VFCT 0x8FBC9000 00F684 (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: SSDT 0x8FBC7000 000418 (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: SSDT 0x8FBC5000 001401 (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: SSDT 0x8FBC4000 00082B (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: SSDT 0x8FBC2000 001138 (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: BGRT 0x8FBC8000 38 (v01 ACRSYS
ACRPRDCT 0001 1025 0004)
[ 1.03] ACPI: 7 ACPI AML tables successfully acquired and loaded

Here I have an entry that is labeled VFCT. I remembered that the
radeon_bios.c file contained a function that uses VFCT I thought the
rom might be in there, in that table. I have dumped the data using
"apcidump -dt", which I added below.

  VFCT: Length=63108, Revision=1, Checksum=97,
OEMID=ACRSYS, OEM Table ID=ACRPRDCT, OEM Revision=0x1,
Creator ID=1025, Creator Revision=0x4

Data={
 56 46 43 54 84 f6 00 0001 61 41 43 52 53 59 53
 41 43 52 50 52 44 43 5401 00 00 00 31 30 32 35
 00 00 04 00 32 9b a3 5dbd c6 cf 49 95 a6 e8 e4
 2e cd 79 a7 4c 00 00 0000 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00
 01 00 00 00 00 00 00 0002 10 09 13 00 00 00 00
 01 00 00 00 00 f6 00 0055 aa 7b e9 19 02 00 00
 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00
 cc 01 00 00 00 00 49 424d 16 fa a1 00 00 00 00
 00 00 00 00 00 00 00 0420 37 36 31 32 39 35 35
 32 30 00 00 00 00 00 0011 02 00 00 00 00 00 00
 a6 01 00 00 00 00 00 0030 33 2f 30 36 2f 31 34
 2c 30 34 3a 31 34 3a 3038 00 00 00 e9 0e 03 00
 e9 1d 03 00 00 00 80 0000 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 0042 52 34 35 33 39 39 2e
 30 30 31 00 53 50 45 4354 52 45 00 50 43 49 5f
 45 58 50 52 45 53 53 0044 44 52 33 00 0d 0a 42
 52 34 35 33 39 39 2e 3030 31 20 53 50 45 43 54
 52 45 20 44 44 52 33 2032 30 30 65 2f 20 20 20
 20 20 20 20 20 20 20 2020 20 20 20 20 20 20 20
 20 20 20 20 20 20 20 2020 20 20 20 20 20 20 20
 20 20 20 20 20 20 20 2020 20 20 0d 0a 00 0d 0a
 20 0d 0a 00 28 43 29 2031 39 38 38 2d 32 30 31
 30 2c 20 41 64 76 61 6e63 65 64 20 4d 69 63 72
 6f 20 44 65 76 69 63 6573 2c 20 49 6e 63 2e 

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

2021-11-04 Thread Riza Dindir
Hello All,

As you know I have a laptop that has amd radeon r7 m265 graphics
device (it seems there are two actually; 0x1002/0x1309 and
0x1002/0x6604). My kernel panics when I do enable radeon, not finding
any ROM.

I am using netbsd 9.2 amd64 and am using UEFI boot.

After reading kern/49964 (which had the same panic with my system -
radeon_get_bios does not find a bios) I did some testing. Here is what
I have so far.

The memory at 0xC (size 131072) starts with 0xff 0xff. So this
means that there is no valid expansion ROM here. This is what I have
done to get this dump (dd if=/dev/mem of=/tmp/bios bs=1 iseek=786432
count=131072) and to view it I used (hexdump -C /tmp/bios). If there
is anything that looks wrong let me know.

Then I have dumped the data on the two PCI devices mentioned above. To
arrive at these I did use (pcictl pci0 dump -d 1 -f 0 and pcictl pci1
dump -d 0 -f 0). Here is the outcome.

The device on pci0:1:0 is as such

PCI configuration registers:
  Common header:
0x00: 0x13091002 0x0017 0x0300 0x00800010

Vendor Name: ATI Technologies (0x1002)
Device ID: 0x1309
Command register: 0x0007
.
 Type 0 ("normal" device) header:
0x10: 0xe00c 0x 0xf00c 0x
0x20: 0x4001 0xf0b0 0x 0x08641025
0x30: 0xfffe0001 0x0048 0x 0x0100

Base address register at 0x10
  type: 64-bit prefetchable memory
  base: 0xe000
Base address register at 0x18
  type: 64-bit prefetchable memory
  base: 0xf000
Base address register at 0x20
  type: I/O
  base: 0x4000
Base address register at 0x24
  type: 32-bit nonprefetchable memory
  base: 0xf0b0
Cardbus CIS Pointer: 0x
Subsystem vendor ID: 0x1025
Subsystem ID: 0x0864
Expansion ROM Base Address Register: 0xfffe0001
  base: 0xfffe
  Expansion ROM Enable: on
  Validation Status: Validation not supported
  Validation Details: 0x0
Capability list pointer: 0x48
Reserved @ 0x38: 0x
Maximum Latency: 0x00
Minimum Grant: 0x00
Interrupt pin: 0x01 (pin A)
Interrupt line: 0x00

and for the device on pci1:0:0 has this information

PCI configuration registers:
  Common header:
0x00: 0x66041002 0x0017 0x0380 0x0010

Vendor Name: ATI Technologies (0x1002)
Device ID: 0x6604
Command register: 0x0007
...
Type 0 ("normal" device) header:
0x10: 0xd00c 0x 0xf0a4 0x
0x20: 0x3001 0x 0x 0x086a1025
0x30: 0xfffe 0x0048 0x 0x0100

Base address register at 0x10
  type: 64-bit prefetchable memory
  base: 0xd000
Base address register at 0x18
  type: 64-bit nonprefetchable memory
  base: 0xf0a0
Base address register at 0x20
  type: I/O
  base: 0x3000
Base address register at 0x24
  not implemented
Cardbus CIS Pointer: 0x
Subsystem vendor ID: 0x1025
Subsystem ID: 0x086a
Expansion ROM Base Address Register: 0xfffe
  base: 0xfffe
  Expansion ROM Enable: off
  Validation Status: Validation not supported
  Validation Details: 0x0
Capability list pointer: 0x48
Reserved @ 0x38: 0x
Maximum Latency: 0x00
Minimum Grant: 0x00
Interrupt pin: 0x01 (pin A)
Interrupt line: 0x00

The ROM in the pci0:1:0 has the PCI ROM enabled but the ROM address is
not correct i think. Would you have any ideas on where the expansion
ROM might be found? Whereelse might I look? Since I am using UEFI, can
this ROM be located in the UEFI boot directories somewhere? Any
pointers, any information or any ideas would be appreciated.

Thanks in advance.

Best Regards,
Riza Dindir


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

2021-10-24 Thread Riza Dindir
Hello Matthew,

On Sat, Oct 23, 2021 at 7:44 PM matthew green  wrote:
>
> > > 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.

I am sorry for not being clear on that. I mean the test code that I
have in the radeon_bios.c (I have a couple of functions in there to
test reading from the ROM), I was not doing bus_space_unmap(). And
when the kernel was getting the other radeon (it finds two radeon
devices) the bus_space_map() call was failing and returning code 35,
which would explain why it was thinking that it had mapped that bus
space.

I also could not find anything regarding vga. All the vga references
in the dmesg below are related to acpi.

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

This will be a bit long here. But here we go...

The "stock kernel" when booted without disabling the radeon device is as such:

Oct 24 07:28:37 mercury syslogd[211]: restart
Oct 24 07:28:37 mercury /netbsd: [   1.000] Copyright (c) 1996,
1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
Oct 24 07:28:37 mercury /netbsd: [   1.000] 2006, 2007, 2008,
2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
Oct 24 07:28:37 mercury /netbsd: [   1.000] 2018, 2019, 2020
The NetBSD Foundation, Inc.  All rights reserved.
Oct 24 07:28:37 mercury /netbsd: [   1.000] Copyright (c) 1982,
1986, 1989, 1991, 1993
Oct 24 07:28:37 mercury /netbsd: [   1.000] The Regents of the
University of California.  All rights reserved.
Oct 24 07:28:37 mercury /netbsd:
Oct 24 07:28:37 mercury /netbsd: [   1.000] NetBSD 9.2 (GENERIC)
#0: Wed May 12 13:15:55 UTC 2021
Oct 24 07:28:37 mercury /netbsd: [   1.000]
mkre...@mkrepro.netbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC
Oct 24 07:28:37 mercury /netbsd: [   1.000] total memory = 15306 MB
Oct 24 07:28:37 mercury /netbsd: [   1.000] avail memory = 14834 MB
Oct 24 07:28:37 mercury /netbsd: [   1.000] WARNING: module error:
module `msdos' pushed by boot loader already exists
Oct 24 07:28:37 mercury /netbsd: [   1.000] rnd: seeded with 256 bits
Oct 24 07:28:37 mercury /netbsd: [   1.000] timecounter:
Timecounters tick every 10.000 msec
Oct 24 07:28:37 mercury /netbsd: [   1.000] Kernelized RAIDframe activated
Oct 24 07:28:37 mercury /netbsd: [   1.000] running cgd selftest
aes-xts-256 aes-xts-512 done
Oct 24 07:28:37 mercury /netbsd: [   1.000] RTC BIOS diagnostic
error 0x80
Oct 24 07:28:37 mercury /netbsd: [   1.000] timecounter:
Timecounter "i8254" frequency 1193182 Hz quality 100
Oct 24 07:28:37 mercury /netbsd: [   1.030] efi: systbl at pa 8f6bef18
Oct 24 07:28:37 mercury /netbsd: [   1.030] Acer Aspire E5-551G (V1.08)
Oct 24 07:28:37 mercury /netbsd: [   1.030] mainbus0 (root)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: RSDP
0x8FBFE014 24 (v02 ACRSYS)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: XSDT
0x8FBFE120 C4 (v01 ACRSYS ACRPRDCT 0001  0113)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: FACP
0x8FBFC000 00010C (v05 ACRSYS ACRPRDCT 0001 1025 0004)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: DSDT
0x8FBEB000 00C377 (v01 ACRSYS ACRPRDCT F000 1025 0004)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: FACS
0x8FB65000 40
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: UEFI
0x8FBFD000 000236 (v01 ACRSYS ACRPRDCT 0001 1025 0004)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: HPET
0x8FBFB000 38 (v01 ACRSYS ACRPRDCT 0001 1025 0004)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: APIC
0x8FBFA000 90 (v03 ACRSYS ACRPRDCT 0001 1025 0004)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: MCFG
0x8FBF9000 3C (v01 ACRSYS ACRPRDCT 0001 1025 0004)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: ASF!
0x8FBF8000 A5 (v32 ACRSYS ACRPRDCT 0001 1025 0004)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: BOOT
0x8FBEA000 28 (v01 ACRSYS ACRPRDCT 0001 1025 0004)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: WDRT
0x8FBE9000 47 (v01 ACRSYS ACRPRDCT  1025 0004)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: WDAT
0x8FBE8000 0001AC (v01 ACRSYS ACRPRDCT 0001 1025 0004)
Oct 24 07:28:37 mercury /netbsd: [   1.030] ACPI: FPDT
0x8FBE6000 44 (v01 ACRSYS 

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


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

2021-10-22 Thread matthew green
> 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?

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.)


.mrg.


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

2021-10-22 Thread Taylor R Campbell
> Date: Wed, 20 Oct 2021 08:26:25 +
> From: Riza Dindir 
> 
> The bus_space_map function returns code 35. Maybe I am doing something
> wrong in the code when I try to read the "expansion rom" of the pci
> card. Anyone has an idea? How should I read the "expansion rom" of a
> PCI card?

35 is EAGAIN, which means something already has it mapped.  Gotta
track down who else has already mapped it -- might stick a
db_stacktrace in bus_space_map conditional on covering this address.


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

2021-10-22 Thread Riza Dindir
Hello Michael,

On Thu, Oct 21, 2021, 19:55 Michael  wrote:

> Hello,
>
> On Wed, 20 Oct 2021 08:26:25 +
> Riza Dindir  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:
> >
> > kern error:
> [drm:(/export/netbsd/src/sys/external/bsd/drm2/dist/drm/radeon/radeon_bios.c:725)radeon_get_bios]
> > *ERROR* Unable to locate a BIOS ROM
> > radeon0: autoconfiguration error: error: Fatal error during GPU init
> > radeon0: autoconfiguration error: unable to attach drm: 22
> >
> > I wanted to see if I can read the bios of that card and added some
> > test functions to the file mentioned above. The code is as such:
> >
> >   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);
> >
> >   result = bus_space_map(rdev->pdev->pd_pa.pa_memt,
> >   PCI_MAPREG_ROM_ADDR(address),
> >   size, BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE, );
> >   DRM_INFO("result of bus_space_map(): %d\n", result);
> >
> >   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]);
> >   } else {
> > DRM_INFO("bios was NULL\n");
> >   }
> >
> > The bus_space_map function returns code 35. Maybe I am doing something
> > wrong in the code when I try to read the "expansion rom" of the pci
> > card. Anyone has an idea? How should I read the "expansion rom" of a
> > PCI card?
>
> Is there something sensible in the ROM BAR? If it's NULL the
>

The rom bar register has a value of fffe. That means the rim decoder is
not enabled i think.

bus_space_map() would fail. It also needs to be enabled in the BAR,
> which it may or may not be already. Then pray that your chip has
>

You mean the first bit (bit 0) should be 1 to enable the rom. Right?

If the address is the address i gave above and the rom decoder enable is
set to true (or 1), then the bus_space_map must succeed. Will try that.

separate decoders for ROM and regular BARs - the specs allow them to
> share one which would mean you can not access the rest of the card if
> the ROM is enabled - you're meant to turn it on, copy the ROM's
> content, turn it off and run the BIOS from RAM.
> Finally, I've seen laptops with no separate graphics BIOS at all...
>
> have fun
> Michael
>


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

2021-10-21 Thread Michael
Hello,

On Wed, 20 Oct 2021 08:26:25 +
Riza Dindir  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:
> 
> kern error: 
> [drm:(/export/netbsd/src/sys/external/bsd/drm2/dist/drm/radeon/radeon_bios.c:725)radeon_get_bios]
> *ERROR* Unable to locate a BIOS ROM
> radeon0: autoconfiguration error: error: Fatal error during GPU init
> radeon0: autoconfiguration error: unable to attach drm: 22
> 
> I wanted to see if I can read the bios of that card and added some
> test functions to the file mentioned above. The code is as such:
> 
>   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);
> 
>   result = bus_space_map(rdev->pdev->pd_pa.pa_memt,
>   PCI_MAPREG_ROM_ADDR(address),
>   size, BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE, );
>   DRM_INFO("result of bus_space_map(): %d\n", result);
> 
>   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]);
>   } else {
> DRM_INFO("bios was NULL\n");
>   }
> 
> The bus_space_map function returns code 35. Maybe I am doing something
> wrong in the code when I try to read the "expansion rom" of the pci
> card. Anyone has an idea? How should I read the "expansion rom" of a
> PCI card?

Is there something sensible in the ROM BAR? If it's NULL the
bus_space_map() would fail. It also needs to be enabled in the BAR,
which it may or may not be already. Then pray that your chip has
separate decoders for ROM and regular BARs - the specs allow them to
share one which would mean you can not access the rest of the card if
the ROM is enabled - you're meant to turn it on, copy the ROM's
content, turn it off and run the BIOS from RAM.
Finally, I've seen laptops with no separate graphics BIOS at all...

have fun
Michael