linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Virtual to physical address mapping
@ 2002-09-18  5:54 Ole André Vadla Ravnås
  2002-09-18  6:05 ` Steve Mickeler
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Ole André Vadla Ravnås @ 2002-09-18  5:54 UTC (permalink / raw)
  To: linux-kernel

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é



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Virtual to physical address mapping
  2002-09-18  5:54 Virtual to physical address mapping Ole André Vadla Ravnås
@ 2002-09-18  6:05 ` Steve Mickeler
  2002-09-18  8:07   ` Ole André Vadla Ravnås
  2002-09-18 11:47 ` Brian Gerst
  2002-09-18 14:46 ` Jonathan Lundell
  2 siblings, 1 reply; 9+ messages in thread
From: Steve Mickeler @ 2002-09-18  6:05 UTC (permalink / raw)
  To: Ole André Vadla Ravnås; +Cc: linux-kernel


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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>



[-] Steve Mickeler [ steve@neptune.ca ]

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

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Virtual to physical address mapping
  2002-09-18  6:05 ` Steve Mickeler
@ 2002-09-18  8:07   ` Ole André Vadla Ravnås
  2002-09-18 12:06     ` Richard B. Johnson
  0 siblings, 1 reply; 9+ messages in thread
From: Ole André Vadla Ravnås @ 2002-09-18  8:07 UTC (permalink / raw)
  To: Steve Mickeler; +Cc: linux-kernel

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 majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/
> >
> 
> 
> 
> [-] Steve Mickeler [ steve@neptune.ca ]
> 
> [|] 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Virtual to physical address mapping
  2002-09-18  5:54 Virtual to physical address mapping Ole André Vadla Ravnås
  2002-09-18  6:05 ` Steve Mickeler
@ 2002-09-18 11:47 ` Brian Gerst
  2002-09-18 16:10   ` Ole André Vadla Ravnås
  2002-09-18 14:46 ` Jonathan Lundell
  2 siblings, 1 reply; 9+ messages in thread
From: Brian Gerst @ 2002-09-18 11:47 UTC (permalink / raw)
  To: Ole André Vadla Ravnås; +Cc: linux-kernel

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Virtual to physical address mapping
  2002-09-18  8:07   ` Ole André Vadla Ravnås
@ 2002-09-18 12:06     ` Richard B. Johnson
  2002-09-18 16:04       ` Ole André Vadla Ravnås
  0 siblings, 1 reply; 9+ messages in thread
From: Richard B. Johnson @ 2002-09-18 12:06 UTC (permalink / raw)
  To: Ole André Vadla Ravnås; +Cc: Steve Mickeler, linux-kernel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: TEXT/PLAIN; charset=US-ASCII, Size: 1901 bytes --]

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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Virtual to physical address mapping
  2002-09-18  5:54 Virtual to physical address mapping Ole André Vadla Ravnås
  2002-09-18  6:05 ` Steve Mickeler
  2002-09-18 11:47 ` Brian Gerst
@ 2002-09-18 14:46 ` Jonathan Lundell
  2002-09-18 16:05   ` Ole André Vadla Ravnås
  2 siblings, 1 reply; 9+ messages in thread
From: Jonathan Lundell @ 2002-09-18 14:46 UTC (permalink / raw)
  To: Ole André Vadla Ravnås, linux-kernel

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Virtual to physical address mapping
  2002-09-18 12:06     ` Richard B. Johnson
@ 2002-09-18 16:04       ` Ole André Vadla Ravnås
  0 siblings, 0 replies; 9+ messages in thread
From: Ole André Vadla Ravnås @ 2002-09-18 16:04 UTC (permalink / raw)
  To: root; +Cc: steve, linux-kernel

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é



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Virtual to physical address mapping
  2002-09-18 14:46 ` Jonathan Lundell
@ 2002-09-18 16:05   ` Ole André Vadla Ravnås
  0 siblings, 0 replies; 9+ messages in thread
From: Ole André Vadla Ravnås @ 2002-09-18 16:05 UTC (permalink / raw)
  To: Jonathan Lundell; +Cc: linux-kernel

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é



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Virtual to physical address mapping
  2002-09-18 11:47 ` Brian Gerst
@ 2002-09-18 16:10   ` Ole André Vadla Ravnås
  0 siblings, 0 replies; 9+ messages in thread
From: Ole André Vadla Ravnås @ 2002-09-18 16:10 UTC (permalink / raw)
  To: Brian Gerst; +Cc: linux-kernel

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é



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2002-09-18 16:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-18  5:54 Virtual to physical address mapping Ole André Vadla Ravnås
2002-09-18  6:05 ` Steve Mickeler
2002-09-18  8:07   ` Ole André Vadla Ravnås
2002-09-18 12:06     ` Richard B. Johnson
2002-09-18 16:04       ` Ole André Vadla Ravnås
2002-09-18 11:47 ` Brian Gerst
2002-09-18 16:10   ` Ole André Vadla Ravnås
2002-09-18 14:46 ` Jonathan Lundell
2002-09-18 16:05   ` Ole André Vadla Ravnås

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).