2002-09-18 05:45:43

by Ole André Vadla Ravnås

[permalink] [raw]
Subject: Virtual to physical address mapping

Hi

I've noticed that ifconfig shows a base address and an interrupt
number.. However, I can't get that base address to correspond to
anything in /proc/iomem, which means that I can't determine which PCI
device (in this case) it corresponds to (guess the base address is
virtual). What I want is to find a way to get the PCI bus and device no
for the network device, but is this at all possible without altering the
kernel?

Ole Andr?



2002-09-18 06:00:37

by Steve Mickeler

[permalink] [raw]
Subject: Re: Virtual to physical address mapping


That info will be in /proc/pci


On 18 Sep 2002, Ole Andr? Vadla Ravn?s wrote:

> Hi
>
> I've noticed that ifconfig shows a base address and an interrupt
> number.. However, I can't get that base address to correspond to
> anything in /proc/iomem, which means that I can't determine which PCI
> device (in this case) it corresponds to (guess the base address is
> virtual). What I want is to find a way to get the PCI bus and device no
> for the network device, but is this at all possible without altering the
> kernel?
>
> Ole Andr?
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>



[-] Steve Mickeler [ [email protected] ]

[|] Todays root password is brought to you by /dev/random

[+] 1024D/9AA80CDF = 4103 9E35 2713 D432 924F 3C2E A7B9 A0FE 9AA8 0CDF

2002-09-18 07:58:34

by Ole André Vadla Ravnås

[permalink] [raw]
Subject: Re: Virtual to physical address mapping

Thanks, but the address specified there is certainly not the same as the
base address ifconfig reports. I made a simple program to verify this:

# ./ioctl_test eth0
mem_start: 0x0
mem_end: 0x0
base_addr: 0xa000
irq: 10
dma: 0
port: 0

And /proc/pci tells me, for that device:
Bus 0, device 15, function 0:
Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C
(rev 16).
IRQ 10.
Master Capable. Latency=32. Min Gnt=32.Max Lat=64.
I/O at 0xd800 [0xd8ff].
Non-prefetchable 32 bit memory at 0xe4005000 [0xe40050ff].

Is there any way I can map this 0xa000 address, which I assume is
virtual, to its physical address? I guess I'm very limited in userspace,
but are there any options or do I have to go about modifying the kernel?

The source for my test program is here for clarity's sake:
#include <stdio.h>
#include <errno.h>
#include <net/if.h>
#include <sys/ioctl.h>

int main(int argc, char *argv[])
{
int fd;
struct ifreq ifr;

if (!argv[1]) {
fprintf(stderr, "usage: %s [devname]\n", argv[0]);
return 1;
}

fd = socket(AF_INET, SOCK_DGRAM, 0);

if (fd < 0) {
perror("failed to open socket");
return 1;
}

memset(&ifr, 0, sizeof(struct ifreq));
strcpy(ifr.ifr_name, argv[1]);

if (ioctl(fd, SIOCGIFMAP, &ifr) < 0) {
perror("ioctl failed");
close(fd);
return 1;
}

printf("mem_start: 0x%lx\n", ifr.ifr_map.mem_start);
printf("mem_end: 0x%lx\n", ifr.ifr_map.mem_end);
printf("base_addr: 0x%hx\n", ifr.ifr_map.base_addr);
printf("irq: %d\n", ifr.ifr_map.irq);
printf("dma: %d\n", ifr.ifr_map.dma);
printf("port: %d\n", ifr.ifr_map.port);

close(fd);

return 0;
}


Ole Andr?

On Wed, 2002-09-18 at 08:05, Steve Mickeler wrote:
>
> That info will be in /proc/pci
>
>
> On 18 Sep 2002, Ole Andr? Vadla Ravn?s wrote:
>
> > Hi
> >
> > I've noticed that ifconfig shows a base address and an interrupt
> > number.. However, I can't get that base address to correspond to
> > anything in /proc/iomem, which means that I can't determine which PCI
> > device (in this case) it corresponds to (guess the base address is
> > virtual). What I want is to find a way to get the PCI bus and device no
> > for the network device, but is this at all possible without altering the
> > kernel?
> >
> > Ole Andr?
> >
> >
> > -
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to [email protected]
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
> >
>
>
>
> [-] Steve Mickeler [ [email protected] ]
>
> [|] Todays root password is brought to you by /dev/random
>
> [+] 1024D/9AA80CDF = 4103 9E35 2713 D432 924F 3C2E A7B9 A0FE 9AA8 0CDF
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>


2002-09-18 11:43:44

by Brian Gerst

[permalink] [raw]
Subject: Re: Virtual to physical address mapping

Ole Andr? Vadla Ravn?s wrote:
> Hi
>
> I've noticed that ifconfig shows a base address and an interrupt
> number.. However, I can't get that base address to correspond to
> anything in /proc/iomem, which means that I can't determine which PCI
> device (in this case) it corresponds to (guess the base address is
> virtual). What I want is to find a way to get the PCI bus and device no
> for the network device, but is this at all possible without altering the
> kernel?
>
> Ole Andr?

It's in /proc/ioports

--
Brian Gerst


2002-09-18 12:03:20

by Richard B. Johnson

[permalink] [raw]
Subject: Re: Virtual to physical address mapping

On 18 Sep 2002, Ole [ISO-8859-1] Andr? Vadla [ISO-8859-1] Ravn?s wrote:

> Thanks, but the address specified there is certainly not the same as the
> base address ifconfig reports. I made a simple program to verify this:

[SNIPPED...]

`ifconfig` reports the base address of a port (I don't know why).
There are other addresses in use.

eth0 Link encap:Ethernet HWaddr 00:50:DA:19:7A:7D
inet addr:10.100.2.224 Bcast:10.255.255.255 Mask:255.0.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2630005 errors:0 dropped:0 overruns:0 frame:0
TX packets:307396 errors:0 dropped:0 overruns:0 carrier:0
collisions:2430 txqueuelen:100
Interrupt:10 Base address:0xb800

[SNIPPED...]

A private version of `lspci` that actually reads the PCI ports
shows:

Device Vendor Type
0 Intel Corporation 440BX/ZX - 82443BX/ZX Host bridge
[SNIPPED...]
11 3Com Corporation 3c905B 100BaseTX [Cyclone]
IRQ 10 Pin A
I/O ports : 0xb800->0xb87e
I/O memory : 0xdf800000->0xdf80007f

Notice that it has memory-mapped I/O.
That said, neither of these addresses are the virtual addresses.
On an ix86, these are physical addresses which are the same as
the bus addresses. Other machines may not have the same physical
and bus address. The virtual address is whatever mmap() returns
in user-space, and whatever ioremap() returns in kernel space.
Note that in kernel space, the returned value should not be used
as a pointer. There are macros defined to access the I/O addressed
elements. See .../linux/Documentation/IO-mapping.txt.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
The US military has given us many words, FUBAR, SNAFU, now ENRON.
Yes, top management were graduates of West Point and Annapolis.

2002-09-18 14:45:40

by Jonathan Lundell

[permalink] [raw]
Subject: Re: Virtual to physical address mapping

At 7:54am +0200 9/18/02, Ole Andr? Vadla Ravn?s wrote:
>I've noticed that ifconfig shows a base address and an interrupt
>number.. However, I can't get that base address to correspond to
>anything in /proc/iomem, which means that I can't determine which PCI
>device (in this case) it corresponds to (guess the base address is
>virtual). What I want is to find a way to get the PCI bus and device no
>for the network device, but is this at all possible without altering the
>kernel?

ETHTOOL_GDRVINFO will do that directly, if the driver supports it.
--
/Jonathan Lundell.

2002-09-18 15:56:08

by Ole André Vadla Ravnås

[permalink] [raw]
Subject: Re: Virtual to physical address mapping

On Wed, 2002-09-18 at 14:06, Richard B. Johnson wrote:
> On 18 Sep 2002, Ole [ISO-8859-1] Andr? Vadla [ISO-8859-1] Ravn?s wrote:
>
> > Thanks, but the address specified there is certainly not the same as the
> > base address ifconfig reports. I made a simple program to verify this:
>
> [SNIPPED...]
>
> `ifconfig` reports the base address of a port (I don't know why).
> There are other addresses in use.

Ah.. that explains it all, as I modified net/core/dev.c earlier today to
report the base_addr present in the net_device structure in the
sprintf_stats() which is responsible for the /proc/net/dev output --
and, what I got was:
0xf88fa000
where the ifmap structure returned by the SIOCGIFMAP ioctl contained a
base_addr saying:
0xa000
I did this ugly hack (WRT net/core/dev.c) since I discovered that the
net_device()'s base_addr was an unsigned long, while ifmap's base_addr
was an unsigned short - and indeed, just like you said, it's only the
base-address that's returned in the ifmap. :-)

> eth0 Link encap:Ethernet HWaddr 00:50:DA:19:7A:7D
> inet addr:10.100.2.224 Bcast:10.255.255.255 Mask:255.0.0.0
> UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
> RX packets:2630005 errors:0 dropped:0 overruns:0 frame:0
> TX packets:307396 errors:0 dropped:0 overruns:0 carrier:0
> collisions:2430 txqueuelen:100
> Interrupt:10 Base address:0xb800
>
> [SNIPPED...]
>
> A private version of `lspci` that actually reads the PCI ports
> shows:
>
> Device Vendor Type
> 0 Intel Corporation 440BX/ZX - 82443BX/ZX Host bridge
> [SNIPPED...]
> 11 3Com Corporation 3c905B 100BaseTX [Cyclone]
> IRQ 10 Pin A
> I/O ports : 0xb800->0xb87e
> I/O memory : 0xdf800000->0xdf80007f
>
> Notice that it has memory-mapped I/O.
> That said, neither of these addresses are the virtual addresses.
> On an ix86, these are physical addresses which are the same as
> the bus addresses. Other machines may not have the same physical
> and bus address. The virtual address is whatever mmap() returns
> in user-space, and whatever ioremap() returns in kernel space.
> Note that in kernel space, the returned value should not be used
> as a pointer. There are macros defined to access the I/O addressed
> elements. See .../linux/Documentation/IO-mapping.txt.

Ah, I see! Thanks a lot for your help! :-)

Best regards
Ole Andr?


2002-09-18 15:57:14

by Ole André Vadla Ravnås

[permalink] [raw]
Subject: Re: Virtual to physical address mapping

On Wed, 2002-09-18 at 16:46, Jonathan Lundell wrote:
> At 7:54am +0200 9/18/02, Ole Andr? Vadla Ravn?s wrote:
> >I've noticed that ifconfig shows a base address and an interrupt
> >number.. However, I can't get that base address to correspond to
> >anything in /proc/iomem, which means that I can't determine which PCI
> >device (in this case) it corresponds to (guess the base address is
> >virtual). What I want is to find a way to get the PCI bus and device no
> >for the network device, but is this at all possible without altering the
> >kernel?
>
> ETHTOOL_GDRVINFO will do that directly, if the driver supports it.

Wow, great!! Thanks a bunch, that's exactly what I was looking for! :-)

Best regards
Ole Andr?


2002-09-18 16:02:17

by Ole André Vadla Ravnås

[permalink] [raw]
Subject: Re: Virtual to physical address mapping

On Wed, 2002-09-18 at 13:47, Brian Gerst wrote:
> Ole Andr? Vadla Ravn?s wrote:
> > Hi
> >
> > I've noticed that ifconfig shows a base address and an interrupt
> > number.. However, I can't get that base address to correspond to
> > anything in /proc/iomem, which means that I can't determine which PCI
> > device (in this case) it corresponds to (guess the base address is
> > virtual). What I want is to find a way to get the PCI bus and device no
> > for the network device, but is this at all possible without altering the
> > kernel?
> >
> > Ole Andr?
>
> It's in /proc/ioports

Well, yes you're absolutely right, I got that all wrong in the first
place. Fortunately things are clearing up now.. :-) Thanks

Best regards
Ole Andr?