octeon_mp.c revision 206829
12088Ssos/*- 25994Ssos * Copyright (c) 2004-2010 Juli Mallett <jmallett@FreeBSD.org> 32088Ssos * All rights reserved. 42088Ssos * 52088Ssos * Redistribution and use in source and binary forms, with or without 62088Ssos * modification, are permitted provided that the following conditions 72088Ssos * are met: 82088Ssos * 1. Redistributions of source code must retain the above copyright 95994Ssos * notice, this list of conditions and the following disclaimer. 105994Ssos * 2. Redistributions in binary form must reproduce the above copyright 112088Ssos * notice, this list of conditions and the following disclaimer in the 122088Ssos * documentation and/or other materials provided with the distribution. 132088Ssos * 142088Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1597748Sschweikh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 162088Ssos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 172088Ssos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 182088Ssos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 192088Ssos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 202088Ssos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 212088Ssos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 222088Ssos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 232088Ssos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 242088Ssos * SUCH DAMAGE. 252088Ssos * 262088Ssos * $FreeBSD: head/sys/mips/cavium/octeon_mp.c 206829 2010-04-19 06:01:58Z jmallett $ 272088Ssos */ 2850479Speter#include <sys/cdefs.h> 292088Ssos__FBSDID("$FreeBSD: head/sys/mips/cavium/octeon_mp.c 206829 2010-04-19 06:01:58Z jmallett $"); 302088Ssos 312088Ssos#include <sys/param.h> 322088Ssos#include <sys/conf.h> 332088Ssos#include <sys/kernel.h> 342088Ssos#include <sys/systm.h> 352088Ssos 362088Ssos#include <machine/hwfunc.h> 372088Ssos#include <machine/smp.h> 382088Ssos 392088Ssos#include <mips/cavium/octeon_pcmap_regs.h> 402088Ssos 412088Ssosunsigned octeon_ap_boot = ~0; 422088Ssos 432088Ssosvoid 442088Ssosplatform_ipi_send(int cpuid) 452088Ssos{ 462088Ssos oct_write64(OCTEON_CIU_MBOX_SETX(cpuid), 1); 472088Ssos mips_wbflush(); 482088Ssos} 492088Ssos 502088Ssosvoid 512088Ssosplatform_ipi_clear(void) 522088Ssos{ 535994Ssos uint64_t action; 5432316Syokota 5538053Syokota action = oct_read64(OCTEON_CIU_MBOX_CLRX(PCPU_GET(cpuid))); 5648105Syokota KASSERT(action == 1, ("unexpected IPIs: %#jx", (uintmax_t)action)); 5754380Syokota oct_write64(OCTEON_CIU_MBOX_CLRX(PCPU_GET(cpuid)), action); 5854380Syokota} 5954380Syokota 6054380Syokotaint 6154380Syokotaplatform_ipi_intrnum(void) 6254380Syokota{ 6354380Syokota return (1); 6465759Sdwmalone} 6565759Sdwmalone 6674118Sachevoid 672088Ssosplatform_init_ap(int cpuid) 682088Ssos{ 692088Ssos /* 702088Ssos * Set the exception base. 7177394Ssobomax */ 7299818Salfred mips_wr_ebase(0x80000000 | cpuid); 73 74 /* 75 * Set up interrupts, clear IPIs and unmask the IPI interrupt. 76 */ 77 octeon_ciu_reset(); 78 79 oct_write64(OCTEON_CIU_MBOX_CLRX(cpuid), 0xffffffff); 80 ciu_enable_interrupts(cpuid, CIU_INT_1, CIU_EN_0, OCTEON_CIU_ENABLE_MBOX_INTR, CIU_MIPS_IP3); 81 82 mips_wbflush(); 83} 84 85int 86platform_num_processors(void) 87{ 88 return (fls(octeon_core_mask)); 89} 90 91int 92platform_start_ap(int cpuid) 93{ 94 if (atomic_cmpset_32(&octeon_ap_boot, ~0, cpuid) == 0) 95 return (-1); 96 for (;;) { 97 DELAY(1000); 98 if (atomic_cmpset_32(&octeon_ap_boot, 0, ~0) != 0) 99 return (0); 100 printf("Waiting for cpu%d to start\n", cpuid); 101 } 102} 103