15fce8027SBjoern A. Zeeb /*- 25fce8027SBjoern A. Zeeb * SPDX-License-Identifier: BSD-2-Clause 35fce8027SBjoern A. Zeeb * 45fce8027SBjoern A. Zeeb * Copyright (c) 2020-2021 The FreeBSD Foundation 55fce8027SBjoern A. Zeeb * 65fce8027SBjoern A. Zeeb * This software was developed by Björn Zeeb under sponsorship from 75fce8027SBjoern A. Zeeb * the FreeBSD Foundation. 85fce8027SBjoern A. Zeeb * 95fce8027SBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without 105fce8027SBjoern A. Zeeb * modification, are permitted provided that the following conditions 115fce8027SBjoern A. Zeeb * are met: 125fce8027SBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright 135fce8027SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer. 145fce8027SBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright 155fce8027SBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the 165fce8027SBjoern A. Zeeb * documentation and/or other materials provided with the distribution. 175fce8027SBjoern A. Zeeb * 185fce8027SBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 195fce8027SBjoern A. Zeeb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 205fce8027SBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 215fce8027SBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 225fce8027SBjoern A. Zeeb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 235fce8027SBjoern A. Zeeb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 245fce8027SBjoern A. Zeeb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 255fce8027SBjoern A. Zeeb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 265fce8027SBjoern A. Zeeb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 275fce8027SBjoern A. Zeeb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 285fce8027SBjoern A. Zeeb * SUCH DAMAGE. 295fce8027SBjoern A. Zeeb * 305fce8027SBjoern A. Zeeb * $FreeBSD$ 315fce8027SBjoern A. Zeeb */ 325fce8027SBjoern A. Zeeb 33*307f78f3SVladimir Kondratyev #ifndef _LINUXKPI_LINUX_CPU_H 34*307f78f3SVladimir Kondratyev #define _LINUXKPI_LINUX_CPU_H 355fce8027SBjoern A. Zeeb 365fce8027SBjoern A. Zeeb #include <sys/types.h> 375fce8027SBjoern A. Zeeb #include <sys/systm.h> 385fce8027SBjoern A. Zeeb #include <sys/cpuset.h> 395fce8027SBjoern A. Zeeb #include <sys/smp.h> 405fce8027SBjoern A. Zeeb #include <linux/compiler.h> 415fce8027SBjoern A. Zeeb #include <linux/slab.h> 425fce8027SBjoern A. Zeeb 435fce8027SBjoern A. Zeeb typedef cpuset_t cpumask_t; 445fce8027SBjoern A. Zeeb 455fce8027SBjoern A. Zeeb extern cpumask_t cpu_online_mask; 465fce8027SBjoern A. Zeeb 475fce8027SBjoern A. Zeeb static __inline int 485fce8027SBjoern A. Zeeb cpumask_next(int cpuid, cpumask_t mask) 495fce8027SBjoern A. Zeeb { 505fce8027SBjoern A. Zeeb 515fce8027SBjoern A. Zeeb /* 525fce8027SBjoern A. Zeeb * -1 can be an input to cpuid according to logic in drivers 535fce8027SBjoern A. Zeeb * but is never a valid cpuid in a set! 545fce8027SBjoern A. Zeeb */ 555fce8027SBjoern A. Zeeb KASSERT((cpuid >= -1 && cpuid <= MAXCPU), ("%s: invalid cpuid %d\n", 565fce8027SBjoern A. Zeeb __func__, cpuid)); 575fce8027SBjoern A. Zeeb KASSERT(!CPU_EMPTY(&mask), ("%s: empty CPU mask", __func__)); 585fce8027SBjoern A. Zeeb 595fce8027SBjoern A. Zeeb do { 605fce8027SBjoern A. Zeeb cpuid++; 615fce8027SBjoern A. Zeeb #ifdef SMP 625fce8027SBjoern A. Zeeb if (cpuid > mp_maxid) 635fce8027SBjoern A. Zeeb #endif 645fce8027SBjoern A. Zeeb cpuid = 0; 655fce8027SBjoern A. Zeeb } while (!CPU_ISSET(cpuid, &mask)); 665fce8027SBjoern A. Zeeb return (cpuid); 675fce8027SBjoern A. Zeeb } 685fce8027SBjoern A. Zeeb 695fce8027SBjoern A. Zeeb static __inline void 705fce8027SBjoern A. Zeeb cpumask_set_cpu(int cpu, cpumask_t *mask) 715fce8027SBjoern A. Zeeb { 725fce8027SBjoern A. Zeeb 735fce8027SBjoern A. Zeeb CPU_SET(cpu, mask); 745fce8027SBjoern A. Zeeb } 755fce8027SBjoern A. Zeeb 76*307f78f3SVladimir Kondratyev #endif /* _LINUXKPI_LINUX_CPU_H */ 77