ioapic: Pass ioapic address to ioapic_{read,write}()
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 14 Feb 2011 09:25:33 +0000 (17:25 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 14 Feb 2011 09:44:33 +0000 (17:44 +0800)
This makes easier for us to get rid of the ioapic addresses array.

sys/platform/pc32/apic/ioapic_abi.c
sys/platform/pc32/apic/ioapic_ipl.s
sys/platform/pc32/apic/mpapic.c
sys/platform/pc32/i386/mp_machdep.c
sys/platform/pc32/include/smp.h
sys/platform/pc64/apic/ioapic_abi.c
sys/platform/pc64/apic/ioapic_ipl.s
sys/platform/pc64/apic/mpapic.c
sys/platform/pc64/include/smp.h
sys/platform/pc64/x86_64/mp_machdep.c

index 671b6d2..6190cff 100644 (file)
@@ -644,13 +644,13 @@ ioapic_vectorctl(int op, int intr, int flags)
                        imen_lock();
 
                        select = int_to_apicintpin[intr].redirindex;
-                       value = ioapic_read(int_to_apicintpin[intr].ioapic,
+                       value = ioapic_read(int_to_apicintpin[intr].apic_address,
                                            select);
                        value |= IOART_INTMSET;
 
-                       ioapic_write(int_to_apicintpin[intr].ioapic,
+                       ioapic_write(int_to_apicintpin[intr].apic_address,
                                     select, (value & ~APIC_TRIGMOD_MASK));
-                       ioapic_write(int_to_apicintpin[intr].ioapic,
+                       ioapic_write(int_to_apicintpin[intr].apic_address,
                                     select, (value & ~IOART_INTVEC) | vector);
 
                        imen_unlock();
@@ -680,12 +680,12 @@ ioapic_vectorctl(int op, int intr, int flags)
                        imen_lock();
 
                        select = int_to_apicintpin[intr].redirindex;
-                       value = ioapic_read(int_to_apicintpin[intr].ioapic,
+                       value = ioapic_read(int_to_apicintpin[intr].apic_address,
                                            select);
 
-                       ioapic_write(int_to_apicintpin[intr].ioapic,
+                       ioapic_write(int_to_apicintpin[intr].apic_address,
                                     select, (value & ~APIC_TRIGMOD_MASK));
-                       ioapic_write(int_to_apicintpin[intr].ioapic,
+                       ioapic_write(int_to_apicintpin[intr].apic_address,
                                     select, (value & ~IOART_INTVEC) | vector);
 
                        imen_unlock();
index 6339548..a221376 100644 (file)
@@ -114,24 +114,20 @@ ENTRY(IOAPIC_INTREN)
  */
 
 /*
- * u_int ioapic_write(int apic, int select);
+ * u_int ioapic_read(volatile void *ioapic, int select);
  */
 ENTRY(ioapic_read)
-       movl    4(%esp), %ecx           /* IOAPIC # */
-       movl    ioapic, %eax
-       movl    (%eax,%ecx,4), %edx     /* IOAPIC base register address */
+       movl    4(%esp), %edx           /* IOAPIC base register address */
        movl    8(%esp), %eax           /* target register index */
        movl    %eax, (%edx)            /* write the target register index */
        movl    IOAPIC_WINDOW(%edx), %eax /* read the IOAPIC register data */
        ret                             /* %eax = register value */
 
 /*
- * void ioapic_write(int apic, int select, int value);
+ * void ioapic_write(volatile void *ioapic, int select, int value);
  */
 ENTRY(ioapic_write)
-       movl    4(%esp), %ecx           /* IOAPIC # */
-       movl    ioapic, %eax
-       movl    (%eax,%ecx,4), %edx     /* IOAPIC base register address */
+       movl    4(%esp), %edx           /* IOAPIC base register address */
        movl    8(%esp), %eax           /* target register index */
        movl    %eax, (%edx)            /* write the target register index */
        movl    12(%esp), %eax          /* target register value */
index 6584311..136556d 100644 (file)
@@ -435,15 +435,15 @@ io_apic_set_id(int apic, int id)
 {
        u_int32_t ux;
        
-       ux = ioapic_read(apic, IOAPIC_ID);      /* get current contents */
+       ux = ioapic_read(ioapic[apic], IOAPIC_ID);      /* get current contents */
        if (((ux & APIC_ID_MASK) >> 24) != id) {
                kprintf("Changing APIC ID for IO APIC #%d"
                       " from %d to %d on chip\n",
                       apic, ((ux & APIC_ID_MASK) >> 24), id);
                ux &= ~APIC_ID_MASK;    /* clear the ID field */
                ux |= (id << 24);
-               ioapic_write(apic, IOAPIC_ID, ux);      /* write new value */
-               ux = ioapic_read(apic, IOAPIC_ID);      /* re-read && test */
+               ioapic_write(ioapic[apic], IOAPIC_ID, ux);      /* write new value */
+               ux = ioapic_read(ioapic[apic], IOAPIC_ID);      /* re-read && test */
                if (((ux & APIC_ID_MASK) >> 24) != id)
                        panic("can't control IO APIC #%d ID, reg: 0x%08x",
                              apic, ux);
@@ -454,7 +454,7 @@ io_apic_set_id(int apic, int id)
 int
 io_apic_get_id(int apic)
 {
-  return (ioapic_read(apic, IOAPIC_ID) & APIC_ID_MASK) >> 24;
+  return (ioapic_read(ioapic[apic], IOAPIC_ID) & APIC_ID_MASK) >> 24;
 }
   
 
@@ -490,17 +490,17 @@ io_apic_setup_intpin(int apic, int pin)
         */
        imen_lock();
 
-       flags = ioapic_read(apic, select) & IOART_RESV;
+       flags = ioapic_read(ioapic[apic], select) & IOART_RESV;
        flags |= IOART_INTMSET | IOART_TRGREDG | IOART_INTAHI;
        flags |= IOART_DESTPHY | IOART_DELFIXED;
 
-       target = ioapic_read(apic, select + 1) & IOART_HI_DEST_RESV;
+       target = ioapic_read(ioapic[apic], select + 1) & IOART_HI_DEST_RESV;
        target |= 0;    /* fixed mode cpu mask of 0 - don't deliver anywhere */
 
        vector = 0;
 
-       ioapic_write(apic, select, flags | vector);
-       ioapic_write(apic, select + 1, target);
+       ioapic_write(ioapic[apic], select, flags | vector);
+       ioapic_write(ioapic[apic], select + 1, target);
 
        imen_unlock();
 
@@ -576,13 +576,13 @@ io_apic_setup_intpin(int apic, int pin)
        imen_lock();
 
        vector = IDT_OFFSET + irq;                      /* IDT vec */
-       target = ioapic_read(apic, select + 1) & IOART_HI_DEST_RESV;
+       target = ioapic_read(ioapic[apic], select + 1) & IOART_HI_DEST_RESV;
        /* Deliver all interrupts to CPU0 (BSP) */
        target |= (CPU_TO_ID(cpuid) << IOART_HI_DEST_SHIFT) &
                  IOART_HI_DEST_MASK;
-       flags |= ioapic_read(apic, select) & IOART_RESV;
-       ioapic_write(apic, select, flags | vector);
-       ioapic_write(apic, select + 1, target);
+       flags |= ioapic_read(ioapic[apic], select) & IOART_RESV;
+       ioapic_write(ioapic[apic], select, flags | vector);
+       ioapic_write(ioapic[apic], select + 1, target);
 
        imen_unlock();
 }
@@ -654,8 +654,8 @@ ext_int_setup(int apic, int intr)
        vector = IDT_OFFSET + intr;
        flags = DEFAULT_EXTINT_FLAGS;
 
-       ioapic_write(apic, select, flags | vector);
-       ioapic_write(apic, select + 1, target);
+       ioapic_write(ioapic[apic], select, flags | vector);
+       ioapic_write(ioapic[apic], select + 1, target);
 
        return 0;
 }
index ee42683..567df46 100644 (file)
@@ -689,7 +689,7 @@ if (apic_io_enable) {
 
        /* fill the LOGICAL io_apic_versions table */
        for (apic = 0; apic < mp_napics; ++apic) {
-               ux = ioapic_read(apic, IOAPIC_VER);
+               ux = ioapic_read(ioapic[apic], IOAPIC_VER);
                io_apic_versions[apic] = ux;
                io_apic_set_id(apic, IO_TO_ID(apic));
        }
@@ -1640,7 +1640,7 @@ int_entry(const struct INTENTRY *entry, int intr)
                /* This signal goes to all IO APICS.  Select an IO APIC
                   with sufficient number of interrupt pins */
                for (apic = 0; apic < mp_napics; apic++)
-                       if (((ioapic_read(apic, IOAPIC_VER) & 
+                       if (((ioapic_read(ioapic[apic], IOAPIC_VER) & 
                              IOART_VER_MAXREDIR) >> MAXREDIRSHIFT) >= 
                            entry->dst_apic_int)
                                break;
@@ -2042,7 +2042,7 @@ mptable_default(int type)
 #endif /* 0 */
 
        /* one and only IO APIC */
-       io_apic_id = (ioapic_read(0, IOAPIC_ID) & APIC_ID_MASK) >> 24;
+       io_apic_id = (ioapic_read(ioapic[0], IOAPIC_ID) & APIC_ID_MASK) >> 24;
 
        /*
         * sanity check, refer to MP spec section 3.6.6, last paragraph
index 4845b37..acf5ee7 100644 (file)
@@ -52,8 +52,8 @@ extern volatile u_int         checkstate_probed_cpus;
 extern void (*cpustop_restartfunc) (void);
 
 /* functions in apic_ipl.s */
-u_int  ioapic_read             (int, int);
-void   ioapic_write            (int, int, u_int);
+u_int  ioapic_read             (volatile void *, int);
+void   ioapic_write            (volatile void *, int, u_int);
 
 /* global data in mp_machdep.c */
 extern int                     mp_naps;
index 4987778..c115659 100644 (file)
@@ -638,13 +638,13 @@ ioapic_vectorctl(int op, int intr, int flags)
                        imen_lock();
 
                        select = int_to_apicintpin[intr].redirindex;
-                       value = ioapic_read(int_to_apicintpin[intr].ioapic,
+                       value = ioapic_read(int_to_apicintpin[intr].apic_address,
                                            select);
                        value |= IOART_INTMSET;
 
-                       ioapic_write(int_to_apicintpin[intr].ioapic,
+                       ioapic_write(int_to_apicintpin[intr].apic_address,
                                     select, (value & ~APIC_TRIGMOD_MASK));
-                       ioapic_write(int_to_apicintpin[intr].ioapic,
+                       ioapic_write(int_to_apicintpin[intr].apic_address,
                                     select, (value & ~IOART_INTVEC) | vector);
 
                        imen_unlock();
@@ -673,12 +673,12 @@ ioapic_vectorctl(int op, int intr, int flags)
                        imen_lock();
 
                        select = int_to_apicintpin[intr].redirindex;
-                       value = ioapic_read(int_to_apicintpin[intr].ioapic,
+                       value = ioapic_read(int_to_apicintpin[intr].apic_address,
                                            select);
 
-                       ioapic_write(int_to_apicintpin[intr].ioapic,
+                       ioapic_write(int_to_apicintpin[intr].apic_address,
                                     select, (value & ~APIC_TRIGMOD_MASK));
-                       ioapic_write(int_to_apicintpin[intr].ioapic,
+                       ioapic_write(int_to_apicintpin[intr].apic_address,
                                     select, (value & ~IOART_INTVEC) | vector);
 
                        imen_unlock();
index 6cf4a20..277917e 100644 (file)
@@ -114,24 +114,18 @@ ENTRY(IOAPIC_INTREN)
  */
 
 /*
- * u_int ioapic_read(int apic, int select);
+ * u_int ioapic_read(volatile void *ioapic, int select);
  */
 ENTRY(ioapic_read)
-       movl    %edi, %ecx              /* IOAPIC # */
-       movq    ioapic, %rax
-       movq    (%rax,%rcx,8), %rdx     /* IOAPIC base register address */
-       movl    %esi, (%rdx)            /* write the target register index */
-       movl    IOAPIC_WINDOW(%rdx), %eax /* read the IOAPIC register data */
+       movl    %esi, (%rdi)            /* write the target register index */
+       movl    IOAPIC_WINDOW(%rdi), %eax /* read the IOAPIC register data */
        ret                             /* %eax = register value */
 
 /*
- * void ioapic_write(int apic, int select, u_int value);
+ * void ioapic_write(volatile void *ioapic, int select, u_int value);
  */
 ENTRY(ioapic_write)
-       movl    %edi, %ecx              /* IOAPIC # */
-       movq    ioapic, %rax
-       movq    (%rax,%rcx,8), %r8      /* IOAPIC base register address */
-       movl    %esi, (%r8)             /* write the target register index */
-       movl    %edx, IOAPIC_WINDOW(%r8) /* write the IOAPIC register data */
+       movl    %esi, (%rdi)            /* write the target register index */
+       movl    %edx, IOAPIC_WINDOW(%rdi) /* write the IOAPIC register data */
        ret                             /* %eax = void */
 #endif
index 7af5e4e..f11fd1d 100644 (file)
@@ -500,15 +500,15 @@ io_apic_set_id(int apic, int id)
 {
        u_int32_t ux;
        
-       ux = ioapic_read(apic, IOAPIC_ID);      /* get current contents */
+       ux = ioapic_read(ioapic[apic], IOAPIC_ID);      /* get current contents */
        if (((ux & APIC_ID_MASK) >> 24) != id) {
                kprintf("Changing APIC ID for IO APIC #%d"
                       " from %d to %d on chip\n",
                       apic, ((ux & APIC_ID_MASK) >> 24), id);
                ux &= ~APIC_ID_MASK;    /* clear the ID field */
                ux |= (id << 24);
-               ioapic_write(apic, IOAPIC_ID, ux);      /* write new value */
-               ux = ioapic_read(apic, IOAPIC_ID);      /* re-read && test */
+               ioapic_write(ioapic[apic], IOAPIC_ID, ux);      /* write new value */
+               ux = ioapic_read(ioapic[apic], IOAPIC_ID);      /* re-read && test */
                if (((ux & APIC_ID_MASK) >> 24) != id)
                        panic("can't control IO APIC #%d ID, reg: 0x%08x",
                              apic, ux);
@@ -519,7 +519,7 @@ io_apic_set_id(int apic, int id)
 int
 io_apic_get_id(int apic)
 {
-  return (ioapic_read(apic, IOAPIC_ID) & APIC_ID_MASK) >> 24;
+  return (ioapic_read(ioapic[apic], IOAPIC_ID) & APIC_ID_MASK) >> 24;
 }
   
 
@@ -555,17 +555,17 @@ io_apic_setup_intpin(int apic, int pin)
         */
        imen_lock();
 
-       flags = ioapic_read(apic, select) & IOART_RESV;
+       flags = ioapic_read(ioapic[apic], select) & IOART_RESV;
        flags |= IOART_INTMSET | IOART_TRGREDG | IOART_INTAHI;
        flags |= IOART_DESTPHY | IOART_DELFIXED;
 
-       target = ioapic_read(apic, select + 1) & IOART_HI_DEST_RESV;
+       target = ioapic_read(ioapic[apic], select + 1) & IOART_HI_DEST_RESV;
        target |= 0;    /* fixed mode cpu mask of 0 - don't deliver anywhere */
 
        vector = 0;
 
-       ioapic_write(apic, select, flags | vector);
-       ioapic_write(apic, select + 1, target);
+       ioapic_write(ioapic[apic], select, flags | vector);
+       ioapic_write(ioapic[apic], select + 1, target);
 
        imen_unlock();
 
@@ -641,13 +641,13 @@ io_apic_setup_intpin(int apic, int pin)
        imen_lock();
 
        vector = IDT_OFFSET + irq;                      /* IDT vec */
-       target = ioapic_read(apic, select + 1) & IOART_HI_DEST_RESV;
+       target = ioapic_read(ioapic[apic], select + 1) & IOART_HI_DEST_RESV;
        /* Deliver all interrupts to CPU0 (BSP) */
        target |= (CPU_TO_ID(cpuid) << IOART_HI_DEST_SHIFT) &
                  IOART_HI_DEST_MASK;
-       flags |= ioapic_read(apic, select) & IOART_RESV;
-       ioapic_write(apic, select, flags | vector);
-       ioapic_write(apic, select + 1, target);
+       flags |= ioapic_read(ioapic[apic], select) & IOART_RESV;
+       ioapic_write(ioapic[apic], select, flags | vector);
+       ioapic_write(ioapic[apic], select + 1, target);
 
        imen_unlock();
 }
@@ -719,8 +719,8 @@ ext_int_setup(int apic, int intr)
        vector = IDT_OFFSET + intr;
        flags = DEFAULT_EXTINT_FLAGS;
 
-       ioapic_write(apic, select, flags | vector);
-       ioapic_write(apic, select + 1, target);
+       ioapic_write(ioapic[apic], select, flags | vector);
+       ioapic_write(ioapic[apic], select + 1, target);
 
        return 0;
 }
index 1558089..de432e7 100644 (file)
@@ -61,8 +61,8 @@ extern volatile u_int         checkstate_probed_cpus;
 extern void (*cpustop_restartfunc) (void);
 
 /* functions in apic_ipl.s */
-u_int  ioapic_read             (int, int);
-void   ioapic_write            (int, int, u_int);
+u_int  ioapic_read             (volatile void *, int);
+void   ioapic_write            (volatile void *, int, u_int);
 
 /* global data in mp_machdep.c */
 extern int                     apic_io_enable;
index 1fa861a..ff325f4 100644 (file)
@@ -710,7 +710,7 @@ if (apic_io_enable) {
 
        /* fill the LOGICAL io_apic_versions table */
        for (apic = 0; apic < mp_napics; ++apic) {
-               ux = ioapic_read(apic, IOAPIC_VER);
+               ux = ioapic_read(ioapic[apic], IOAPIC_VER);
                io_apic_versions[apic] = ux;
                io_apic_set_id(apic, IO_TO_ID(apic));
        }
@@ -1665,7 +1665,7 @@ int_entry(const struct INTENTRY *entry, int intr)
                /* This signal goes to all IO APICS.  Select an IO APIC
                   with sufficient number of interrupt pins */
                for (apic = 0; apic < mp_napics; apic++)
-                       if (((ioapic_read(apic, IOAPIC_VER) & 
+                       if (((ioapic_read(ioapic[apic], IOAPIC_VER) & 
                              IOART_VER_MAXREDIR) >> MAXREDIRSHIFT) >= 
                            entry->dst_apic_int)
                                break;
@@ -2067,7 +2067,7 @@ mptable_default(int type)
 #endif /* 0 */
 
        /* one and only IO APIC */
-       io_apic_id = (ioapic_read(0, IOAPIC_ID) & APIC_ID_MASK) >> 24;
+       io_apic_id = (ioapic_read(ioapic[0], IOAPIC_ID) & APIC_ID_MASK) >> 24;
 
        /*
         * sanity check, refer to MP spec section 3.6.6, last paragraph