* Re: Problem trying to address custom hardware
@ 2004-08-25 7:50 Rupesh S
0 siblings, 0 replies; 6+ messages in thread
From: Rupesh S @ 2004-08-25 7:50 UTC (permalink / raw)
To: linuxppc-embedded; +Cc: oliver.king-smith
Hi Oliver,
I guess you are missing just the Chip Select initialization for the CPLD memory map.
--
Rupesh S
>>> Oliver King-Smith <oliver.king-smith@nuvation.com> 08/25/04 04:40AM >>>
Hello,
I am using a IBM405EP to run Linux. I am trying to add a CPLD to the
system that has a few registers I want to read and write from. This
device is wired physically to respond when it sees
0x40000000-0x40000010 on the PPC address pins. So I wrote the
following program:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#define CPLD_OFFSET 0x40000000
typedef struct{
unsigned long register1;
int register2;
}CPLD_REGISTERS;
#define CPLD_SIZE sizeof(CPLD_REGISTERS)
int main()
{
int memfd;
volatile CPLD_REGISTERS *pCPLD;
memfd = open("/dev/mem", O_RDWR);
if (memfd){
pCPLD = (CPLD_REGISTERS *) mmap(0,
CPLD_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE,
memfd, CPLD_OFFSET);
if( pCPLD>0 )
{
int readback;
printf( "CPLD located at virtual address %x\n",
(unsigned long) pCPLD );
pCPLD->register1 = 1; // !!!CRASH!!!
...
It maps into a part of virtual space that make
sense from other setups shown in /proc/#/maps. (i.e. pCPLD is 0x30150000)
The /proc/kmsg gives the following errors
<4>do_wp_page: bogus page at address 30015000 (page 0xc0d1f01c)
<4>VM: killing process mmap.out
This seems reasonable enough. So I tried mapping in a page to VM using a
small driver. I wrote the following code, and instantiated it with
insmod.
#define MODULE
#include <linux/module.h>
#define CPLD_P_ADDR 0x40000000
#define CPLD_V_ADDR 0xE8126000
typedef struct{
unsigned long register1;
unsigned long register2;
}CPLD_REGISTERS;
#define CPLD_SIZE sizeof(CPLD_REGISTERS)
volatile CPLD_REGISTERS *pCPLD;
int init_module(void)
{
printk( "<1> Hello World\n" );
pCPLD = (volatile CPLD_REGISTERS *)ioremap( CPLD_P_ADDR,
CPLD_SIZE );
if( pCPLD>0 )
{
printk( "CPLD located at virtual address %x and held at
%x\n", (unsigned long)pCPLD, (unsigned long)&pCPLD );
pCPLD->register1 = 1; // !!! CRASH !!!
...
And I get a crash again. The value for pCPLD is in the 0xC3xxxxxx range.
<1> init_module in cpld_module.c on line 22
<4>CPLD located at virtual address c3019000 and held at c3017390
<4>Data machine check in kernel mode.
<4>Oops: machine check, sig: 7
<4>NIP: C0014990 XER: 00000000 LR: C3017120 SP: C19ADDE0 REGS: c19add30
TRAP: 0200 Tainted: P
<4>MSR: 00009030 EE: 1 PR: 0 FP: 0 ME: 1 IR/DR: 11
<4>TASK = c19ac000[80] 'insmod' Last syscall: 128
<4>last math 00000000 last altivec 00000000
<4>PLB0: bear= 0x40000000 acr= 0x00000000 besr= 0x00c00000
<4>PLB0 to OPB: bear= 0x00000000 besr0= 0x00000000 besr1= 0x00000000
<4>
<4>GPR00: 01000000 C19ADDE0 C19AC000 C301724C 00000000 00000001
00000020 C01F0000
<4>GPR08: 000035BF C3019000 00000000 C19ADDEC 80042082 1003A0CC
00000000 00000000
<4>GPR16: 00000000 00000001 00000000 00000000 00009032 019ADF40
C19ADEA8 C1C25D00
<4>GPR24: 0000000B C19ADF0C 1003BA38 C3010000 C3010000 C19ADDE8
C3010000 C3010000
<4>Call backtrace:
<4>C0014AF0 C3017120 C0015D78 C000475C 1003BA38 10003A34 10004F2C
<4>10008CA8 10008EC8 0FECAC30 00000000
If anyone could tell me what I am doing wrong, I would greatly
appreciate it.
Oliver
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread* RE: Problem trying to address custom hardware
@ 2004-08-25 22:29 Oliver King-Smith
2004-08-25 23:05 ` Matt Porter
0 siblings, 1 reply; 6+ messages in thread
From: Oliver King-Smith @ 2004-08-25 22:29 UTC (permalink / raw)
To: 'linuxppc-embedded@lists.linuxppc.org'
Things are working much better. Both the driver and the main code work
without crashing now.
> Others addressed your core problem, but you should know that this
> mmap request won't produce the desired result. You need MAP_SHARED
> since MAP_PRIVATE will result in a COW when you attempt to modify
> your register.
I am not sure I understand why this needs to be MAP_SHARED (it sure does
though). Is there a good resource I can read to understand this a bit
better?
Oliver
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem trying to address custom hardware
2004-08-25 22:29 Oliver King-Smith
@ 2004-08-25 23:05 ` Matt Porter
0 siblings, 0 replies; 6+ messages in thread
From: Matt Porter @ 2004-08-25 23:05 UTC (permalink / raw)
To: Oliver King-Smith; +Cc: 'linuxppc-embedded@lists.linuxppc.org'
On Wed, Aug 25, 2004 at 03:29:20PM -0700, Oliver King-Smith wrote:
>
> Things are working much better. Both the driver and the main code work
> without crashing now.
>
> > Others addressed your core problem, but you should know that this
> > mmap request won't produce the desired result. You need MAP_SHARED
> > since MAP_PRIVATE will result in a COW when you attempt to modify
> > your register.
>
> I am not sure I understand why this needs to be MAP_SHARED (it sure does
> though). Is there a good resource I can read to understand this a bit
> better?
The mmap(2) manpage explains the difference pretty well. MAP_PRIVATE
indicates that any modification are local to the process. So, as
soon as you write to it, it makes a copy of the page for your process
to modify. MAP_SHARED indicates that any modifications are seen by
any processes that also map the region.
googling will probably yield many threads on lkml on this topic.
-Matt
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Problem trying to address custom hardware
@ 2004-08-24 23:10 Oliver King-Smith
2004-08-25 5:56 ` Eugene Surovegin
2004-08-25 17:40 ` Matt Porter
0 siblings, 2 replies; 6+ messages in thread
From: Oliver King-Smith @ 2004-08-24 23:10 UTC (permalink / raw)
To: 'linuxppc-embedded@lists.linuxppc.org'
Hello,
I am using a IBM405EP to run Linux. I am trying to add a CPLD to the
system that has a few registers I want to read and write from. This
device is wired physically to respond when it sees
0x40000000-0x40000010 on the PPC address pins. So I wrote the
following program:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#define CPLD_OFFSET 0x40000000
typedef struct{
unsigned long register1;
int register2;
}CPLD_REGISTERS;
#define CPLD_SIZE sizeof(CPLD_REGISTERS)
int main()
{
int memfd;
volatile CPLD_REGISTERS *pCPLD;
memfd = open("/dev/mem", O_RDWR);
if (memfd){
pCPLD = (CPLD_REGISTERS *) mmap(0,
CPLD_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE,
memfd, CPLD_OFFSET);
if( pCPLD>0 )
{
int readback;
printf( "CPLD located at virtual address %x\n",
(unsigned long) pCPLD );
pCPLD->register1 = 1; // !!!CRASH!!!
...
It maps into a part of virtual space that make
sense from other setups shown in /proc/#/maps. (i.e. pCPLD is 0x30150000)
The /proc/kmsg gives the following errors
<4>do_wp_page: bogus page at address 30015000 (page 0xc0d1f01c)
<4>VM: killing process mmap.out
This seems reasonable enough. So I tried mapping in a page to VM using a
small driver. I wrote the following code, and instantiated it with
insmod.
#define MODULE
#include <linux/module.h>
#define CPLD_P_ADDR 0x40000000
#define CPLD_V_ADDR 0xE8126000
typedef struct{
unsigned long register1;
unsigned long register2;
}CPLD_REGISTERS;
#define CPLD_SIZE sizeof(CPLD_REGISTERS)
volatile CPLD_REGISTERS *pCPLD;
int init_module(void)
{
printk( "<1> Hello World\n" );
pCPLD = (volatile CPLD_REGISTERS *)ioremap( CPLD_P_ADDR,
CPLD_SIZE );
if( pCPLD>0 )
{
printk( "CPLD located at virtual address %x and held at
%x\n", (unsigned long)pCPLD, (unsigned long)&pCPLD );
pCPLD->register1 = 1; // !!! CRASH !!!
...
And I get a crash again. The value for pCPLD is in the 0xC3xxxxxx range.
<1> init_module in cpld_module.c on line 22
<4>CPLD located at virtual address c3019000 and held at c3017390
<4>Data machine check in kernel mode.
<4>Oops: machine check, sig: 7
<4>NIP: C0014990 XER: 00000000 LR: C3017120 SP: C19ADDE0 REGS: c19add30
TRAP: 0200 Tainted: P
<4>MSR: 00009030 EE: 1 PR: 0 FP: 0 ME: 1 IR/DR: 11
<4>TASK = c19ac000[80] 'insmod' Last syscall: 128
<4>last math 00000000 last altivec 00000000
<4>PLB0: bear= 0x40000000 acr= 0x00000000 besr= 0x00c00000
<4>PLB0 to OPB: bear= 0x00000000 besr0= 0x00000000 besr1= 0x00000000
<4>
<4>GPR00: 01000000 C19ADDE0 C19AC000 C301724C 00000000 00000001
00000020 C01F0000
<4>GPR08: 000035BF C3019000 00000000 C19ADDEC 80042082 1003A0CC
00000000 00000000
<4>GPR16: 00000000 00000001 00000000 00000000 00009032 019ADF40
C19ADEA8 C1C25D00
<4>GPR24: 0000000B C19ADF0C 1003BA38 C3010000 C3010000 C19ADDE8
C3010000 C3010000
<4>Call backtrace:
<4>C0014AF0 C3017120 C0015D78 C000475C 1003BA38 10003A34 10004F2C
<4>10008CA8 10008EC8 0FECAC30 00000000
If anyone could tell me what I am doing wrong, I would greatly
appreciate it.
Oliver
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: Problem trying to address custom hardware
2004-08-24 23:10 Oliver King-Smith
@ 2004-08-25 5:56 ` Eugene Surovegin
2004-08-25 17:40 ` Matt Porter
1 sibling, 0 replies; 6+ messages in thread
From: Eugene Surovegin @ 2004-08-25 5:56 UTC (permalink / raw)
To: Oliver King-Smith; +Cc: linuxppc-embedded
On Tue, Aug 24, 2004 at 04:10:15PM -0700, Oliver King-Smith wrote:
[snip]
> pCPLD->register1 = 1; // !!! CRASH !!!
> ...
>
> And I get a crash again. The value for pCPLD is in the 0xC3xxxxxx range.
> <1> init_module in cpld_module.c on line 22
> <4>CPLD located at virtual address c3019000 and held at c3017390
> <4>Data machine check in kernel mode.
> <4>Oops: machine check, sig: 7
> <4>NIP: C0014990 XER: 00000000 LR: C3017120 SP: C19ADDE0 REGS: c19add30
> TRAP: 0200 Tainted: P
> <4>MSR: 00009030 EE: 1 PR: 0 FP: 0 ME: 1 IR/DR: 11
> <4>TASK = c19ac000[80] 'insmod' Last syscall: 128
> <4>last math 00000000 last altivec 00000000
> <4>PLB0: bear= 0x40000000 acr= 0x00000000 besr= 0x00c00000
> <4>PLB0 to OPB: bear= 0x00000000 besr0= 0x00000000 besr1= 0x00000000
> <4>
> <4>GPR00: 01000000 C19ADDE0 C19AC000 C301724C 00000000 00000001
> 00000020 C01F0000
> <4>GPR08: 000035BF C3019000 00000000 C19ADDEC 80042082 1003A0CC
> 00000000 00000000
> <4>GPR16: 00000000 00000001 00000000 00000000 00009032 019ADF40
> C19ADEA8 C1C25D00
> <4>GPR24: 0000000B C19ADF0C 1003BA38 C3010000 C3010000 C19ADDE8
> C3010000 C3010000
> <4>Call backtrace:
> <4>C0014AF0 C3017120 C0015D78 C000475C 1003BA38 10003A34 10004F2C
> <4>10008CA8 10008EC8 0FECAC30 00000000
>
> If anyone could tell me what I am doing wrong, I would greatly
> appreciate it.
>
Did you setup External Bus Controller registers (EBC0_BnCR and
EBC0_BnAP, where n is equal to the chip select line connected to PLD)?
I suspect you didn't that's why you got Machine Check error.
In fact, take a look at PLB0 registers from the crash log above:
PLB0_BEAR contains phys addr of the invalid access - 0x4000'0000,
PLB0_BESR contains error status - 0x00c0'0000, which means "master 2
(DCU) PLB timeout".
Please read "Chapter 16" in 405EP user manual for more info about
External Bus controller.
--
Eugene
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem trying to address custom hardware
2004-08-24 23:10 Oliver King-Smith
2004-08-25 5:56 ` Eugene Surovegin
@ 2004-08-25 17:40 ` Matt Porter
1 sibling, 0 replies; 6+ messages in thread
From: Matt Porter @ 2004-08-25 17:40 UTC (permalink / raw)
To: Oliver King-Smith; +Cc: 'linuxppc-embedded@lists.linuxppc.org'
[your mailer is really bad and should be fixed, this required heavy editing]
On Tue, Aug 24, 2004 at 04:10:15PM -0700, Oliver King-Smith wrote:
> memfd = open("/dev/mem", O_RDWR);
> if (memfd){
> pCPLD = (CPLD_REGISTERS *) mmap(0,
> CPLD_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE,
> memfd, CPLD_OFFSET);
Others addressed your core problem, but you should know that this
mmap request won't produce the desired result. You need MAP_SHARED
since MAP_PRIVATE will result in a COW when you attempt to modify
your register.
-Matt
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-08-25 23:05 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-25 7:50 Problem trying to address custom hardware Rupesh S
-- strict thread matches above, loose matches on Subject: below --
2004-08-25 22:29 Oliver King-Smith
2004-08-25 23:05 ` Matt Porter
2004-08-24 23:10 Oliver King-Smith
2004-08-25 5:56 ` Eugene Surovegin
2004-08-25 17:40 ` Matt Porter
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).