phys(2) -- allow a process to access physical addresses !!

phys(2) -- allow a process to access physical addresses !!

Post by Andrew Hoddinot » Sat, 21 Dec 1996 04:00:00



I have just tripped over the above manual page, which comments that:

       "Since this function  is  not  implemented  as  of
       Linux  0.99.11,  it will always return -1 and set errno to
       ENOSYS."

Can anyone tell me what happened to phys [like was it ever implemented,
and if so where is it now?], or give me any pointers to other ways of
accessing physical memory from outside the kernel. (I need to write to
and read from a PCI device without the delay associated with the context
switch in and out ofthe kernel)

----------------------------------------------------------------------
Andrew Hoddinott                    Advanced Rendering Technology Ltd.
Software Engineer               Mount Pleasant House, 2 Mount Pleasant

http://www.art.co.uk/                 Tel. +44 1223 563854 Fax. 516520
PGP key fingerprint:  F1 AA FF 2E 61 7C 68 A8  C0 65 0A BC 52 65 69 0C

 
 
 

phys(2) -- allow a process to access physical addresses !!

Post by Mark Ha » Sun, 22 Dec 1996 04:00:00


Quote:> Can anyone tell me what happened to phys [like was it ever implemented,
> and if so where is it now?], or give me any pointers to other ways of
> accessing physical memory from outside the kernel. (I need to write to
> and read from a PCI device without the delay associated with the context
> switch in and out ofthe kernel)

phys seems pretty arcane and archaic from the (also bizarre) man page.
the obvious way to do this is (off the top of my head):

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>

void *
mapPhysical(void *phys, unsigned length, void *virt, int writable) {
    // ensure that the addresses are page-aligned,
    // and length is a page-multiple.
    int fd = open("/dev/kmem",(writable?O_RDWR:O_RDONLY));
    if (fd == -1) {
        perror("open failed");
        return (void*) -1;
    }
    return mmap(virt,
                length,
                PROT_READ | (writable?PROT_WRITE:0),
                MAP_PRIVATE | MAP_FILE | (virt?MAP_FIXED:0),
                fd,
                (off_t)phys);

Quote:}

int
main() {
    const unsigned len = 128*1024;
    unsigned short *screen =
        (unsigned short*) mapPhysical((void*)0xa0000, len, 0, 0);

    if (screen == (void*)-1) {
        perror("map failed");
        return 1;
    }
    for (unsigned i=0; i<len/2; i++)
        putchar(screen[i] & 0x00ffU);
    return 0;

Quote:}

this works, btw: grabs the VGA video buffer and spews out characters from it.

regards, mark hahn.
--

                                        http://neurocog.lrdc.pitt.edu/~hahn/

 
 
 

phys(2) -- allow a process to access physical addresses !!

Post by Itai Nahsho » Sun, 22 Dec 1996 04:00:00



> I have just tripped over the above manual page, which comments that:

>        "Since this function  is  not  implemented  as  of
>        Linux  0.99.11,  it will always return -1 and set errno to
>        ENOSYS."

> Can anyone tell me what happened to phys [like was it ever implemented,
> and if so where is it now?], or give me any pointers to other ways of
> accessing physical memory from outside the kernel. (I need to write to
> and read from a PCI device without the delay associated with the context
> switch in and out ofthe kernel)

AFAIK phys() was never implemented for linux and there is
really no reason to implement it.

If you need to access io port space look at the call
to ioperm (and read the IO-Port-Programming mini howto).

If you want to access a memory-mapped device you can open
"/dev/mem" and use mmap to map the physical addressees to the
address space of your process.

For both cases you may have to run the program with root
permissions.

Itai
--

 
 
 

1. How to allow access from a range of ip address in /etc/hosts.allow

Hi

I am newbie in linux networking.
My linux box is in network 212.1.2.128/25.
I want to allow some of ip addresses below to open
connection to my server (telnet, etc).
  212.1.2.192 - 212.1.2.212
Then how make a rule in /etc/hosts.allow ?
So far I made this rule:
  ALL:212.1.2.192/27
But the others (212.1.2.213-254) will be welcomed too :-(

TIA

~yudi

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Kernel 1.2.13: Files > 2MB via POP3 Brings Mail-Hub to its Knees

3. allow ia64 kernel to be virtually mapped from any physical address

4. Brouter or Roudge? :-)

5. YDL 1.2 Synergy VGM5 Virtual Address, Physical Address, Bus Address and remap_page_range (HELP!)

6. ghostcript and HP690

7. Virtual / Physical memory address access in drivers ? help ?

8. Help installing java on Slackware 3.4!

9. Accessing physical addresses from the kernel on ARM - part II

10. Access physical address space from user-level program

11. Deny access by physical port instead of source address?

12. Fail to access physical address under Alpha machine

13. Accessing a physical memory address in Solaris