Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: mapping small parts of a pci card to conserve KVA

0 views
Skip to first unread message

Warner Losh

unread,
Feb 15, 2005, 3:55:50 PM2/15/05
to
> I maintain drivers for a PCI card which presents itself as having
> 16MB of address space. Eg:
>
> mx0: <Myrinet PCIXE> mem 0xf9000000-0xf9ffffff irq 20 at device 3.0 on pci1
>
> However, most of that address space does not need to be mapped into
> the host. Really, only a little over 2MB needs to be mapped (3 regions
> with length 1024 bytes, 256 bytes, and 2MB).
>
> I've tried to re-write things so that I make multiple calls
> to bus_alloc_resource() with the (hopefully) appropriate offset and
> lengths. Eg:
>
> rid = PCIR_MAPS;
> *res = bus_alloc_resource(is->arch.dev, SYS_RES_MEMORY, &rid,
> (u_long)offset,
> (u_long)(offset + len - 1), len,
> RF_ACTIVE|PCI_RF_DENSE);
>
> At least on 5.3R, I seem to get back the same struct resource * from
> each call. rman_get_virtual() returns a different kva for each
> mapping, yet they all seem to map to the same physical address.
> Eg, I call vtophys() on the results of rman_get_virtual(),
> for each segment, and they all map to 0xf9000000.
>
> Is there a way to just map what I need?

There's no way to map part of a resource currently. I'd like to
create an API to do that, since it would be useful for a lot of
things, but none exists today. As soon as bus_activate_resource is
called, it gets mapped.

Warner
_______________________________________________
freebsd...@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hacke...@freebsd.org"

Scott Long

unread,
Feb 15, 2005, 4:04:42 PM2/15/05
to
Andrew Gallatin wrote:

> I maintain drivers for a PCI card which presents itself as having
> 16MB of address space. Eg:
>
> mx0: <Myrinet PCIXE> mem 0xf9000000-0xf9ffffff irq 20 at device 3.0 on pci1
>
> However, most of that address space does not need to be mapped into
> the host. Really, only a little over 2MB needs to be mapped (3 regions
> with length 1024 bytes, 256 bytes, and 2MB).
>
> I've tried to re-write things so that I make multiple calls
> to bus_alloc_resource() with the (hopefully) appropriate offset and
> lengths. Eg:
>
> rid = PCIR_MAPS;
> *res = bus_alloc_resource(is->arch.dev, SYS_RES_MEMORY, &rid,
> (u_long)offset,
> (u_long)(offset + len - 1), len,
> RF_ACTIVE|PCI_RF_DENSE);
>
> At least on 5.3R, I seem to get back the same struct resource * from
> each call. rman_get_virtual() returns a different kva for each
> mapping, yet they all seem to map to the same physical address.
> Eg, I call vtophys() on the results of rman_get_virtual(),
> for each segment, and they all map to 0xf9000000.
>
> Is there a way to just map what I need?
>

> Thanks,
>
> Drew
>

You can use pmap_mapdev() to create a KVA mapping of an arbitrary
physaddr+len. In fact, this is exactly what newbus uses to create the
PCI MEMIO resources when bus_alloc_resource() is called. I'm not sure
if the range is mapped and activated before the driver makes that call,
Warner or John might know for sure.

Scott

Andrew Gallatin

unread,
Feb 15, 2005, 4:16:12 PM2/15/05
to

Scott Long writes:
>
> You can use pmap_mapdev() to create a KVA mapping of an arbitrary
> physaddr+len. In fact, this is exactly what newbus uses to create the
> PCI MEMIO resources when bus_alloc_resource() is called. I'm not sure
> if the range is mapped and activated before the driver makes that call,
> Warner or John might know for sure.

Thanks.. But since this is an out of tree driver, I want to stick
as much as I can to the normal driver APIs. If the KVA wastage
becomes a huge problem, I'll explore pmap_mapdev(), but for now
its not a big deal.

Thanks again,

Drew

Warner Losh

unread,
Feb 15, 2005, 5:07:48 PM2/15/05
to
From: Scott Long <sco...@samsco.org>
Subject: Re: mapping small parts of a pci card to conserve KVA
Date: Tue, 15 Feb 2005 14:03:12 -0700

> Andrew Gallatin wrote:
>
> > I maintain drivers for a PCI card which presents itself as having
> > 16MB of address space. Eg:
> >
> > mx0: <Myrinet PCIXE> mem 0xf9000000-0xf9ffffff irq 20 at device 3.0 on pci1
> >
> > However, most of that address space does not need to be mapped into
> > the host. Really, only a little over 2MB needs to be mapped (3 regions
> > with length 1024 bytes, 256 bytes, and 2MB).
> >
> > I've tried to re-write things so that I make multiple calls
> > to bus_alloc_resource() with the (hopefully) appropriate offset and
> > lengths. Eg:
> >
> > rid = PCIR_MAPS;
> > *res = bus_alloc_resource(is->arch.dev, SYS_RES_MEMORY, &rid,
> > (u_long)offset,
> > (u_long)(offset + len - 1), len,
> > RF_ACTIVE|PCI_RF_DENSE);
> >
> > At least on 5.3R, I seem to get back the same struct resource * from
> > each call. rman_get_virtual() returns a different kva for each
> > mapping, yet they all seem to map to the same physical address.
> > Eg, I call vtophys() on the results of rman_get_virtual(),
> > for each segment, and they all map to 0xf9000000.
> >
> > Is there a way to just map what I need?
> >
> > Thanks,
> >
> > Drew
> >
>

> You can use pmap_mapdev() to create a KVA mapping of an arbitrary
> physaddr+len. In fact, this is exactly what newbus uses to create the
> PCI MEMIO resources when bus_alloc_resource() is called. I'm not sure
> if the range is mapped and activated before the driver makes that call,
> Warner or John might know for sure.

If you go that route, you need to allocate the resource (all of it).
RF_ACTIVE in the flags, or bus_activate_resource is what maps it in,
so if you don't do that, you can call pmap_mamdev.

Warner

Daniel O'Connor

unread,
Feb 15, 2005, 8:54:37 PM2/15/05
to
--nextPart1181563.LWCu8OVLV4
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On Wed, 16 Feb 2005 07:23, Warner Losh wrote:
> > At least on 5.3R, I seem to get back the same struct resource * from
> > each call. rman_get_virtual() returns a different kva for each
> > mapping, yet they all seem to map to the same physical address.
> > Eg, I call vtophys() on the results of rman_get_virtual(),
> > for each segment, and they all map to 0xf9000000.
> >
> > Is there a way to just map what I need?
>

> There's no way to map part of a resource currently. I'd like to
> create an API to do that, since it would be useful for a lot of
> things, but none exists today. As soon as bus_activate_resource is
> called, it gets mapped.

You could do something like puc does and attach a child driver to part of i=
t=20
right?

(Stab in dark :)

=2D-=20
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C

--nextPart1181563.LWCu8OVLV4
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (FreeBSD)

iD8DBQBCEqeI5ZPcIHs/zowRAustAJ0VO1TpxQFZpgLsYfxC3fqZflM/CACgjybQ
oxt3L7/deob4c5QDAuM+wCs=
=fJao
-----END PGP SIGNATURE-----

--nextPart1181563.LWCu8OVLV4--

0 new messages