kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* mmap local APIC address
@ 2011-10-15  0:22 Vaibhav Jain
  2011-10-15  4:10 ` Mulyadi Santosa
  0 siblings, 1 reply; 9+ messages in thread
From: Vaibhav Jain @ 2011-10-15  0:22 UTC (permalink / raw)
  To: kernelnewbies

Hi,

I am trying to map local APIC on an intel system (physical address
0xfee00000) in a user level program using mmap
but my mmap is failing saying "Bad file descriptor". I am not sure if this
problem is related to apic or
mmap. I am running the program as root.  Please help me figure this out.

Thanks
Vaibhav Jain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111014/e4deb3a1/attachment.html 

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

* mmap local APIC address
  2011-10-15  0:22 mmap local APIC address Vaibhav Jain
@ 2011-10-15  4:10 ` Mulyadi Santosa
  2011-10-19 17:12   ` Vaibhav Jain
  0 siblings, 1 reply; 9+ messages in thread
From: Mulyadi Santosa @ 2011-10-15  4:10 UTC (permalink / raw)
  To: kernelnewbies

hi...

On Sat, Oct 15, 2011 at 07:22, Vaibhav Jain <vjoss197@gmail.com> wrote:
> Hi,
>
> I am trying to map local APIC on an intel system (physical address
> 0xfee00000) in a user level program using mmap
> but my mmap is failing saying "Bad file descriptor". I am not sure if this
> problem is related to apic or
> mmap. I am running the program as root.??Please help me figure this out.

could you post the code?

anyway, check "man mmap" in "errors" section....the hint could be
found there.....

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

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

* mmap local APIC address
  2011-10-15  4:10 ` Mulyadi Santosa
@ 2011-10-19 17:12   ` Vaibhav Jain
  2011-10-19 17:19     ` Vaibhav Jain
  0 siblings, 1 reply; 9+ messages in thread
From: Vaibhav Jain @ 2011-10-19 17:12 UTC (permalink / raw)
  To: kernelnewbies

On Fri, Oct 14, 2011 at 9:10 PM, Mulyadi Santosa
<mulyadi.santosa@gmail.com>wrote:

> hi...
>
> On Sat, Oct 15, 2011 at 07:22, Vaibhav Jain <vjoss197@gmail.com> wrote:
> > Hi,
> >
> > I am trying to map local APIC on an intel system (physical address
> > 0xfee00000) in a user level program using mmap
> > but my mmap is failing saying "Bad file descriptor". I am not sure if
> this
> > problem is related to apic or
> > mmap. I am running the program as root.  Please help me figure this out.
>
> could you post the code?
>
> anyway, check "man mmap" in "errors" section....the hint could be
> found there.....
>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>


Hi,

Here's the code



typedef unsigned int u32;

#define MAP_LEN                 0x1000  //4 KB page
#define BUFLEN 100
*#define APIC_BASE               0xfee00000*
#define APIC_ICR_low            0xfee00300
#define APIC_ICR_high           0xfee00310
#define APIC_ICR_init           0x00000500
#define APIC_ICR_start          0x00000600
#define APIC_ICR_ASSERT_LVL_TRG 0x0000c000
#define BOUNCE_CODE        0x2000

int apic_reset_cpu(cpu);
int cpu = 2;

int main(){
if ((apic_reset_cpu(cpu)) != 0)
    printf("INIT & Startup failed!\n");
}


int apic_reset_cpu(int cpu)
{
  unsigned long tmpaddress, apic_icr, *apic_phy_addr;
  int fd, sleep_now=0;


  printf("Assuming APIC physical base: %lx \n", APIC_BASE);
  tmpaddress = (unsigned long) mmap(NULL, MAP_LEN, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, (off_t)APIC_BASE);

*  if(tmpaddress == (unsigned long)MAP_FAILED) //check if it worked
  {
    perror("Mapping memory for absolute memory access failed.\n");
    return -3;
  }*

  //prep ICR high
  apic_icr = tmpaddress;
  apic_icr |= APIC_ICR_high;
  apic_phy_addr = (unsigned long *) apic_icr;
  *apic_phy_addr = cpu << 24;

  //prep ICR low Send INIT and wait
  apic_icr = tmpaddress;
  apic_icr |= APIC_ICR_low;
  apic_phy_addr = (unsigned long *) apic_icr;
  *apic_phy_addr = APIC_ICR_init | APIC_ICR_ASSERT_LVL_TRG;
  sleep_now = usleep( 10000 ); //sleep 10 ms

  //prep for SIPI
  apic_icr = tmpaddress;
  apic_icr |= APIC_ICR_low;
  apic_phy_addr = (unsigned long *) apic_icr;
  *apic_phy_addr = APIC_ICR_start | (BOUNCE_CODE >> 12);
  sleep_now = usleep( 500 ); //sleep 500 usec

  printf("Unmapping APIC Base page\n");
  tmpaddress &= 0xfffff000;
  munmap(tmpaddress, MAP_LEN);

  return 0;
}

Thanks
Vaibhav Jain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111019/c666d46f/attachment.html 

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

* mmap local APIC address
  2011-10-19 17:12   ` Vaibhav Jain
@ 2011-10-19 17:19     ` Vaibhav Jain
  2011-10-19 17:57       ` bob
       [not found]       ` <BLU0-SMTP193E689128F94E5900AE5C98BEA0@phx.gbl>
  0 siblings, 2 replies; 9+ messages in thread
From: Vaibhav Jain @ 2011-10-19 17:19 UTC (permalink / raw)
  To: kernelnewbies

Hi,

Please ignore the email below. I am sorry I  made a very silly mistake.

Thanks
Vaibhav Jain

On Wed, Oct 19, 2011 at 10:12 AM, Vaibhav Jain <vjoss197@gmail.com> wrote:

> On Fri, Oct 14, 2011 at 9:10 PM, Mulyadi Santosa <
> mulyadi.santosa at gmail.com> wrote:
>
>> hi...
>>
>> On Sat, Oct 15, 2011 at 07:22, Vaibhav Jain <vjoss197@gmail.com> wrote:
>> > Hi,
>> >
>> > I am trying to map local APIC on an intel system (physical address
>> > 0xfee00000) in a user level program using mmap
>> > but my mmap is failing saying "Bad file descriptor". I am not sure if
>> this
>> > problem is related to apic or
>> > mmap. I am running the program as root.  Please help me figure this out.
>>
>> could you post the code?
>>
>> anyway, check "man mmap" in "errors" section....the hint could be
>> found there.....
>>
>> --
>> regards,
>>
>> Mulyadi Santosa
>> Freelance Linux trainer and consultant
>>
>> blog: the-hydra.blogspot.com
>> training: mulyaditraining.blogspot.com
>>
>
>
> Hi,
>
> Here's the code
>
>
>
> typedef unsigned int u32;
>
> #define MAP_LEN                 0x1000  //4 KB page
> #define BUFLEN 100
> *#define APIC_BASE               0xfee00000*
> #define APIC_ICR_low            0xfee00300
> #define APIC_ICR_high           0xfee00310
> #define APIC_ICR_init           0x00000500
> #define APIC_ICR_start          0x00000600
> #define APIC_ICR_ASSERT_LVL_TRG 0x0000c000
> #define BOUNCE_CODE        0x2000
>
> int apic_reset_cpu(cpu);
> int cpu = 2;
>
> int main(){
> if ((apic_reset_cpu(cpu)) != 0)
>     printf("INIT & Startup failed!\n");
> }
>
>
> int apic_reset_cpu(int cpu)
> {
>   unsigned long tmpaddress, apic_icr, *apic_phy_addr;
>   int fd, sleep_now=0;
>
>
>   printf("Assuming APIC physical base: %lx \n", APIC_BASE);
>   tmpaddress = (unsigned long) mmap(NULL, MAP_LEN, PROT_READ|PROT_WRITE,
> MAP_SHARED, fd, (off_t)APIC_BASE);
>
> *  if(tmpaddress == (unsigned long)MAP_FAILED) //check if it worked
>   {
>     perror("Mapping memory for absolute memory access failed.\n");
>     return -3;
>   }*
>
>   //prep ICR high
>   apic_icr = tmpaddress;
>   apic_icr |= APIC_ICR_high;
>   apic_phy_addr = (unsigned long *) apic_icr;
>   *apic_phy_addr = cpu << 24;
>
>   //prep ICR low Send INIT and wait
>   apic_icr = tmpaddress;
>   apic_icr |= APIC_ICR_low;
>   apic_phy_addr = (unsigned long *) apic_icr;
>   *apic_phy_addr = APIC_ICR_init | APIC_ICR_ASSERT_LVL_TRG;
>   sleep_now = usleep( 10000 ); //sleep 10 ms
>
>   //prep for SIPI
>   apic_icr = tmpaddress;
>   apic_icr |= APIC_ICR_low;
>   apic_phy_addr = (unsigned long *) apic_icr;
>   *apic_phy_addr = APIC_ICR_start | (BOUNCE_CODE >> 12);
>   sleep_now = usleep( 500 ); //sleep 500 usec
>
>   printf("Unmapping APIC Base page\n");
>   tmpaddress &= 0xfffff000;
>   munmap(tmpaddress, MAP_LEN);
>
>   return 0;
> }
>
> Thanks
> Vaibhav Jain
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111019/454996ea/attachment.html 

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

* mmap local APIC address
  2011-10-19 17:19     ` Vaibhav Jain
@ 2011-10-19 17:57       ` bob
       [not found]       ` <BLU0-SMTP193E689128F94E5900AE5C98BEA0@phx.gbl>
  1 sibling, 0 replies; 9+ messages in thread
From: bob @ 2011-10-19 17:57 UTC (permalink / raw)
  To: kernelnewbies

It would be nice to share your solution in case someone else comes into the
same problem.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111019/ea241230/attachment.html 

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

* mmap local APIC address
       [not found]       ` <BLU0-SMTP193E689128F94E5900AE5C98BEA0@phx.gbl>
@ 2011-10-19 18:02         ` Vaibhav Jain
  2011-10-20 18:50           ` Vaibhav Jain
  0 siblings, 1 reply; 9+ messages in thread
From: Vaibhav Jain @ 2011-10-19 18:02 UTC (permalink / raw)
  To: kernelnewbies

On Wed, Oct 19, 2011 at 10:57 AM, bob <ilikepie420@live.com> wrote:

> It would be nice to share your solution in case someone else comes into the
> same problem.
>
Hi,

It was stupid mistake. I forgot to initialize the file descriptor which was
passed to  mmap and therefore it was throwing "Bad file descriptor" error.i
realized it after looking the errors in "man mmap".

Thanks
Vaibhav Jain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111019/dab72cf9/attachment-0001.html 

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

* mmap local APIC address
  2011-10-19 18:02         ` Vaibhav Jain
@ 2011-10-20 18:50           ` Vaibhav Jain
  2011-10-20 19:07             ` bob
  0 siblings, 1 reply; 9+ messages in thread
From: Vaibhav Jain @ 2011-10-20 18:50 UTC (permalink / raw)
  To: kernelnewbies

On Wed, Oct 19, 2011 at 11:02 AM, Vaibhav Jain <vjoss197@gmail.com> wrote:

>
>
> On Wed, Oct 19, 2011 at 10:57 AM, bob <ilikepie420@live.com> wrote:
>
>> It would be nice to share your solution in case someone else comes into
>> the same problem.
>>
> Hi,
>
> It was stupid mistake. I forgot to initialize the file descriptor which was
> passed to  mmap and therefore it was throwing "Bad file descriptor" error.i
> realized it after looking the errors in "man mmap".
>
> Thanks
> Vaibhav Jain
>
>
>

Hi,

I am now having another problem with the code. It throws a segmentation
fault as soon as it tries to write something into the ICR of the APIC.(line
highlighted below).
Is is not possible to do this through a user-level program ?


Here's the code

typedef unsigned int u32;
#define MAP_LEN                 0x1000  //4 KB page
#define BUFLEN 100
#define APIC_BASE               0xfee00000
#define APIC_ICR_low            0xfee00300
#define APIC_ICR_high           0xfee00310
#define APIC_ICR_init           0x00000500
#define APIC_ICR_start          0x00000600
#define APIC_ICR_ASSERT_LVL_TRG 0x0000c000
#define BOUNCE_CODE        0x2000
int apic_reset_cpu(cpu);
int cpu = 2;
int main(){
if ((apic_reset_cpu(cpu)) != 0)
    printf("INIT & Startup failed!\n");
}

int apic_reset_cpu(int cpu)
{
  unsigned long tmpaddress, apic_icr, *apic_phy_addr;
  int fd, sleep_now=0;

  printf("Assuming APIC physical base: %lx \n", APIC_BASE);
  tmpaddress = (unsigned long) mmap(NULL, MAP_LEN, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, (off_t)APIC_BASE);

  if(tmpaddress == (unsigned long)MAP_FAILED) //check if it worked
  {
    perror("Mapping memory for absolute memory access failed.\n");
    return -3;
  }

  //prep ICR high
  apic_icr = tmpaddress;
  apic_icr |= APIC_ICR_high;
  apic_phy_addr = (unsigned long *) apic_icr;
 * *apic_phy_addr = cpu << 24;
*
  //prep ICR low Send INIT and wait
  apic_icr = tmpaddress;
  apic_icr |= APIC_ICR_low;
  apic_phy_addr = (unsigned long *) apic_icr;
  *apic_phy_addr = APIC_ICR_init | APIC_ICR_ASSERT_LVL_TRG;
  sleep_now = usleep( 10000 ); //sleep 10 ms
  //prep for SIPI
  apic_icr = tmpaddress;
  apic_icr |= APIC_ICR_low;
  apic_phy_addr = (unsigned long *) apic_icr;
  *apic_phy_addr = APIC_ICR_start | (BOUNCE_CODE >> 12);
  sleep_now = usleep( 500 ); //sleep 500 usec
  printf("Unmapping APIC Base page\n");
  tmpaddress &= 0xfffff000;
  munmap(tmpaddress, MAP_LEN);

  return 0;
}



Thanks
Vaibhav Jain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111020/5e2f552e/attachment.html 

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

* mmap local APIC address
  2011-10-20 18:50           ` Vaibhav Jain
@ 2011-10-20 19:07             ` bob
  2011-10-21 17:55               ` Vaibhav Jain
  0 siblings, 1 reply; 9+ messages in thread
From: bob @ 2011-10-20 19:07 UTC (permalink / raw)
  To: kernelnewbies

> #define APIC_ICR_high           0xfee00310

>   apic_icr = tmpaddress;
>   apic_icr |= APIC_ICR_high;
>   apic_phy_addr = (unsigned long *) apic_icr;
>   *apic_phy_addr = cpu << 24;

You mangled apic_icr here, APIC_ICR_high should be an offset. Look at
the definitions in arch/x86/include/asm/apicdef.h.

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

* mmap local APIC address
  2011-10-20 19:07             ` bob
@ 2011-10-21 17:55               ` Vaibhav Jain
  0 siblings, 0 replies; 9+ messages in thread
From: Vaibhav Jain @ 2011-10-21 17:55 UTC (permalink / raw)
  To: kernelnewbies

On Thu, Oct 20, 2011 at 12:07 PM, bob <ilikepie420@live.com> wrote:

> > #define APIC_ICR_high           0xfee00310
>
> >   apic_icr = tmpaddress;
> >   apic_icr |= APIC_ICR_high;
> >   apic_phy_addr = (unsigned long *) apic_icr;
> >   *apic_phy_addr = cpu << 24;
>
> You mangled apic_icr here, APIC_ICR_high should be an offset. Look at
> the definitions in arch/x86/include/asm/apicdef.h.
>

My bad!! Thanks Bob for pointing it out.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111021/23d285a7/attachment.html 

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

end of thread, other threads:[~2011-10-21 17:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-15  0:22 mmap local APIC address Vaibhav Jain
2011-10-15  4:10 ` Mulyadi Santosa
2011-10-19 17:12   ` Vaibhav Jain
2011-10-19 17:19     ` Vaibhav Jain
2011-10-19 17:57       ` bob
     [not found]       ` <BLU0-SMTP193E689128F94E5900AE5C98BEA0@phx.gbl>
2011-10-19 18:02         ` Vaibhav Jain
2011-10-20 18:50           ` Vaibhav Jain
2011-10-20 19:07             ` bob
2011-10-21 17:55               ` Vaibhav Jain

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