linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* mmap
@ 2001-05-15  6:47 mdaljeet
  2001-05-15  7:33 ` mmap Gerd Knorr
  2001-05-15  9:42 ` mmap Alan Cox
  0 siblings, 2 replies; 8+ messages in thread
From: mdaljeet @ 2001-05-15  6:47 UTC (permalink / raw)
  To: linux-kernel

I am doing the following:

   malloc some memory is user space
   pass its pointer to some kernel module
   in the kernel module...do a pci_alloc_consistent so that i get a memory
   region for PCI DMA operations

now the problem is that i want to remap the address range pointed by the
user space pointer to the memory region allocated by the
'pci_alloc_consistent' inside the module. I think this is possible..need
some hints....

thanks,
Daljeet Maini
IBM Global Services Ltd. - Bangalore
Ph. No. - 5267117 Extn 2954



^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: mmap
@ 2001-05-15 10:08 mdaljeet
  0 siblings, 0 replies; 8+ messages in thread
From: mdaljeet @ 2001-05-15 10:08 UTC (permalink / raw)
  To: Gerd Knorr; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1077 bytes --]

When I malloc the memory in user space, the memory may be discontinuous for
large chunks of memory say 16k or 32k. Does the 'kiobuf' interface take
care of this or it assumes it to be continuous?

regards,
Daljeet Maini
IBM Global Services Ltd. - Bangalore
Ph. No. - 5267117 Extn 2954


|--------+----------------------->
|        |          Gerd Knorr   |
|        |          <kraxel@bytes|
|        |          ex.org>      |
|        |                       |
|        |          05/15/01     |
|        |          01:03 PM     |
|        |          Please       |
|        |          respond to   |
|        |          Gerd Knorr   |
|        |                       |
|--------+----------------------->
  >--------------------------------------------------------|
  |                                                        |
  |       To:     linux-kernel@vger.kernel.org             |
  |       cc:     (bcc: Daljeet Maini/India/IBM)           |
  |       Subject:     Re: mmap                            |
  >--------------------------------------------------------|





[-- Attachment #2: Type: text/plain, Size: 1125 bytes --]



mdaljeet@in.ibm.com wrote:
>  I am doing the following:
>
>     malloc some memory is user space
>     pass its pointer to some kernel module
>     in the kernel module...do a pci_alloc_consistent so that i get a
memory
>     region for PCI DMA operations

Wrong approach, you can use kiobufs if you want DMA to the malloc()ed
userspace memory:

 * lock down the user memory using map_user_kiobuf() + lock_kiovec()
   (see linux/iobuf.h).
 * translate the iobuf->maplist into a scatterlist [1]
 * feed pci_map_sg() with the scatterlist to get DMA addresses.
   you can pass to the hardware.

And the reverse to free everything when you are done of course.

  Gerd

[1] IMHO it would be more useful if iobufs would use a scatterlist
    instead of an struct page* array.


--
Gerd Knorr <kraxel@bytesex.org>  --  SuSE Labs, Außenstelle Berlin
-
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] 8+ messages in thread
* Re: mmap
@ 2001-07-02 14:00 mdaljeet
  2001-07-03 17:47 ` mmap Jens Axboe
  0 siblings, 1 reply; 8+ messages in thread
From: mdaljeet @ 2001-07-02 14:00 UTC (permalink / raw)
  To: Gerd Knorr; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1313 bytes --]

I use the 'map_user_kiobuf' and 'lock_kiovec' kernel routines in a module
for 'user space memory'. After that if I pass the
'(iobuf->maplist[0])-mem_map) <<  PAGE_SHIFT)' to the hardware for DMA
operations and it works fine for Intel platforms. Now how can I use the
'iobuf' struct obtained after lock_kiovec operation to get a PCI bus
address that I can pass to hardware for DMA operations on my Apple
machine.?

thanks,
Daljeet.


|--------+----------------------->
|        |          Gerd Knorr   |
|        |          <kraxel@bytes|
|        |          ex.org>      |
|        |                       |
|        |          05/15/01     |
|        |          01:03 PM     |
|        |          Please       |
|        |          respond to   |
|        |          Gerd Knorr   |
|        |                       |
|--------+----------------------->
  >-----------------------------------------------------------------------|
  |                                                                       |
  |       To:     linux-kernel@vger.kernel.org                            |
  |       cc:     (bcc: Daljeet Maini/India/IBM)                          |
  |       Subject:     Re: mmap                                           |
  >-----------------------------------------------------------------------|





[-- Attachment #2: Type: text/plain, Size: 1125 bytes --]



mdaljeet@in.ibm.com wrote:
>  I am doing the following:
>
>     malloc some memory is user space
>     pass its pointer to some kernel module
>     in the kernel module...do a pci_alloc_consistent so that i get a
memory
>     region for PCI DMA operations

Wrong approach, you can use kiobufs if you want DMA to the malloc()ed
userspace memory:

 * lock down the user memory using map_user_kiobuf() + lock_kiovec()
   (see linux/iobuf.h).
 * translate the iobuf->maplist into a scatterlist [1]
 * feed pci_map_sg() with the scatterlist to get DMA addresses.
   you can pass to the hardware.

And the reverse to free everything when you are done of course.

  Gerd

[1] IMHO it would be more useful if iobufs would use a scatterlist
    instead of an struct page* array.


--
Gerd Knorr <kraxel@bytesex.org>  --  SuSE Labs, Außenstelle Berlin
-
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] 8+ messages in thread
* mmap
@ 2011-12-02 12:20 Sébastien Paumier
  2011-12-02 14:45 ` mmap Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: Sébastien Paumier @ 2011-12-02 12:20 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 699 bytes --]

Hi,
I have a question about mmap's behavior when one tries to map a file asking for 
a length greater than the actual file size. When I run the attached code on a 
100 bytes file, I have the following output:

(... file content followed by zeros...)
n=4096
write: Bad address

So, it seems that the actual memory area provided by mmap is one page large and 
not the requested length of filesize+10000. I guess that 'write' writes less 
than requested because it was interrupted by the SIGBUS signal. And my question is:

shouldn't mmap either complain about the requested length or provide an 
accessible area of the requested length, instead of silently failing ?

Best regards,
Sébastien Paumier

[-- Attachment #2: mmap.c --]
[-- Type: text/x-csrc, Size: 884 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <signal.h>
#include <time.h>
#include <errno.h>

int main(int argc, char* argv[]){
if(argc != 2) {
	fprintf(stderr,"Usage: %s <file>\n",argv[0]);
	exit(1);
}
int fd = open(argv[argc-1],O_RDONLY);
if (fd==-1) {
	perror("open");
	return 1;
}
struct stat status;
if(-1 == fstat(fd,&status)){
	perror("fstat");
	return 1;
}
char* mem=(char*) mmap(NULL, status.st_size+10000, PROT_READ, MAP_PRIVATE,fd,0);
if(mem == MAP_FAILED){
	perror("mmap");
	return 1;
}
int n;
if ( -1 == (n=write(1,mem, status.st_size+10000))) {
	perror("write");
	return 1;
}
printf("\nn=%d\n",n);
if( -1 == (n=write(1,mem+n, status.st_size+10000-n))) {
	perror("write");
	return 1;
}
printf("\nn=%d\n",n);
return 0;
}

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

end of thread, other threads:[~2011-12-02 14:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-15  6:47 mmap mdaljeet
2001-05-15  7:33 ` mmap Gerd Knorr
2001-05-15  9:42 ` mmap Alan Cox
2001-05-15 10:08 mmap mdaljeet
2001-07-02 14:00 mmap mdaljeet
2001-07-03 17:47 ` mmap Jens Axboe
2011-12-02 12:20 mmap Sébastien Paumier
2011-12-02 14:45 ` mmap Eric Dumazet

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