public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: "Gérard Roudier" <groudier@free.fr>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>,
	Jes Sorensen <jes@sunsite.dk>,
	paulus@samba.org, "David S. Miller" <davem@redhat.com>,
	linuxopinion@yahoo.com, linux-kernel@vger.kernel.org
Subject: Re: how to get virtual address from dma address
Date: Sun, 07 Oct 2001 18:02:15 -0500	[thread overview]
Message-ID: <200110072302.f97N2GX03070@localhost.localdomain> (raw)
In-Reply-To: Message from Gérard Roudier <groudier@free.fr>  of "Sun, 07 Oct 2001 20:24:26 +0200." <20011007195159.D1867-100000@gerard>

groudier@free.fr said:
> No problem. Here is the FULL simple code from SYM-2 driver that
> perform the reverse mapping (it is mostly the same in sym53c8xx): 

Well, since this piece of code isn't in the current kernel, it makes it more 
difficult, but it looks to me like there's an internal ccb structure in the 
driver that would contain pointers to the scsi command pointer, the dsa 
structure and various other things.  The dsa structure is the chip's internal 
representation of an outstanding command.  When a command is completed, you 
get a dma address of the dsa pointer back from the chip, so you do the 
sym_ccb_from_dsa() conversion to get the ccb and from that you get the virtual 
address of the dsa structure because you need to collect completion 
information about the command before sending it back into the mid-layer.

The way you do this is to walk a list of ccb structures hashed on the dsa 
pointer for efficient reverse lookup until you find the ccb of the returning 
dsa.

It's certainly a valid thing to do, I've done it before myself.  However, an 
equally valid way of processing a returning dsa is to embed a pointer to the 
ccb structure in the dsa structure.  Then to get back to the ccb you simply 
dereference the dsa structure.  The catch now is that I need the virtual 
address of the dsa pointer.  If I had the API I could do this.  How 
efficiently?  well on the x86 it's a simple bit flip to get the virtual 
address and away I go. The cost is O(1).  On the most opaque DMA hardware, the 
mappings would have to be stored separately in a hash table.  The cost of 
doing the lookup is O(number of pages registered for this device) which, since 
I would expect to pack a few dsa structures per page is less than O(total dsa 
structures).

Your method, providing only outstanding dsa structures are hashed, has an 
efficiency O(total outstanding commands).

So, for the worst case DMA hardware the two methods are very comparable (you 
can probably get each to beat the other by judicious tuning of the hash bucket 
size).  For the best case DMA hardware, my lookup is O(1) which is hard for a 
hash lookup to beat.

So, in summary we have two methods, each of which could beat the other under 
optimal hardware conditions.  Which should be used?  well that's up to the 
choice of the device driver writer.

My point here is that there isn't a choice any more because the API to do DMA 
to virtual address mappings is gone.  What I've done is proposed a replacement 
API that will have no impact on a device driver writer who doesn't want to use 
it.

The fact that you wouldn't use it is irrelevant to the argument, since I've no 
wish to force you to.  However, I do want the the freedom to write my drivers 
according to my choice of method.

So the outstanding point of debate still remains:  what is wrong with the 
proposed API?  The arguments I've heard so far are:

- It might be misused [true but not relevant].
- It would bloat the kernel [Actually, it would be implemented as #defines 
like the standard dma APIs, so would only bloat the kernel for hardware that 
has no window into the IOMMU]
- You can do the same thing differently [true, but you cannot do it as 
efficiently on optimal dma hardware].

James Bottomley



  reply	other threads:[~2001-10-07 23:03 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-03 22:44 how to get virtual address from dma address James Bottomley
2001-10-04  0:24 ` David S. Miller
2001-10-04 10:11   ` BALBIR SINGH
2001-10-04 11:16     ` David S. Miller
2001-10-04 15:37   ` James Bottomley
2001-10-05 14:06 ` Jes Sorensen
2001-10-06  8:06   ` Paul Mackerras
2001-10-06  8:38     ` David S. Miller
2001-10-06 12:18       ` Paul Mackerras
2001-10-06 14:45         ` James Bottomley
2001-10-06 16:51           ` Gérard Roudier
2001-10-06 17:23         ` Jes Sorensen
2001-10-07  2:13           ` Paul Mackerras
2001-10-07 17:40             ` Jes Sorensen
2001-10-07  7:21           ` Gérard Roudier
2001-10-07 16:23             ` James Bottomley
2001-10-07 18:24               ` Gérard Roudier
2001-10-07 23:02                 ` James Bottomley [this message]
2001-10-08 21:06                   ` Gérard Roudier
     [not found]       ` <mailman.1002371041.9232.linux-kernel2news@redhat.com>
2001-10-06 18:19         ` Pete Zaitcev
     [not found]   ` <mailman.1002355920.6872.linux-kernel2news@redhat.com>
2001-10-06 18:04     ` Pete Zaitcev
     [not found] <Pine.LNX.4.21.0110031525370.14852-100000@pogo.esscom.com>
2001-10-03 21:48 ` Linux Bigot
2001-10-03 22:03   ` Ben Collins
2001-10-05 14:04   ` Jes Sorensen
  -- strict thread matches above, loose matches on Subject: below --
2001-10-03 21:30 Manfred Spraul
2001-10-03 16:37 Linux Bigot
2001-10-03 19:32 ` Ben Collins
2001-10-03 21:11   ` Linux Bigot
2001-10-03 21:23     ` Ben Collins
2001-10-03 14:11 Linux Bigot
2001-10-03 15:25 ` Jes Sorensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200110072302.f97N2GX03070@localhost.localdomain \
    --to=james.bottomley@hansenpartnership.com \
    --cc=davem@redhat.com \
    --cc=groudier@free.fr \
    --cc=jes@sunsite.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxopinion@yahoo.com \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox