From owner-freebsd-hackers Tue May 9 2:58:53 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from critter.freebsd.dk (critter.freebsd.dk [212.242.40.131]) by hub.freebsd.org (Postfix) with ESMTP id E7AFE37B7EA for ; Tue, 9 May 2000 02:58:48 -0700 (PDT) (envelope-from phk@critter.freebsd.dk) Received: from critter.freebsd.dk (localhost.freebsd.dk [127.0.0.1]) by critter.freebsd.dk (8.9.3/8.9.3) with ESMTP id LAA24304; Tue, 9 May 2000 11:58:04 +0200 (CEST) (envelope-from phk@critter.freebsd.dk) To: Peter Edwards Cc: hackers@FreeBSD.ORG, Coleman Kane Subject: Re: mmap cdev function in device drivers In-reply-to: Your message of "Tue, 09 May 2000 10:55:19 BST." <3917E087.B2477FA0@openet-telecom.com> Date: Tue, 09 May 2000 11:58:04 +0200 Message-ID: <24302.957866284@critter.freebsd.dk> From: Poul-Henning Kamp Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG A good example to look at is the pci/xrpu.c file, that driver barely does anything but a mmap. Poul-Henning In message <3917E087.B2477FA0@openet-telecom.com>, Peter Edwards writes: >Hi, >Just trying to take some of the aforementioned "magic" out of i386_btop >/ vtop :-) > >> return( atop(vtophys(bktr->bigbuf) + offset) ); > >atop (I assume) stands for "address to page" (given a pointer, give the >number of the page it is in) >vtophys is "virtual to physical". (given a pointer in a virtual address >space, find out the physical address of the backing memory.) > >My understanding is that mmap(2) will allocate a portion of the calling >process's address space, and for each page it needs to map, will call >the device's mmap function, giving it the calculated offset (and the >protection attributes). > >The device's mmap returns the index of the physical page of the memory >to be inserted under the virtual addresses the process sees. > >simplified_mmap_syscall_for_device(dev_t device, size_t len, off_t >offset) >{ > caddr_t ptr = alloc_address_space(len); > > assert(ptr % PAGESIZE == 0); > > while (len) { > pageno = device->mmap(offset); /* Call device's mmap */ > map_address_to_page(ptr, pageno); > len -= PAGESIZE; > offset += PAGESIZE; > ptr += PAGESIZE; > } >} > >So, the call above is returning the page number (of the physical address >(of bktr->bigbuf)). > >Of course, My ignorance will probably be corrected in due course! >-- >Peter. > > >To Unsubscribe: send mail to majordomo@FreeBSD.org >with "unsubscribe freebsd-hackers" in the body of the message > -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD coreteam member | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message