xref: /netbsd-src/lib/libc/arch/powerpc/misc/powerpc_initfini.c (revision bff961dda2d0777bdbccab27297654ff0e6e9d37)
1*bff961ddSmatt /*-
2*bff961ddSmatt  * Copyright (c) 2013 The NetBSD Foundation, Inc.
3*bff961ddSmatt  * All rights reserved.
4*bff961ddSmatt  *
5*bff961ddSmatt  * This code is derived from software contributed to The NetBSD Foundation
6*bff961ddSmatt  * by Matt Thomas of 3am Software Foundry.
7*bff961ddSmatt  *
8*bff961ddSmatt  * Redistribution and use in source and binary forms, with or without
9*bff961ddSmatt  * modification, are permitted provided that the following conditions
10*bff961ddSmatt  * are met:
11*bff961ddSmatt  * 1. Redistributions of source code must retain the above copyright
12*bff961ddSmatt  *    notice, this list of conditions and the following disclaimer.
13*bff961ddSmatt  * 2. Redistributions in binary form must reproduce the above copyright
14*bff961ddSmatt  *    notice, this list of conditions and the following disclaimer in the
15*bff961ddSmatt  *    documentation and/or other materials provided with the distribution.
16*bff961ddSmatt  *
17*bff961ddSmatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18*bff961ddSmatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19*bff961ddSmatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20*bff961ddSmatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21*bff961ddSmatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*bff961ddSmatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*bff961ddSmatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*bff961ddSmatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*bff961ddSmatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*bff961ddSmatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*bff961ddSmatt  * POSSIBILITY OF SUCH DAMAGE.
28*bff961ddSmatt  */
29*bff961ddSmatt 
30*bff961ddSmatt #include <sys/cdefs.h>
31*bff961ddSmatt 
32*bff961ddSmatt __RCSID("$NetBSD: powerpc_initfini.c,v 1.1 2013/08/30 21:28:59 matt Exp $");
33*bff961ddSmatt 
34*bff961ddSmatt #include "namespace.h"
35*bff961ddSmatt 
36*bff961ddSmatt /*
37*bff961ddSmatt  * Grab the cache_info at load time.
38*bff961ddSmatt  */
39*bff961ddSmatt 
40*bff961ddSmatt #include <sys/param.h>
41*bff961ddSmatt #include <sys/sysctl.h>
42*bff961ddSmatt #include <sys/queue.h>
43*bff961ddSmatt #include <sys/cpu.h>
44*bff961ddSmatt 
45*bff961ddSmatt #include <stdbool.h>
46*bff961ddSmatt #include <stddef.h>
47*bff961ddSmatt 
48*bff961ddSmatt __dso_hidden struct cache_info _libc_powerpc_cache_info;
49*bff961ddSmatt 
50*bff961ddSmatt static void _libc_cache_info_init(void)
51*bff961ddSmatt     __attribute__((__constructor__, __used__));
52*bff961ddSmatt 
53*bff961ddSmatt void __section(".text.startup")
_libc_cache_info_init(void)54*bff961ddSmatt _libc_cache_info_init(void)
55*bff961ddSmatt {
56*bff961ddSmatt 	static bool initialized;
57*bff961ddSmatt 	if (!initialized) {
58*bff961ddSmatt 		const int name[2] = { CTL_MACHDEP, CPU_CACHEINFO };
59*bff961ddSmatt 		size_t len = sizeof(_libc_powerpc_cache_info);
60*bff961ddSmatt 		(void)sysctl(name, __arraycount(name),
61*bff961ddSmatt 		    &_libc_powerpc_cache_info, &len, NULL, 0);
62*bff961ddSmatt 		initialized = 1;
63*bff961ddSmatt 	}
64*bff961ddSmatt }
65