xref: /freebsd/sys/compat/linuxkpi/common/src/linux_domain.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
1*ebe5cf35SHans Petter Selasky /*-
2*ebe5cf35SHans Petter Selasky  * Copyright (c) 2021 NVIDIA Networking
3*ebe5cf35SHans Petter Selasky  * All rights reserved.
4*ebe5cf35SHans Petter Selasky  *
5*ebe5cf35SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
6*ebe5cf35SHans Petter Selasky  * modification, are permitted provided that the following conditions
7*ebe5cf35SHans Petter Selasky  * are met:
8*ebe5cf35SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
9*ebe5cf35SHans Petter Selasky  *    notice unmodified, this list of conditions, and the following
10*ebe5cf35SHans Petter Selasky  *    disclaimer.
11*ebe5cf35SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
12*ebe5cf35SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
13*ebe5cf35SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
14*ebe5cf35SHans Petter Selasky  *
15*ebe5cf35SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*ebe5cf35SHans Petter Selasky  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*ebe5cf35SHans Petter Selasky  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*ebe5cf35SHans Petter Selasky  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*ebe5cf35SHans Petter Selasky  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*ebe5cf35SHans Petter Selasky  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*ebe5cf35SHans Petter Selasky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*ebe5cf35SHans Petter Selasky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*ebe5cf35SHans Petter Selasky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*ebe5cf35SHans Petter Selasky  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*ebe5cf35SHans Petter Selasky  */
26*ebe5cf35SHans Petter Selasky 
27*ebe5cf35SHans Petter Selasky #include <sys/param.h>
28*ebe5cf35SHans Petter Selasky #include <sys/systm.h>
29*ebe5cf35SHans Petter Selasky #include <sys/domainset.h>
30*ebe5cf35SHans Petter Selasky #include <sys/bus.h>
31*ebe5cf35SHans Petter Selasky 
32*ebe5cf35SHans Petter Selasky #include <linux/compat.h>
33*ebe5cf35SHans Petter Selasky #include <linux/device.h>
34*ebe5cf35SHans Petter Selasky 
35*ebe5cf35SHans Petter Selasky struct domainset *
linux_get_vm_domain_set(int node)36*ebe5cf35SHans Petter Selasky linux_get_vm_domain_set(int node)
37*ebe5cf35SHans Petter Selasky {
38*ebe5cf35SHans Petter Selasky 	KASSERT(node < MAXMEMDOM, ("Invalid VM domain %d", node));
39*ebe5cf35SHans Petter Selasky 
40*ebe5cf35SHans Petter Selasky 	if (node < 0)
41*ebe5cf35SHans Petter Selasky 		return (DOMAINSET_RR());
42*ebe5cf35SHans Petter Selasky 	else
43*ebe5cf35SHans Petter Selasky 		return (DOMAINSET_PREF(node));
44*ebe5cf35SHans Petter Selasky }
45*ebe5cf35SHans Petter Selasky 
46*ebe5cf35SHans Petter Selasky int
linux_dev_to_node(struct device * dev)47*ebe5cf35SHans Petter Selasky linux_dev_to_node(struct device *dev)
48*ebe5cf35SHans Petter Selasky {
49*ebe5cf35SHans Petter Selasky 	int numa_domain;
50*ebe5cf35SHans Petter Selasky 
51*ebe5cf35SHans Petter Selasky 	if (dev == NULL || dev->bsddev == NULL ||
52*ebe5cf35SHans Petter Selasky 	    bus_get_domain(dev->bsddev, &numa_domain) != 0)
53*ebe5cf35SHans Petter Selasky 		return (-1);
54*ebe5cf35SHans Petter Selasky 	else
55*ebe5cf35SHans Petter Selasky 		return (numa_domain);
56*ebe5cf35SHans Petter Selasky }
57