Subversion Repositories HelenOS

Rev

Rev 3619 | Rev 3661 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2005 Jakub Vana
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup ia64
  30.  * @{
  31.  */
  32. /** @file
  33.  */
  34.  
  35. #include <arch.h>
  36. #include <arch/ski/ski.h>
  37. #include <arch/drivers/it.h>
  38. #include <arch/interrupt.h>
  39. #include <arch/barrier.h>
  40. #include <arch/asm.h>
  41. #include <arch/register.h>
  42. #include <arch/types.h>
  43. #include <arch/context.h>
  44. #include <arch/stack.h>
  45. #include <arch/mm/page.h>
  46. #include <mm/as.h>
  47. #include <config.h>
  48. #include <userspace.h>
  49. #include <console/console.h>
  50. #include <proc/uarg.h>
  51. #include <syscall/syscall.h>
  52. #include <ddi/irq.h>
  53. #include <ddi/device.h>
  54. #include <arch/drivers/ega.h>
  55. #include <arch/bootinfo.h>
  56. #include <genarch/kbd/i8042.h>
  57. #include <genarch/kbd/ns16550.h>
  58. #include <smp/smp.h>
  59. #include <smp/ipi.h>
  60. #include <arch/atomic.h>
  61. #include <panic.h>
  62. #include <print.h>
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. #ifdef CONFIG_SMP
  70.  
  71.  
  72. extern char cpu_by_id_eid_list[256][256];
  73.  
  74.  
  75. static void sapic_init(void)
  76. {
  77.     bootinfo->sapic=(unative_t *)(PA2KA((unative_t)(bootinfo->sapic))|FW_OFFSET);
  78. }
  79.  
  80.  
  81.  
  82. static void ipi_broadcast_arch_all(int ipi )
  83. {
  84.     int id,eid;
  85.     int myid,myeid;
  86.    
  87.     myid=ia64_get_cpu_id();
  88.     myeid=ia64_get_cpu_eid();
  89.  
  90.    
  91.     for(id=0;id<256;id++)
  92.         for(eid=0;eid<256;eid++)
  93.             if((id!=myid) || (eid!=myeid))
  94.                 ipi_send_ipi(id,eid,ipi);
  95. }
  96.  
  97. void ipi_broadcast_arch(int ipi )
  98. {
  99.     int id,eid;
  100.     int myid,myeid;
  101.    
  102.     myid=ia64_get_cpu_id();
  103.     myeid=ia64_get_cpu_eid();
  104.  
  105.     //printf("Sending ipi %d on %d\n",ipi,CPU->id);
  106.     for(id=0;id<256;id++)
  107.         for(eid=0;eid<256;eid++)
  108.             if((id!=myid) || (eid!=myeid))
  109.                 if(cpu_by_id_eid_list[id][eid])
  110.                     ipi_send_ipi(id,eid,ipi);
  111.  
  112. }
  113.  
  114.  
  115. void smp_init(void)
  116. {
  117.     sapic_init();
  118.     ipi_broadcast_arch_all(bootinfo->wakeup_intno);
  119.     volatile long long brk;
  120.         for(brk=0;brk<100LL*1024LL*1024LL;brk++); //wait a while before CPUs starts
  121.  
  122.     config.cpu_count=0;
  123.     int id,eid;
  124.    
  125.     for(id=0;id<256;id++)
  126.         for(eid=0;eid<256;eid++)
  127.                 if(cpu_by_id_eid_list[id][eid]==1){
  128.                     config.cpu_count++;
  129.                     cpu_by_id_eid_list[id][eid]=2;
  130.  
  131.             }
  132. }
  133.  
  134.  
  135. void kmp(void *arg __attribute__((unused)))
  136. {
  137.     int id,eid;
  138.     int myid,myeid;
  139.    
  140.     myid=ia64_get_cpu_id();
  141.     myeid=ia64_get_cpu_eid();
  142.  
  143.     for(id=0;id<256;id++)
  144.         for(eid=0;eid<256;eid++)
  145.                 if((id!=myid) || (eid!=myeid))
  146.                     if(cpu_by_id_eid_list[id][eid]!=0){
  147.                         if(cpu_by_id_eid_list[id][eid]==1){
  148.                    
  149.                             //config.cpu_count++;
  150.                             //cpu_by_id_eid_list[id][eid]=2;
  151.                             printf("Found Late CPU ID:%d EDI:%d Not added to system!!!\n",id,eid);
  152.                             continue;
  153.                             }
  154.                     cpu_by_id_eid_list[id][eid]=3;
  155.                     /*
  156.                      * There may be just one AP being initialized at
  157.                      * the time. After it comes completely up, it is
  158.                      * supposed to wake us up.
  159.                      */
  160.                     if (waitq_sleep_timeout(&ap_completion_wq, 1000000,
  161.                         SYNCH_FLAGS_NONE) == ESYNCH_TIMEOUT) {
  162.                         printf("%s: waiting for cpu ID:%d EID:%d"
  163.                             "timed out\n", __FUNCTION__,
  164.                             id, eid);
  165.                         }    
  166.        
  167.                 }
  168. }
  169. #endif
  170.  
  171.  
  172. /*This is just a hack for linking with assembler - may be removed in future*/
  173. #ifndef CONFIG_SMP
  174. void main_ap(void);
  175. void main_ap(void)
  176. {
  177.     while(1);
  178. }
  179.  
  180. #endif
  181.  
  182. /** @}
  183.  */
  184.  
  185.