<br><br>
<div class="gmail_quote">On Wed, Oct 19, 2011 at 11:02 AM, Vaibhav Jain <span dir="ltr"><<a href="mailto:vjoss197@gmail.com">vjoss197@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="im"><br><br>
<div class="gmail_quote">On Wed, Oct 19, 2011 at 10:57 AM, bob <span dir="ltr"><<a href="mailto:ilikepie420@live.com" target="_blank">ilikepie420@live.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<p>It would be nice to share your solution in case someone else comes into the same problem. </p></blockquote></div></div>Hi,<br><br>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".<br>
<br>Thanks<br><font color="#888888">Vaibhav Jain<br><br><br></font></blockquote></div>
<div> </div>
<div> </div>
<div>Hi,</div>
<div> </div>
<div>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).</div>
<div>Is is not possible to do this through a user-level program ?</div>
<div> </div>
<div> </div>
<div>Here's the code </div>
<div> </div>
<div>typedef unsigned int u32;</div>
<div>#define MAP_LEN 0x1000 //4 KB page<br>#define BUFLEN 100<br>#define APIC_BASE 0xfee00000<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</div>
<div>int apic_reset_cpu(cpu); <br>int cpu = 2;</div>
<div>int main(){<br>if ((apic_reset_cpu(cpu)) != 0)<br> printf("INIT & Startup failed!\n");<br>}</div>
<div><br>int apic_reset_cpu(int cpu)<br>{<br> unsigned long tmpaddress, apic_icr, *apic_phy_addr;<br> int fd, sleep_now=0;</div>
<div><br> printf("Assuming APIC physical base: %lx \n", APIC_BASE);<br> tmpaddress = (unsigned long) mmap(NULL, MAP_LEN, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)APIC_BASE);<br> <br> if(tmpaddress == (unsigned long)MAP_FAILED) //check if it worked<br>
{<br> perror("Mapping memory for absolute memory access failed.\n");<br> return -3;<br> }<br> <br> //prep ICR high<br> apic_icr = tmpaddress;<br> apic_icr |= APIC_ICR_high;<br> apic_phy_addr = (unsigned long *) apic_icr;<br>
<font style="BACKGROUND-COLOR: #ffff00"><strong> *apic_phy_addr = cpu << 24;<br></strong></font> <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</div>
<div> //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 >> 12);<br> sleep_now = usleep( 500 ); //sleep 500 usec </div>
<div> printf("Unmapping APIC Base page\n");<br> tmpaddress &= 0xfffff000;<br> munmap(tmpaddress, MAP_LEN); <br> <br> return 0;<br>}</div>
<div> </div>
<div> </div>
<div><br>Thanks</div>
<div>Vaibhav Jain</div>