Hi,<br><br>Please ignore the email below. I am sorry I  made a very silly mistake.<br><br>Thanks<br>Vaibhav Jain<br><br><div class="gmail_quote">On Wed, Oct 19, 2011 at 10:12 AM, Vaibhav Jain <span dir="ltr">&lt;<a href="mailto:vjoss197@gmail.com">vjoss197@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5"><div class="gmail_quote">On Fri, Oct 14, 2011 at 9:10 PM, Mulyadi Santosa <span dir="ltr">&lt;<a href="mailto:mulyadi.santosa@gmail.com" target="_blank">mulyadi.santosa@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
hi...<br>
<div><div></div><div><br>
On Sat, Oct 15, 2011 at 07:22, Vaibhav Jain &lt;<a href="mailto:vjoss197@gmail.com" target="_blank">vjoss197@gmail.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; I am trying to map local APIC on an intel system (physical address<br>
&gt; 0xfee00000) in a user level program using mmap<br>
&gt; but my mmap is failing saying &quot;Bad file descriptor&quot;. I am not sure if this<br>
&gt; problem is related to apic or<br>
&gt; mmap. I am running the program as root.  Please help me figure this out.<br>
<br>
</div></div>could you post the code?<br>
<br>
anyway, check &quot;man mmap&quot; in &quot;errors&quot; section....the hint could be<br>
found there.....<br>
<font color="#888888"><br>
--<br>
regards,<br>
<br>
Mulyadi Santosa<br>
Freelance Linux trainer and consultant<br>
<br>
blog: <a href="http://the-hydra.blogspot.com" target="_blank">the-hydra.blogspot.com</a><br>
training: <a href="http://mulyaditraining.blogspot.com" target="_blank">mulyaditraining.blogspot.com</a><br>
</font></blockquote></div><br><br></div></div>Hi,<br><br>Here&#39;s the code <br><br><br><br>typedef unsigned int u32;<br><br>#define MAP_LEN                 0x1000  //4 KB page<br>#define BUFLEN 100<br><b>#define APIC_BASE               0xfee00000</b><br>

#define APIC_ICR_low            0xfee00300<br>#define APIC_ICR_high           0xfee00310<br>#define APIC_ICR_init           0x00000500<br>#define APIC_ICR_start          0x00000600<br>#define APIC_ICR_ASSERT_LVL_TRG 0x0000c000<br>

#define BOUNCE_CODE        0x2000<br><br>int apic_reset_cpu(cpu); <br>int cpu = 2;<br><br>int main(){<br>if ((apic_reset_cpu(cpu)) != 0)<br>    printf(&quot;INIT &amp; Startup failed!\n&quot;);<br>}<br><br><br>int apic_reset_cpu(int cpu)<br>

{<br>  unsigned long tmpaddress, apic_icr, *apic_phy_addr;<br>  int fd, sleep_now=0;<br><br><br>  printf(&quot;Assuming APIC physical base: %lx \n&quot;, APIC_BASE);<br>  tmpaddress = (unsigned long) mmap(NULL, MAP_LEN, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)APIC_BASE);<br>

  <br><b><span style="background-color:rgb(255, 255, 153)"> <span style="background-color:rgb(255, 255, 255)"> if(tmpaddress == (unsigned long)MAP_FAILED) //check if it worked</span></span><br style="background-color:rgb(255, 255, 255)">

<span style="background-color:rgb(255, 255, 255)">  {</span><br style="background-color:rgb(255, 255, 255)"><span style="background-color:rgb(255, 255, 255)">    perror(&quot;Mapping memory for absolute memory access failed.\n&quot;);</span><br style="background-color:rgb(255, 255, 255)">

<span style="background-color:rgb(255, 255, 255)">    return -3;</span><br style="background-color:rgb(255, 255, 255)"><span style="background-color:rgb(255, 255, 255)">  }</span></b><br>  <br>  //prep ICR high<br>  apic_icr = tmpaddress;<br>

  apic_icr |= APIC_ICR_high;<br>  apic_phy_addr = (unsigned long *) apic_icr;<br>  *apic_phy_addr = cpu &lt;&lt; 24;<br>  <br>  //prep ICR low Send INIT and wait<br>  apic_icr = tmpaddress;<br>  apic_icr |= APIC_ICR_low;<br>

  apic_phy_addr = (unsigned long *) apic_icr;<br>  *apic_phy_addr = APIC_ICR_init | APIC_ICR_ASSERT_LVL_TRG;<br>  sleep_now = usleep( 10000 ); //sleep 10 ms<br><br>  //prep for SIPI<br>  apic_icr = tmpaddress;<br>  apic_icr |= APIC_ICR_low;<br>

  apic_phy_addr = (unsigned long *) apic_icr;<br>  *apic_phy_addr = APIC_ICR_start | (BOUNCE_CODE &gt;&gt; 12);<br>  sleep_now = usleep( 500 ); //sleep 500 usec <br><br>  printf(&quot;Unmapping APIC Base page\n&quot;);<br>

  tmpaddress &amp;= 0xfffff000;<br>  munmap(tmpaddress, MAP_LEN);  <br>  <br>  return 0;<br>}<br><br>Thanks<br><font color="#888888">Vaibhav Jain<br>
</font></blockquote></div><br>