1a3bb9fccSApple OSS Distributions /*
2a3bb9fccSApple OSS Distributions * Copyright (c) 2014 Apple Inc. All rights reserved.
3a3bb9fccSApple OSS Distributions *
4a3bb9fccSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5a3bb9fccSApple OSS Distributions *
6a3bb9fccSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7a3bb9fccSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8a3bb9fccSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9a3bb9fccSApple OSS Distributions * compliance with the License. The rights granted to you under the License
10a3bb9fccSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11a3bb9fccSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12a3bb9fccSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13a3bb9fccSApple OSS Distributions * terms of an Apple operating system software license agreement.
14a3bb9fccSApple OSS Distributions *
15a3bb9fccSApple OSS Distributions * Please obtain a copy of the License at
16a3bb9fccSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17a3bb9fccSApple OSS Distributions *
18a3bb9fccSApple OSS Distributions * The Original Code and all software distributed under the License are
19a3bb9fccSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20a3bb9fccSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21a3bb9fccSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22a3bb9fccSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23a3bb9fccSApple OSS Distributions * Please see the License for the specific language governing rights and
24a3bb9fccSApple OSS Distributions * limitations under the License.
25a3bb9fccSApple OSS Distributions *
26a3bb9fccSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27a3bb9fccSApple OSS Distributions */
28a3bb9fccSApple OSS Distributions
29*bb611c8fSApple OSS Distributions #define IOKIT_ENABLE_SHARED_PTR
30*bb611c8fSApple OSS Distributions
31a3bb9fccSApple OSS Distributions #include <IOKit/IOInterruptAccountingPrivate.h>
32a3bb9fccSApple OSS Distributions #include <IOKit/IOKernelReporters.h>
33a3bb9fccSApple OSS Distributions
34a3bb9fccSApple OSS Distributions uint32_t gInterruptAccountingStatisticBitmask =
3576e12aa3SApple OSS Distributions #if !defined(__arm__)
36a3bb9fccSApple OSS Distributions /* Disable timestamps for older ARM platforms; they are expensive. */
37a3bb9fccSApple OSS Distributions IA_GET_ENABLE_BIT(kInterruptAccountingFirstLevelTimeIndex) |
38a3bb9fccSApple OSS Distributions IA_GET_ENABLE_BIT(kInterruptAccountingSecondLevelCPUTimeIndex) |
39a3bb9fccSApple OSS Distributions IA_GET_ENABLE_BIT(kInterruptAccountingSecondLevelSystemTimeIndex) |
4076e12aa3SApple OSS Distributions #endif
41a3bb9fccSApple OSS Distributions IA_GET_ENABLE_BIT(kInterruptAccountingFirstLevelCountIndex) |
42a3bb9fccSApple OSS Distributions IA_GET_ENABLE_BIT(kInterruptAccountingSecondLevelCountIndex);
43a3bb9fccSApple OSS Distributions
44a3bb9fccSApple OSS Distributions IOLock * gInterruptAccountingDataListLock = NULL;
45a3bb9fccSApple OSS Distributions queue_head_t gInterruptAccountingDataList;
46a3bb9fccSApple OSS Distributions
47a5e72196SApple OSS Distributions void
interruptAccountingInit(void)48a5e72196SApple OSS Distributions interruptAccountingInit(void)
49a3bb9fccSApple OSS Distributions {
50a3bb9fccSApple OSS Distributions int bootArgValue = 0;
51a3bb9fccSApple OSS Distributions
52a5e72196SApple OSS Distributions if (PE_parse_boot_argn("interrupt_accounting", &bootArgValue, sizeof(bootArgValue))) {
53a3bb9fccSApple OSS Distributions gInterruptAccountingStatisticBitmask = bootArgValue;
54a5e72196SApple OSS Distributions }
55a3bb9fccSApple OSS Distributions
56a3bb9fccSApple OSS Distributions gInterruptAccountingDataListLock = IOLockAlloc();
57a3bb9fccSApple OSS Distributions
58a3bb9fccSApple OSS Distributions assert(gInterruptAccountingDataListLock);
59a3bb9fccSApple OSS Distributions
60a3bb9fccSApple OSS Distributions queue_init(&gInterruptAccountingDataList);
61a3bb9fccSApple OSS Distributions }
62a3bb9fccSApple OSS Distributions
63a5e72196SApple OSS Distributions void
interruptAccountingDataAddToList(IOInterruptAccountingData * data)64a5e72196SApple OSS Distributions interruptAccountingDataAddToList(IOInterruptAccountingData * data)
65a3bb9fccSApple OSS Distributions {
66a3bb9fccSApple OSS Distributions IOLockLock(gInterruptAccountingDataListLock);
67a3bb9fccSApple OSS Distributions queue_enter(&gInterruptAccountingDataList, data, IOInterruptAccountingData *, chain);
68a3bb9fccSApple OSS Distributions IOLockUnlock(gInterruptAccountingDataListLock);
69a3bb9fccSApple OSS Distributions }
70a3bb9fccSApple OSS Distributions
71a5e72196SApple OSS Distributions void
interruptAccountingDataRemoveFromList(IOInterruptAccountingData * data)72a5e72196SApple OSS Distributions interruptAccountingDataRemoveFromList(IOInterruptAccountingData * data)
73a3bb9fccSApple OSS Distributions {
74a3bb9fccSApple OSS Distributions IOLockLock(gInterruptAccountingDataListLock);
75a3bb9fccSApple OSS Distributions queue_remove(&gInterruptAccountingDataList, data, IOInterruptAccountingData *, chain);
76a3bb9fccSApple OSS Distributions IOLockUnlock(gInterruptAccountingDataListLock);
77a3bb9fccSApple OSS Distributions }
78a3bb9fccSApple OSS Distributions
79a5e72196SApple OSS Distributions void
interruptAccountingDataUpdateChannels(IOInterruptAccountingData * data,IOSimpleReporter * reporter)80a5e72196SApple OSS Distributions interruptAccountingDataUpdateChannels(IOInterruptAccountingData * data, IOSimpleReporter * reporter)
81a3bb9fccSApple OSS Distributions {
82a3bb9fccSApple OSS Distributions uint64_t i = 0;
83a3bb9fccSApple OSS Distributions
84a3bb9fccSApple OSS Distributions for (i = 0; i < IA_NUM_INTERRUPT_ACCOUNTING_STATISTICS; i++) {
85a5e72196SApple OSS Distributions if (IA_GET_STATISTIC_ENABLED(i)) {
86a3bb9fccSApple OSS Distributions reporter->setValue(IA_GET_CHANNEL_ID(data->interruptIndex, i), data->interruptStatistics[i]);
87a3bb9fccSApple OSS Distributions }
88a3bb9fccSApple OSS Distributions }
89a5e72196SApple OSS Distributions }
90a3bb9fccSApple OSS Distributions
91a5e72196SApple OSS Distributions void
interruptAccountingDataInheritChannels(IOInterruptAccountingData * data,IOSimpleReporter * reporter)92a5e72196SApple OSS Distributions interruptAccountingDataInheritChannels(IOInterruptAccountingData * data, IOSimpleReporter * reporter)
93a3bb9fccSApple OSS Distributions {
94a3bb9fccSApple OSS Distributions uint64_t i = 0;
95a3bb9fccSApple OSS Distributions
96a3bb9fccSApple OSS Distributions for (i = 0; i < IA_NUM_INTERRUPT_ACCOUNTING_STATISTICS; i++) {
97a5e72196SApple OSS Distributions if (IA_GET_STATISTIC_ENABLED(i)) {
98a3bb9fccSApple OSS Distributions data->interruptStatistics[i] = reporter->getValue(IA_GET_CHANNEL_ID(data->interruptIndex, i));
99a3bb9fccSApple OSS Distributions }
100a3bb9fccSApple OSS Distributions }
101a5e72196SApple OSS Distributions }
102