1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Inc. nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
43 * Provides APIs for applications to register for hotplug. It also provides
44 * APIs for requesting shutdown of a running target application.
46 * <hr>$Revision: $<hr>
49 #include "cvmx-app-hotplug.h"
50 #include "cvmx-spinlock.h"
51 #include "cvmx-debug.h"
55 static cvmx_app_hotplug_global_t *hotplug_global_ptr = 0;
57 #ifndef CVMX_BUILD_FOR_LINUX_USER
59 static CVMX_SHARED cvmx_spinlock_t cvmx_app_hotplug_sync_lock = { CVMX_SPINLOCK_UNLOCKED_VAL };
60 static CVMX_SHARED cvmx_spinlock_t cvmx_app_hotplug_lock = { CVMX_SPINLOCK_UNLOCKED_VAL };
61 static CVMX_SHARED cvmx_app_hotplug_info_t *cvmx_app_hotplug_info_ptr = NULL;
63 static void __cvmx_app_hotplug_shutdown(int irq_number, uint64_t registers[32], void *user_arg);
64 static void __cvmx_app_hotplug_sync(void);
65 static void __cvmx_app_hotplug_reset(void);
67 /* Declaring this array here is a compile time check to ensure that the
68 size of cvmx_app_hotplug_info_t is 1024. If the size is not 1024
69 the size of the array will be -1 and this results in a compilation
71 char __hotplug_info_check[(sizeof(cvmx_app_hotplug_info_t) == 1024) ? 1 : -1];
73 * This routine registers an application for hotplug. It installs a handler for
74 * any incoming shutdown request. It also registers a callback routine from the
75 * application. This callback is invoked when the application receives a
76 * shutdown notification.
78 * This routine only needs to be called once per application.
80 * @param fn Callback routine from the application.
81 * @param arg Argument to the application callback routine.
82 * @return Return 0 on success, -1 on failure
85 int cvmx_app_hotplug_register(void(*fn)(void*), void* arg)
87 /* Find the list of applications launched by bootoct utility. */
89 if (!(cvmx_app_hotplug_info_ptr = cvmx_app_hotplug_get_info(cvmx_sysinfo_get()->core_mask)))
91 /* Application not launched by bootoct? */
92 printf("ERROR: cmvx_app_hotplug_register() failed\n");
96 /* Register the callback */
97 cvmx_app_hotplug_info_ptr->data = CAST64(arg);
98 cvmx_app_hotplug_info_ptr->shutdown_callback = CAST64(fn);
101 printf("cvmx_app_hotplug_register(): coremask 0x%x valid %d\n",
102 cvmx_app_hotplug_info_ptr->coremask, cvmx_app_hotplug_info_ptr->valid);
105 cvmx_interrupt_register(CVMX_IRQ_MBOX0, __cvmx_app_hotplug_shutdown, NULL);
111 * This routine deprecates the the cvmx_app_hotplug_register method. This
112 * registers application for hotplug and the application will have CPU
113 * hotplug callbacks. Various callbacks are specified in cb.
114 * cvmx_app_hotplug_callbacks_t documents the callbacks
116 * This routine only needs to be called once per application.
118 * @param cb Callback routine from the application.
119 * @param arg Argument to the application callback routins
120 * @param app_shutdown When set to 1 the application will invoke core_shutdown
121 on each core. When set to 0 core shutdown will be
122 called invoked automatically after invoking the
123 application callback.
124 * @return Return index of app on success, -1 on failure
127 int cvmx_app_hotplug_register_cb(cvmx_app_hotplug_callbacks_t *cb, void* arg,
130 cvmx_app_hotplug_info_t *app_info;
132 /* Find the list of applications launched by bootoct utility. */
133 app_info = cvmx_app_hotplug_get_info(cvmx_sysinfo_get()->core_mask);
134 cvmx_app_hotplug_info_ptr = app_info;
137 /* Application not launched by bootoct? */
138 printf("ERROR: cmvx_app_hotplug_register() failed\n");
141 /* Register the callback */
142 app_info->data = CAST64(arg);
143 app_info->shutdown_callback = CAST64(cb->shutdown_callback);
144 app_info->cores_added_callback = CAST64(cb->cores_added_callback);
145 app_info->cores_removed_callback = CAST64(cb->cores_removed_callback);
146 app_info->unplug_callback = CAST64(cb->unplug_core_callback);
147 app_info->hotplug_start = CAST64(cb->hotplug_start);
148 app_info->app_shutdown = app_shutdown;
150 printf("cvmx_app_hotplug_register(): coremask 0x%x valid %d\n",
151 app_info->coremask, app_info->valid);
154 cvmx_interrupt_register(CVMX_IRQ_MBOX0, __cvmx_app_hotplug_shutdown, NULL);
159 void cvmx_app_hotplug_remove_self_from_core_mask(void)
161 int core = cvmx_get_core_num();
162 uint32_t core_mask = 1ull << core;
164 cvmx_spinlock_lock(&cvmx_app_hotplug_lock);
165 cvmx_app_hotplug_info_ptr->coremask = cvmx_app_hotplug_info_ptr->coremask & ~core_mask ;
166 cvmx_app_hotplug_info_ptr->hotplug_activated_coremask =
167 cvmx_app_hotplug_info_ptr->hotplug_activated_coremask & ~core_mask ;
168 cvmx_spinlock_unlock(&cvmx_app_hotplug_lock);
174 * Returns 1 if the running core is being unplugged, else it returns 0.
176 int is_core_being_unplugged(void)
178 if (cvmx_app_hotplug_info_ptr->unplug_cores &
179 (1ull << cvmx_get_core_num()))
186 * Activate the current application core for receiving hotplug shutdown requests.
188 * This routine makes sure that each core belonging to the application is enabled
189 * to receive the shutdown notification and also provides a barrier sync to make
190 * sure that all cores are ready.
192 int cvmx_app_hotplug_activate(void)
195 uint64_t cnt_interval = 10000000;
197 while (!cvmx_app_hotplug_info_ptr)
200 if ((cnt % cnt_interval) == 0)
201 printf("waiting for cnt=%lld\n", (unsigned long long)cnt);
204 if (cvmx_app_hotplug_info_ptr->hplugged_cores & (1ull << cvmx_get_core_num()))
207 printf("core=%d : is being hotplugged \n", cvmx_get_core_num());
209 cvmx_sysinfo_t *sys_info_ptr = cvmx_sysinfo_get();
210 sys_info_ptr->core_mask |= 1ull << cvmx_get_core_num();
214 __cvmx_app_hotplug_sync();
216 cvmx_spinlock_lock(&cvmx_app_hotplug_lock);
217 if (!cvmx_app_hotplug_info_ptr)
219 cvmx_spinlock_unlock(&cvmx_app_hotplug_lock);
220 printf("ERROR: This application is not registered for hotplug\n");
223 /* Enable the interrupt before we mark the core as activated */
224 cvmx_interrupt_unmask_irq(CVMX_IRQ_MBOX0);
225 cvmx_app_hotplug_info_ptr->hotplug_activated_coremask |= (1ull<<cvmx_get_core_num());
228 printf("cvmx_app_hotplug_activate(): coremask 0x%x valid %d sizeof %d\n",
229 cvmx_app_hotplug_info_ptr->coremask, cvmx_app_hotplug_info_ptr->valid,
230 sizeof(*cvmx_app_hotplug_info_ptr));
233 cvmx_spinlock_unlock(&cvmx_app_hotplug_lock);
239 * This routine is only required if cvmx_app_hotplug_shutdown_request() was called
240 * with wait=0. This routine waits for the application shutdown to complete.
242 * @param coremask Coremask the application is running on.
243 * @return 0 on success, -1 on error
246 int cvmx_app_hotplug_shutdown_complete(uint32_t coremask)
248 cvmx_app_hotplug_info_t *hotplug_info_ptr;
250 if (!(hotplug_info_ptr = cvmx_app_hotplug_get_info(coremask)))
252 printf("\nERROR: Failed to get hotplug info for coremask: 0x%x\n", (unsigned int)coremask);
256 while(!hotplug_info_ptr->shutdown_done);
258 /* Clean up the hotplug info region for this app */
259 bzero(hotplug_info_ptr, sizeof(*hotplug_info_ptr));
265 * Disable recognition of any incoming shutdown request.
268 void cvmx_app_hotplug_shutdown_disable(void)
270 cvmx_interrupt_mask_irq(CVMX_IRQ_MBOX0);
274 * Re-enable recognition of incoming shutdown requests.
277 void cvmx_app_hotplug_shutdown_enable(void)
279 cvmx_interrupt_unmask_irq(CVMX_IRQ_MBOX0);
283 * Request shutdown of the currently running core. Should be
284 * called by the application when it has been registered with
285 * app_shutdown option set to 1.
287 void cvmx_app_hotplug_core_shutdown(void)
290 if (cvmx_app_hotplug_info_ptr->shutdown_cores)
292 cvmx_sysinfo_t *sys_info_ptr = cvmx_sysinfo_get();
293 __cvmx_app_hotplug_sync();
294 if (cvmx_coremask_first_core(sys_info_ptr->core_mask))
296 bzero(cvmx_app_hotplug_info_ptr,
297 sizeof(*cvmx_app_hotplug_info_ptr));
299 printf("__cvmx_app_hotplug_shutdown(): setting shutdown done! \n");
301 cvmx_app_hotplug_info_ptr->shutdown_done = 1;
303 /* Tell the debugger that this application is finishing. */
304 cvmx_debug_finish ();
305 flags = cvmx_interrupt_disable_save();
306 __cvmx_app_hotplug_sync();
308 __cvmx_app_hotplug_reset();
312 cvmx_sysinfo_remove_self_from_core_mask();
313 cvmx_app_hotplug_remove_self_from_core_mask();
314 flags = cvmx_interrupt_disable_save();
315 __cvmx_app_hotplug_reset();
320 * ISR for the incoming shutdown request interrupt.
322 static void __cvmx_app_hotplug_shutdown(int irq_number, uint64_t registers[32],
325 cvmx_sysinfo_t *sys_info_ptr = cvmx_sysinfo_get();
327 cvmx_app_hotplug_info_t *ai = cvmx_app_hotplug_info_ptr;
333 cvmx_interrupt_mask_irq(CVMX_IRQ_MBOX0);
335 mbox = cvmx_read_csr(CVMX_CIU_MBOX_CLRX(cvmx_get_core_num()));
336 /* Clear the interrupt */
337 cvmx_write_csr(CVMX_CIU_MBOX_CLRX(cvmx_get_core_num()), mbox);
339 /* Make sure the write above completes */
340 cvmx_read_csr(CVMX_CIU_MBOX_CLRX(cvmx_get_core_num()));
343 if (!cvmx_app_hotplug_info_ptr)
345 printf("ERROR: Application is not registered for hotplug!\n");
349 if (ai->hotplug_activated_coremask != sys_info_ptr->core_mask)
351 printf("ERROR: Shutdown requested when not all app cores have "
352 "activated hotplug\n" "Application coremask: 0x%x Hotplug "
353 "coremask: 0x%x\n", (unsigned int)sys_info_ptr->core_mask,
354 (unsigned int)ai->hotplug_activated_coremask);
360 int core = cvmx_get_core_num();
362 printf("Shutting down application .\n");
363 /* Call the application's own callback function */
364 if (ai->shutdown_callback)
366 ((void(*)(void*))(long)ai->shutdown_callback)(CASTPTR(void *, ai->data));
370 printf("ERROR : Shutdown callback has not been registered\n");
372 if (!ai->app_shutdown)
375 printf("%s : core = %d Invoking app shutdown\n", __FUNCTION__, core);
376 cvmx_app_hotplug_core_shutdown();
379 else if (mbox & 2ull)
381 int core = cvmx_get_core_num();
382 int unplug = is_core_being_unplugged();
383 if (dbg) printf("%s : core=%d Unplug event \n", __FUNCTION__, core);
387 /* Call the application's own callback function */
388 if (ai->unplug_callback)
390 if (dbg) printf("%s : core=%d Calling unplug callback\n",
392 ((void(*)(void*))(long)ai->unplug_callback)(CASTPTR(void *,
395 if (!ai->app_shutdown)
397 if (dbg) printf("%s : core = %d Invoking app shutdown\n",
399 cvmx_app_hotplug_core_shutdown();
404 if (ai->cores_removed_callback)
406 if (dbg) printf("%s : core=%d Calling cores removed callback\n",
408 ((void(*)(uint32_t, void*))(long)ai->cores_removed_callback)
409 (ai->unplug_cores, CASTPTR(void *, ai->data));
411 cvmx_interrupt_unmask_irq(CVMX_IRQ_MBOX0);
414 else if (mbox & 4ull)
416 int core = cvmx_get_core_num();
417 if (dbg) printf("%s : core=%d Add cores event \n", __FUNCTION__, core);
419 if (ai->cores_added_callback)
421 if (dbg) printf("%s : core=%d Calling cores added callback\n",
423 ((void(*)(uint32_t, void*))(long)ai->cores_added_callback)
424 (ai->hplugged_cores, CASTPTR(void *, ai->data));
426 cvmx_interrupt_unmask_irq(CVMX_IRQ_MBOX0);
430 printf("ERROR: unexpected mbox=%llx\n", (unsigned long long)mbox);
435 void __cvmx_app_hotplug_reset(void)
437 #define IDLE_CORE_BLOCK_NAME "idle-core-loop"
438 #define HPLUG_MAKE_XKPHYS(x) ((1ULL << 63) | (x))
440 const cvmx_bootmem_named_block_desc_t *block_desc;
442 block_desc = cvmx_bootmem_find_named_block(IDLE_CORE_BLOCK_NAME);
444 cvmx_dprintf("Named block(%s) is not created\n", IDLE_CORE_BLOCK_NAME);
445 /* loop here, should not happen */
458 reset_addr = HPLUG_MAKE_XKPHYS(block_desc->base_addr);
459 asm volatile (" .set push \n"
462 " move $2, %[addr] \n"
466 :: [addr] "r"(reset_addr)
469 /*Should never reach here*/
475 * We need a separate sync operation from cvmx_coremask_barrier_sync() to
476 * avoid a deadlock on state.lock, since the application itself maybe doing a
477 * cvmx_coremask_barrier_sync().
479 static void __cvmx_app_hotplug_sync(void)
481 static CVMX_SHARED volatile uint32_t sync_coremask = 0;
482 cvmx_sysinfo_t *sys_info_ptr = cvmx_sysinfo_get();
484 cvmx_spinlock_lock(&cvmx_app_hotplug_sync_lock);
486 sync_coremask |= cvmx_coremask_core(cvmx_get_core_num());
488 cvmx_spinlock_unlock(&cvmx_app_hotplug_sync_lock);
490 while (sync_coremask != sys_info_ptr->core_mask);
492 cvmx_spinlock_lock(&cvmx_app_hotplug_sync_lock);
494 cvmx_spinlock_unlock(&cvmx_app_hotplug_sync_lock);
499 #endif /* CVMX_BUILD_FOR_LINUX_USER */
502 * Returns 1 if the running core is being hotplugged, else it returns 0.
504 int is_core_being_hot_plugged(void)
507 #ifndef CVMX_BUILD_FOR_LINUX_USER
508 if (!cvmx_app_hotplug_info_ptr) return 0;
509 if (cvmx_app_hotplug_info_ptr->hplugged_cores &
510 (1ull << cvmx_get_core_num()))
518 static cvmx_app_hotplug_global_t *cvmx_app_get_hotplug_global_ptr(void)
520 const struct cvmx_bootmem_named_block_desc *block_desc;
521 cvmx_app_hotplug_global_t *hgp;
523 if(hotplug_global_ptr != 0) return hotplug_global_ptr;
525 block_desc = cvmx_bootmem_find_named_block(CVMX_APP_HOTPLUG_INFO_REGION_NAME);
528 printf("ERROR: Hotplug info region is not setup\n");
532 #ifdef CVMX_BUILD_FOR_LINUX_USER
534 size_t pg_sz = sysconf(_SC_PAGESIZE), size;
539 if ((fd = open("/dev/mem", O_RDWR)) == -1) {
545 * We need to mmap() this memory, since this was allocated from the
546 * kernel bootup code and does not reside in the RESERVE32 region.
548 size = CVMX_APP_HOTPLUG_INFO_REGION_SIZE + pg_sz-1;
549 offset = block_desc->base_addr & ~(pg_sz-1);
550 if ((vaddr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, offset))
557 hgp = (cvmx_app_hotplug_global_t *)(vaddr + ( block_desc->base_addr & (pg_sz-1)));
560 hgp = CASTPTR(void, CVMX_ADD_SEG(CVMX_MIPS_SPACE_XKPHYS, block_desc->base_addr));
562 hotplug_global_ptr = hgp;
568 * Return the hotplug info structure (cvmx_app_hotplug_info_t) pointer for the
569 * application running on the given coremask.
571 * @param coremask Coremask of application.
572 * @return Returns hotplug info struct on success, NULL on failure
575 cvmx_app_hotplug_info_t* cvmx_app_hotplug_get_info(uint32_t coremask)
577 cvmx_app_hotplug_info_t *hip;
578 cvmx_app_hotplug_global_t *hgp;
585 hgp = cvmx_app_get_hotplug_global_ptr();
586 if (!hgp) return NULL;
587 hip = hgp->hotplug_info_array;
589 /* Look for the current app's info */
590 for (i=0; i<CVMX_APP_HOTPLUG_MAX_APPS; i++)
592 if (hip[i].coremask == coremask)
595 printf("cvmx_app_hotplug_get_info(): coremask match %d -- coremask 0x%x, valid %d\n", i, (unsigned int)hip[i].coremask, (unsigned int)hip[i].valid);
603 * Return the hotplug application index structure for the application running on the
606 * @param coremask Coremask of application.
607 * @return Returns hotplug application index on success. -1 on failure
610 int cvmx_app_hotplug_get_index(uint32_t coremask)
612 cvmx_app_hotplug_info_t *hip;
613 cvmx_app_hotplug_global_t *hgp;
620 hgp = cvmx_app_get_hotplug_global_ptr();
622 hip = hgp->hotplug_info_array;
624 /* Look for the current app's info */
625 for (i=0; i<CVMX_APP_HOTPLUG_MAX_APPS; i++)
627 if (hip[i].coremask == coremask)
630 printf("cvmx_app_hotplug_get_info(): coremask match %d -- coremask 0x%x valid %d\n", i, (unsigned int)hip[i].coremask, (unsigned int)hip[i].valid);
637 void print_hot_plug_info(cvmx_app_hotplug_info_t* hpinfo)
639 printf("name=%s coremask=%08x hotplugged coremask=%08x valid=%d\n", hpinfo->app_name,
640 (unsigned int)hpinfo->coremask, (unsigned int)hpinfo->hotplug_activated_coremask, (unsigned int)hpinfo->valid);
644 * Return the hotplug info structure (cvmx_app_hotplug_info_t) pointer for the
645 * application with the specified index.
647 * @param index index of application.
648 * @return Returns hotplug info struct on success, NULL on failure
651 cvmx_app_hotplug_info_t* cvmx_app_hotplug_get_info_at_index(int index)
653 cvmx_app_hotplug_info_t *hip;
654 cvmx_app_hotplug_global_t *hgp;
656 hgp = cvmx_app_get_hotplug_global_ptr();
657 if (!hgp) return NULL;
658 hip = hgp->hotplug_info_array;
661 printf("cvmx_app_hotplug_get_info(): hotplug_info phy addr 0x%llx ptr %p\n",
662 block_desc->base_addr, hgp);
664 if (index < CVMX_APP_HOTPLUG_MAX_APPS)
666 if (hip[index].valid)
668 //print_hot_plug_info( &hip[index] );
676 * Determines if SE application at the index specified is hotpluggable.
678 * @param index index of application.
679 * @return Returns -1 on error.
680 * 0 -> The application is not hotpluggable
681 * 1 -> The application is hotpluggable
683 int is_app_hotpluggable(int index)
685 cvmx_app_hotplug_info_t *ai;
687 if (!(ai = cvmx_app_hotplug_get_info_at_index(index)))
689 printf("\nERROR: Failed to get hotplug info for app at index=%d\n", index);
692 if (ai->hotplug_activated_coremask) return 1;
697 * This routine sends a shutdown request to a running target application.
699 * @param coremask Coremask the application is running on.
700 * @param wait 1 - Wait for shutdown completion
702 * @return 0 on success, -1 on error
706 int cvmx_app_hotplug_shutdown_request(uint32_t coremask, int wait)
709 cvmx_app_hotplug_info_t *hotplug_info_ptr;
711 if (!(hotplug_info_ptr = cvmx_app_hotplug_get_info(coremask)))
713 printf("\nERROR: Failed to get hotplug info for coremask: 0x%x\n", (unsigned int)coremask);
716 hotplug_info_ptr->shutdown_cores = coremask;
717 if (!hotplug_info_ptr->shutdown_callback)
719 printf("\nERROR: Target application has not registered for hotplug!\n");
723 if (hotplug_info_ptr->hotplug_activated_coremask != coremask)
725 printf("\nERROR: Not all application cores have activated hotplug\n");
729 /* Send IPIs to all application cores to request shutdown */
730 for (i=0; i<CVMX_MAX_CORES; i++) {
731 if (coremask & (1ull<<i))
732 cvmx_write_csr(CVMX_CIU_MBOX_SETX(i), 1);
737 while (!hotplug_info_ptr->shutdown_done);
739 /* Clean up the hotplug info region for this application */
740 bzero(hotplug_info_ptr, sizeof(*hotplug_info_ptr));
749 * This routine invokes the invoked the cores_added callbacks.
751 int cvmx_app_hotplug_call_add_cores_callback(int index)
753 cvmx_app_hotplug_info_t *ai;
755 if (!(ai = cvmx_app_hotplug_get_info_at_index(index)))
757 printf("\nERROR: Failed to get hotplug info for app at index=%d\n", index);
760 /* Send IPIs to all application cores to request add_cores callback*/
761 for (i=0; i<CVMX_MAX_CORES; i++) {
762 if (ai->coremask & (1ull<<i))
763 cvmx_write_csr(CVMX_CIU_MBOX_SETX(i), 4);
769 * This routine sends a request to a running target application
770 * to unplug a specified set cores
771 * @param index is the index of the target application
772 * @param coremask Coremask of the cores to be unplugged from the app.
773 * @param wait 1 - Wait for shutdown completion
775 * @return 0 on success, -1 on error
778 int cvmx_app_hotplug_unplug_cores(int index, uint32_t coremask, int wait)
780 cvmx_app_hotplug_info_t *ai;
783 if (!(ai = cvmx_app_hotplug_get_info_at_index(index)))
785 printf("\nERROR: Failed to get hotplug info for app at index=%d\n", index);
788 ai->unplug_cores = coremask;
790 if (!ai->shutdown_callback)
792 printf("\nERROR: Target application has not registered for hotplug!\n");
796 if ( (ai->coremask | coremask ) != ai->coremask)
798 printf("\nERROR: Not all cores requested are a part of the app "
799 "r=%08x:%08x\n", (unsigned int)coremask, (unsigned int)ai->coremask);
802 if (ai->coremask == coremask)
804 printf("\nERROR: Trying to remove all cores in app. "
805 "r=%08x:%08x\n", (unsigned int)coremask, (unsigned int)ai->coremask);
808 /* Send IPIs to all application cores to request unplug/remove_cores
810 for (i=0; i<CVMX_MAX_CORES; i++) {
811 if (ai->coremask & (1ull<<i))
812 cvmx_write_csr(CVMX_CIU_MBOX_SETX(i), 2);
818 while (!ai->shutdown_done);
820 /* Clean up the hotplug info region for this application */
821 bzero(ai, sizeof(*ai));
828 * Returns 1 if any app is currently being currently booted , hotplugged or
829 * shutdown. Only one app can be under a boot, hotplug or shutdown condition.
830 * Before booting an app this methods should be used to check whether boot or
831 * shutdown activity is in progress and proceed with the boot or shutdown only
832 * when there is no other activity.
835 int is_app_under_boot_or_shutdown(void)
838 cvmx_app_hotplug_global_t *hgp;
840 hgp = cvmx_app_get_hotplug_global_ptr();
841 cvmx_spinlock_lock(&hgp->hotplug_global_lock);
842 if (hgp->app_under_boot || hgp->app_under_shutdown) ret=1;
843 cvmx_spinlock_unlock(&hgp->hotplug_global_lock);
849 * Sets or clear the app_under_boot value. This when set signifies that an app
850 * is being currently booted or hotplugged with a new core.
853 * @param val sets the app_under_boot to the specified value. This should be
854 * set to 1 while app any is being booted and cleared after the
855 * application has booted up.
858 void set_app_unber_boot(int val)
860 cvmx_app_hotplug_global_t *hgp;
862 hgp = cvmx_app_get_hotplug_global_ptr();
863 cvmx_spinlock_lock(&hgp->hotplug_global_lock);
864 hgp->app_under_boot = val;
865 cvmx_spinlock_unlock(&hgp->hotplug_global_lock);
869 * Sets or clear the app_under_shutdown value. This when set signifies that an
870 * app is being currently shutdown or some cores of an app are being shutdown.
872 * @param val sets the app_under_shutdown to the specified value. This
873 * should be set to 1 while any app is being shutdown and cleared
874 * after the shutdown of the app is complete.
877 void set_app_under_shutdown(int val)
879 cvmx_app_hotplug_global_t *hgp;
881 hgp = cvmx_app_get_hotplug_global_ptr();
882 cvmx_spinlock_lock(&hgp->hotplug_global_lock);
883 hgp->app_under_shutdown = val;
884 cvmx_spinlock_unlock(&hgp->hotplug_global_lock);