<div class="gmail_quote">On Fri, Oct 14, 2011 at 9:10 PM, Mulyadi Santosa <span dir="ltr"><<a href="mailto:mulyadi.santosa@gmail.com">mulyadi.santosa@gmail.com</a>></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 class="h5"><br>
On Sat, Oct 15, 2011 at 07:22, Vaibhav Jain <<a href="mailto:vjoss197@gmail.com">vjoss197@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> I am trying to map local APIC on an intel system (physical address<br>
> 0xfee00000) in a user level program using mmap<br>
> but my mmap is failing saying "Bad file descriptor". I am not sure if this<br>
> problem is related to apic or<br>
> 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 "man mmap" in "errors" 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>Hi,<br><br>Here'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("INIT & Startup failed!\n");<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("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><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("Mapping memory for absolute memory access failed.\n");</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 << 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 >> 12);<br> sleep_now = usleep( 500 ); //sleep 500 usec <br><br> printf("Unmapping APIC Base page\n");<br>
tmpaddress &= 0xfffff000;<br> munmap(tmpaddress, MAP_LEN); <br> <br> return 0;<br>}<br><br>Thanks<br>Vaibhav Jain<br>