From mboxrd@z Thu Jan 1 00:00:00 1970 From: j.neuschaefer@gmx.net (Jonathan =?utf-8?Q?Neusch=C3=A4fer?=) Date: Tue, 7 May 2013 18:20:53 +0200 Subject: read PCI memory and config spyce through /dev/mem In-Reply-To: <6D83E89737156549AEA25EF9ED712C5D012D8D@DEFTHW99EK1MSX.ww902.siemens.net> References: <6D83E89737156549AEA25EF9ED712C5D01241D@DEFTHW99EK1MSX.ww902.siemens.net> <118536.1367853547@turing-police.cc.vt.edu> <6D83E89737156549AEA25EF9ED712C5D012D8D@DEFTHW99EK1MSX.ww902.siemens.net> Message-ID: <20130507162053.GA3194@debian.debian> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On Tue, May 07, 2013 at 06:35:43AM +0000, Warlich, Christof wrote: [...] > Furthermore, read / write access through a simple program using /dev/mem > _does_ work as expected: > > #include > #include > #include > #include > #include > int main( int argc, char *argv[]) { > char *mem; > int fd; > fd = open ("/dev/mem", O_RDWR); > assert(fd >= 0); > mem = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t) 0x81423000); > assert(mem != MAP_FAILED); > printf("Memory pointer: %p\n", mem); > printf("The PCI memory is : %#x\n", *mem); > *mem = *argv[1]; > printf("The PCI memory is : %#x\n", *mem); > munmap(mem, getpagesize()); > close(fd); > return 0; > } > > Calling it, yields: > > $ led 4 > Memory pointer: 0xb7678000 > The PCI memory is : 0x33 > The PCI memory is : 0x34 > > And the LED matrix display being behind that address switches from 3 to > 4 as expected. > > Thus, I still cannot see why the access through /dev/mem using dd doesn't > work. I suspect dd uses read instead of mmap. Thanks, Jonathan Neusch?fer