1dc90e12Robert Mustacchi/*
2dc90e12Robert Mustacchi * This file and its contents are supplied under the terms of the
3dc90e12Robert Mustacchi * Common Development and Distribution License ("CDDL"), version 1.0.
4dc90e12Robert Mustacchi * You may only use this file in accordance with the terms of version
5dc90e12Robert Mustacchi * 1.0 of the CDDL.
6dc90e12Robert Mustacchi *
7dc90e12Robert Mustacchi * A full copy of the text of the CDDL should have accompanied this
8dc90e12Robert Mustacchi * source.  A copy of the CDDL is also available via the Internet at
9dc90e12Robert Mustacchi * http://www.illumos.org/license/CDDL.
10dc90e12Robert Mustacchi */
11dc90e12Robert Mustacchi
12dc90e12Robert Mustacchi/*
13dc90e12Robert Mustacchi * Copyright 2019 Joyent, Inc.
140267428Robert Mustacchi * Copyright 2020 Oxide Computer Company
15dc90e12Robert Mustacchi */
16dc90e12Robert Mustacchi
17dc90e12Robert Mustacchi/*
18dc90e12Robert Mustacchi * Intel Platform Controller Hub (PCH) Thermal Sensor Driver
19dc90e12Robert Mustacchi *
20dc90e12Robert Mustacchi * The Intel PCH is a chip that was introduced around the Nehalem generation
21dc90e12Robert Mustacchi * that provides many services for the broader system on a discrete chip from
22dc90e12Robert Mustacchi * the CPU. While it existed prior to the Nehalem generation, it was previously
23dc90e12Robert Mustacchi * two discrete chips called the Northbridge and Southbridge. Sometimes this
24dc90e12Robert Mustacchi * device is also called a 'chipset'.
25dc90e12Robert Mustacchi *
26dc90e12Robert Mustacchi * The PCH contains everything from a USB controller, to an AHCI controller, to
27dc90e12Robert Mustacchi * clocks, the Intel Management Engine, and more. Relevant to this driver is its
28dc90e12Robert Mustacchi * thermal sensor which gives us the ability to read the temperature sensor that
29dc90e12Robert Mustacchi * is embedded in the PCH.
30dc90e12Robert Mustacchi *
31dc90e12Robert Mustacchi * The format of this sensor varies based on the generation of the chipset. The
32dc90e12Robert Mustacchi * current driver supports the following chipsets organized by datasheet, which
33dc90e12Robert Mustacchi * corresponds with a change in format that was introduced in the Haswell
34dc90e12Robert Mustacchi * generation:
35dc90e12Robert Mustacchi *
36dc90e12Robert Mustacchi *  - Intel 8 Series PCH
37dc90e12Robert Mustacchi *  - Intel 9 Series PCH
38dc90e12Robert Mustacchi *  - Intel C610 Series and X99 PCH
39dc90e12Robert Mustacchi *  - Intel C620 Series PCH
40dc90e12Robert Mustacchi *  - Intel 100 Series PCH
41dc90e12Robert Mustacchi *  - Intel 200 Series and Z730 PCH
42dc90e12Robert Mustacchi *  - Intel Sunrise Point-LP (Kaby Lake-U) PCH
432c4824dRobert Mustacchi *  - Intel Cannon Lake (Whiskey Lake-U) PCH
44dc90e12Robert Mustacchi *  - Intel 300 Series and C240 Chipset
45dc90e12Robert Mustacchi *
46dc90e12Robert Mustacchi * The following chipsets use a different format and are not currently
47dc90e12Robert Mustacchi * supported:
48dc90e12Robert Mustacchi *
49dc90e12Robert Mustacchi *  - Intel 5 Series and Xeon 3400 PCH
50dc90e12Robert Mustacchi *  - Intel 6 Series PCH
51dc90e12Robert Mustacchi *  - Intel 7 Series PCH
52dc90e12Robert Mustacchi *  - Intel C600 Series and X79 PCH
53dc90e12Robert Mustacchi */
54dc90e12Robert Mustacchi
55dc90e12Robert Mustacchi#include <sys/modctl.h>
56dc90e12Robert Mustacchi#include <sys/conf.h>
57dc90e12Robert Mustacchi#include <sys/devops.h>
58dc90e12Robert Mustacchi#include <sys/types.h>
59dc90e12Robert Mustacchi#include <sys/file.h>
60dc90e12Robert Mustacchi#include <sys/open.h>
61dc90e12Robert Mustacchi#include <sys/cred.h>
62dc90e12Robert Mustacchi#include <sys/ddi.h>
63dc90e12Robert Mustacchi#include <sys/sunddi.h>
64dc90e12Robert Mustacchi#include <sys/cmn_err.h>
65dc90e12Robert Mustacchi#include <sys/stat.h>
66dc90e12Robert Mustacchi#include <sys/sensors.h>
67dc90e12Robert Mustacchi
68dc90e12Robert Mustacchi/*
69dc90e12Robert Mustacchi * In all cases the data we care about is in the first PCI bar, bar 0. Per
70dc90e12Robert Mustacchi * pci(4)/pcie(4), this is always going to be register number 1.
71dc90e12Robert Mustacchi */
72dc90e12Robert Mustacchi#define	PCHTEMP_RNUMBER	1
73dc90e12Robert Mustacchi
74dc90e12Robert Mustacchi/*
75dc90e12Robert Mustacchi * The PCH Temperature Sensor has a resolution of 1/2 a degree. This is a
76dc90e12Robert Mustacchi * resolution of 2 in our parlance. The register reads 50 C higher than it is.
77dc90e12Robert Mustacchi * Therefore our offset is 50 shifted over by one.
78dc90e12Robert Mustacchi */
79dc90e12Robert Mustacchi#define	PCHTEMP_TEMP_RESOLUTION	2
80dc90e12Robert Mustacchi#define	PCHTEMP_TEMP_OFFSET	(50 << 1)
81dc90e12Robert Mustacchi
82dc90e12Robert Mustacchi/*
83dc90e12Robert Mustacchi * This register offset has the temperature that we want to read in the lower
84dc90e12Robert Mustacchi * 8-bits. The resolution and offset are described above.
85dc90e12Robert Mustacchi */
86dc90e12Robert Mustacchi#define	PCHTEMP_REG_TEMP	0x00
87dc90e12Robert Mustacchi#define	PCHTEMP_REG_TEMP_TSR	0x00ff
88dc90e12Robert Mustacchi
89dc90e12Robert Mustacchi/*
90dc90e12Robert Mustacchi * Thermal Sensor Enable and Lock (TSEL) register. This register is a byte wide
91dc90e12Robert Mustacchi * and has two bits that we care about. The ETS bit, enable thermal sensor,
92dc90e12Robert Mustacchi * indicates whether or not the sensor is enabled. The control for this can be
93dc90e12Robert Mustacchi * locked which is the PLDB, Policy Lock-Down Bit, bit. Which restricts
94dc90e12Robert Mustacchi * additional control of this register.
95dc90e12Robert Mustacchi */
96dc90e12Robert Mustacchi#define	PCHTEMP_REG_TSEL	0x08
97dc90e12Robert Mustacchi#define	PCHTEMP_REG_TSEL_ETS	0x01
98dc90e12Robert Mustacchi#define	PCHTEMP_REG_TSEL_PLDB	0x80
99dc90e12Robert Mustacchi
100dc90e12Robert Mustacchi/*
101dc90e12Robert Mustacchi * Threshold registers for the thermal sensors. These indicate the catastrophic,
102dc90e12Robert Mustacchi * the high alert threshold, and the low alert threshold respectively.
103dc90e12Robert Mustacchi */
104dc90e12Robert Mustacchi#define	PCHTEMP_REG_CTT		0x10
105dc90e12Robert Mustacchi#define	PCHTEMP_REG_TAHV	0x14
106dc90e12Robert Mustacchi#define	PCHTEMP_REG_TALV	0x18
107dc90e12Robert Mustacchi
108dc90e12Robert Mustacchitypedef struct pchtemp {
109dc90e12Robert Mustacchi	dev_info_t		*pcht_dip;
110dc90e12Robert Mustacchi	int			pcht_fm_caps;
111dc90e12Robert Mustacchi	caddr_t			pcht_base;
112dc90e12Robert Mustacchi	ddi_acc_handle_t	pcht_handle;
1130267428Robert Mustacchi	id_t			pcht_ksensor;
114dc90e12Robert Mustacchi	kmutex_t		pcht_mutex;	/* Protects members below */
115dc90e12Robert Mustacchi	uint16_t		pcht_temp_raw;
116dc90e12Robert Mustacchi	uint8_t			pcht_tsel_raw;
117dc90e12Robert Mustacchi	uint16_t		pcht_ctt_raw;
118dc90e12Robert Mustacchi	uint16_t		pcht_tahv_raw;
119dc90e12Robert Mustacchi	uint16_t		pcht_talv_raw;
120dc90e12Robert Mustacchi	int64_t			pcht_temp;
121dc90e12Robert Mustacchi} pchtemp_t;
122dc90e12Robert Mustacchi
123dc90e12Robert Mustacchivoid *pchtemp_state;
124dc90e12Robert Mustacchi
125dc90e12Robert Mustacchistatic int
126dc90e12Robert Mustacchipchtemp_read_check(pchtemp_t *pch)
127dc90e12Robert Mustacchi{
128dc90e12Robert Mustacchi	ddi_fm_error_t de;
129dc90e12Robert Mustacchi
130dc90e12Robert Mustacchi	if (!DDI_FM_ACC_ERR_CAP(pch->pcht_fm_caps)) {
131dc90e12Robert Mustacchi		return (DDI_FM_OK);
132dc90e12Robert Mustacchi	}
133dc90e12Robert Mustacchi
134dc90e12Robert Mustacchi	ddi_fm_acc_err_get(pch->pcht_handle, &de, DDI_FME_VERSION);
135dc90e12Robert Mustacchi	ddi_fm_acc_err_clear(pch->pcht_handle, DDI_FME_VERSION);
136dc90e12Robert Mustacchi	return (de.fme_status);
137dc90e12Robert Mustacchi}
138dc90e12Robert Mustacchi
139dc90e12Robert Mustacchistatic int
1400267428Robert Mustacchipchtemp_read(void *arg, sensor_ioctl_temperature_t *sit)
141dc90e12Robert Mustacchi{
142dc90e12Robert Mustacchi	uint16_t temp, ctt, tahv, talv;
143dc90e12Robert Mustacchi	uint8_t tsel;
1440267428Robert Mustacchi	pchtemp_t *pch = arg;
145dc90e12Robert Mustacchi
1460267428Robert Mustacchi	mutex_enter(&pch->pcht_mutex);
147dc90e12Robert Mustacchi
148dc90e12Robert Mustacchi	temp = ddi_get16(pch->pcht_handle,
149dc90e12Robert Mustacchi	    (uint16_t *)((uintptr_t)pch->pcht_base + PCHTEMP_REG_TEMP));
150dc90e12Robert Mustacchi	tsel = ddi_get8(pch->pcht_handle,
151dc90e12Robert Mustacchi	    (uint8_t *)((uintptr_t)pch->pcht_base + PCHTEMP_REG_TSEL));
152dc90e12Robert Mustacchi	ctt = ddi_get16(pch->pcht_handle,
153dc90e12Robert Mustacchi	    (uint16_t *)((uintptr_t)pch->pcht_base + PCHTEMP_REG_CTT));
154dc90e12Robert Mustacchi	tahv = ddi_get16(pch->pcht_handle,
155dc90e12Robert Mustacchi	    (uint16_t *)((uintptr_t)pch->pcht_base + PCHTEMP_REG_TAHV));
156dc90e12Robert Mustacchi	talv = ddi_get16(pch->pcht_handle,
157dc90e12Robert Mustacchi	    (uint16_t *)((uintptr_t)pch->pcht_base + PCHTEMP_REG_TALV));
158dc90e12Robert Mustacchi
159dc90e12Robert Mustacchi	if (pchtemp_read_check(pch) != DDI_FM_OK) {
1600267428Robert Mustacchi		mutex_exit(&pch->pcht_mutex);
161dc90e12Robert Mustacchi		dev_err(pch->pcht_dip, CE_WARN, "failed to read temperature "
162dc90e12Robert Mustacchi		    "data due to FM device error");
163dc90e12Robert Mustacchi		return (EIO);
164dc90e12Robert Mustacchi	}
165dc90e12Robert Mustacchi
166dc90e12Robert Mustacchi	pch->pcht_temp_raw = temp;
167dc90e12Robert Mustacchi	pch->pcht_tsel_raw = tsel;
168dc90e12Robert Mustacchi	pch->pcht_ctt_raw = ctt;
169dc90e12Robert Mustacchi	pch->pcht_tahv_raw = tahv;
170dc90e12Robert Mustacchi	pch->pcht_talv_raw = talv;
171dc90e12Robert Mustacchi
172dc90e12Robert Mustacchi	if ((tsel & PCHTEMP_REG_TSEL_ETS) == 0) {
1730267428Robert Mustacchi		mutex_exit(&pch->pcht_mutex);
174dc90e12Robert Mustacchi		return (ENXIO);
175dc90e12Robert Mustacchi	}
176dc90e12Robert Mustacchi
177dc90e12Robert Mustacchi	pch->pcht_temp = (temp & PCHTEMP_REG_TEMP_TSR) - PCHTEMP_TEMP_OFFSET;
1780267428Robert Mustacchi	sit->sit_unit = SENSOR_UNIT_CELSIUS;
1790267428Robert Mustacchi	sit->sit_gran = PCHTEMP_TEMP_RESOLUTION;
1800267428Robert Mustacchi	sit->sit_temp = pch->pcht_temp;
181dc90e12Robert Mustacchi	mutex_exit(&pch->pcht_mutex);
182dc90e12Robert Mustacchi
183dc90e12Robert Mustacchi	return (0);
184dc90e12Robert Mustacchi}
185dc90e12Robert Mustacchi
1860267428Robert Mustacchistatic const ksensor_ops_t pchtemp_temp_ops = {
1870267428Robert Mustacchi	.kso_kind = ksensor_kind_temperature,
1880267428Robert Mustacchi	.kso_temp = pchtemp_read
1890267428Robert Mustacchi};
190dc90e12Robert Mustacchi
191dc90e12Robert Mustacchistatic void
192dc90e12Robert Mustacchipchtemp_cleanup(pchtemp_t *pch)
193dc90e12Robert Mustacchi{
194dc90e12Robert Mustacchi	int inst;
195dc90e12Robert Mustacchi
196dc90e12Robert Mustacchi	ASSERT3P(pch->pcht_dip, !=, NULL);
197dc90e12Robert Mustacchi	inst = ddi_get_instance(pch->pcht_dip);
198dc90e12Robert Mustacchi
1990267428Robert Mustacchi	(void) ksensor_remove(pch->pcht_dip, KSENSOR_ALL_IDS);
200dc90e12Robert Mustacchi
201dc90e12Robert Mustacchi	if (pch->pcht_handle != NULL) {
202dc90e12Robert Mustacchi		ddi_regs_map_free(&pch->pcht_handle);
203dc90e12Robert Mustacchi	}
204dc90e12Robert Mustacchi
205dc90e12Robert Mustacchi	if (pch->pcht_fm_caps != DDI_FM_NOT_CAPABLE) {
206dc90e12Robert Mustacchi		ddi_fm_fini(pch->pcht_dip);
207dc90e12Robert Mustacchi	}
208dc90e12Robert Mustacchi
209dc90e12Robert Mustacchi	mutex_destroy(&pch->pcht_mutex);
210dc90e12Robert Mustacchi	ddi_soft_state_free(pchtemp_state, inst);
211dc90e12Robert Mustacchi}
212dc90e12Robert Mustacchi
213dc90e12Robert Mustacchistatic int
214dc90e12Robert Mustacchipchtemp_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
215dc90e12Robert Mustacchi{
216dc90e12Robert Mustacchi	int inst, ret;
217dc90e12Robert Mustacchi	pchtemp_t *pch;
218dc90e12Robert Mustacchi	off_t memsize;
219dc90e12Robert Mustacchi	ddi_device_acc_attr_t da;
220dc90e12Robert Mustacchi	ddi_iblock_cookie_t iblk;
221dc90e12Robert Mustacchi	char name[1024];
222dc90e12Robert Mustacchi
223dc90e12Robert Mustacchi	switch (cmd) {
224dc90e12Robert Mustacchi	case DDI_RESUME:
225dc90e12Robert Mustacchi		return (DDI_SUCCESS);
226dc90e12Robert Mustacchi	case DDI_ATTACH:
227dc90e12Robert Mustacchi		break;
228dc90e12Robert Mustacchi	default:
229dc90e12Robert Mustacchi		return (DDI_FAILURE);
230dc90e12Robert Mustacchi	}
231dc90e12Robert Mustacchi
232dc90e12Robert Mustacchi	inst = ddi_get_instance(dip);
233dc90e12Robert Mustacchi	if (ddi_soft_state_zalloc(pchtemp_state, inst) != DDI_SUCCESS) {
234dc90e12Robert Mustacchi		dev_err(dip, CE_WARN, "failed to allocate soft state entry %d",
235dc90e12Robert Mustacchi		    inst);
236dc90e12Robert Mustacchi		return (DDI_FAILURE);
237dc90e12Robert Mustacchi	}
238dc90e12Robert Mustacchi
239dc90e12Robert Mustacchi	pch = ddi_get_soft_state(pchtemp_state, inst);
240dc90e12Robert Mustacchi	if (pch == NULL) {
241dc90e12Robert Mustacchi		dev_err(dip, CE_WARN, "failed to retrieve soft state entry %d",
242dc90e12Robert Mustacchi		    inst);
243dc90e12Robert Mustacchi		return (DDI_FAILURE);
244dc90e12Robert Mustacchi	}
245dc90e12Robert Mustacchi	pch->pcht_dip = dip;
246dc90e12Robert Mustacchi
247dc90e12Robert Mustacchi	pch->pcht_fm_caps = DDI_FM_ACCCHK_CAPABLE;
248dc90e12Robert Mustacchi	ddi_fm_init(dip, &pch->pcht_fm_caps, &iblk);
249dc90e12Robert Mustacchi
250dc90e12Robert Mustacchi	mutex_init(&pch->pcht_mutex, NULL, MUTEX_DRIVER, NULL);
251dc90e12Robert Mustacchi
252dc90e12Robert Mustacchi	if (ddi_dev_regsize(dip, PCHTEMP_RNUMBER, &memsize) != DDI_SUCCESS) {
253dc90e12Robert Mustacchi		dev_err(dip, CE_WARN, "failed to obtain register size for "
254dc90e12Robert Mustacchi		    "register set %d", PCHTEMP_RNUMBER);
255dc90e12Robert Mustacchi		goto err;
256dc90e12Robert Mustacchi	}
257dc90e12Robert Mustacchi
258dc90e12Robert Mustacchi	bzero(&da, sizeof (ddi_device_acc_attr_t));
259dc90e12Robert Mustacchi	da.devacc_attr_version = DDI_DEVICE_ATTR_V0;
260dc90e12Robert Mustacchi	da.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
261dc90e12Robert Mustacchi	da.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
262dc90e12Robert Mustacchi
263dc90e12Robert Mustacchi	if (DDI_FM_ACC_ERR_CAP(pch->pcht_fm_caps)) {
264dc90e12Robert Mustacchi		da.devacc_attr_access = DDI_FLAGERR_ACC;
265dc90e12Robert Mustacchi	} else {
266dc90e12Robert Mustacchi		da.devacc_attr_access = DDI_DEFAULT_ACC;
267dc90e12Robert Mustacchi	}
268dc90e12Robert Mustacchi
269dc90e12Robert Mustacchi	if ((ret = ddi_regs_map_setup(dip, PCHTEMP_RNUMBER, &pch->pcht_base,
270dc90e12Robert Mustacchi	    0, memsize, &da, &pch->pcht_handle)) != DDI_SUCCESS) {
271dc90e12Robert Mustacchi		dev_err(dip, CE_WARN, "failed to map register set %d: %d",
272dc90e12Robert Mustacchi		    PCHTEMP_RNUMBER, ret);
273dc90e12Robert Mustacchi		goto err;
274dc90e12Robert Mustacchi	}
275dc90e12Robert Mustacchi
276dc90e12Robert Mustacchi	if (snprintf(name, sizeof (name), "ts.%d", inst) >= sizeof (name)) {
277dc90e12Robert Mustacchi		dev_err(dip, CE_WARN, "failed to construct minor node name, "
278dc90e12Robert Mustacchi		    "name too long");
279dc90e12Robert Mustacchi		goto err;
280dc90e12Robert Mustacchi	}
281dc90e12Robert Mustacchi
2820267428Robert Mustacchi	if ((ret = ksensor_create(pch->pcht_dip, &pchtemp_temp_ops, pch, name,
2830267428Robert Mustacchi	    DDI_NT_SENSOR_TEMP_PCH, &pch->pcht_ksensor)) != 0) {
284dc90e12Robert Mustacchi		dev_err(dip, CE_WARN, "failed to create minor node %s", name);
285dc90e12Robert Mustacchi		goto err;
286dc90e12Robert Mustacchi	}
287dc90e12Robert Mustacchi
288dc90e12Robert Mustacchi	return (DDI_SUCCESS);
289dc90e12Robert Mustacchi
290dc90e12Robert Mustacchierr:
291dc90e12Robert Mustacchi	pchtemp_cleanup(pch);
292dc90e12Robert Mustacchi	return (DDI_FAILURE);
293dc90e12Robert Mustacchi}
294dc90e12Robert Mustacchi
295dc90e12Robert Mustacchistatic int
296dc90e12Robert Mustacchipchtemp_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
297dc90e12Robert Mustacchi{
298dc90e12Robert Mustacchi	int inst;
299dc90e12Robert Mustacchi	pchtemp_t *pch;
300dc90e12Robert Mustacchi
301dc90e12Robert Mustacchi	switch (cmd) {
302dc90e12Robert Mustacchi	case DDI_DETACH:
303dc90e12Robert Mustacchi		break;
304dc90e12Robert Mustacchi	case DDI_SUSPEND:
305dc90e12Robert Mustacchi		return (DDI_SUCCESS);
306dc90e12Robert Mustacchi	default:
307dc90e12Robert Mustacchi		return (DDI_FAILURE);
308dc90e12Robert Mustacchi	}
309dc90e12Robert Mustacchi
310dc90e12Robert Mustacchi	inst = ddi_get_instance(dip);
311dc90e12Robert Mustacchi	pch = ddi_get_soft_state(pchtemp_state, inst);
312dc90e12Robert Mustacchi	if (pch == NULL) {
313dc90e12Robert Mustacchi		dev_err(dip, CE_WARN, "asked to detached instance %d, but "
314dc90e12Robert Mustacchi		    "it does not exist in soft state", inst);
315dc90e12Robert Mustacchi		return (DDI_FAILURE);
316dc90e12Robert Mustacchi	}
317dc90e12Robert Mustacchi
318dc90e12Robert Mustacchi	pchtemp_cleanup(pch);
319dc90e12Robert Mustacchi	return (DDI_SUCCESS);
320dc90e12Robert Mustacchi}
321dc90e12Robert Mustacchi
322dc90e12Robert Mustacchistatic struct dev_ops pchtemp_dev_ops = {
323dc90e12Robert Mustacchi	.devo_rev = DEVO_REV,
324dc90e12Robert Mustacchi	.devo_refcnt = 0,
3250267428Robert Mustacchi	.devo_getinfo = nodev,
326dc90e12Robert Mustacchi	.devo_identify = nulldev,
327dc90e12Robert Mustacchi	.devo_probe = nulldev,
328dc90e12Robert Mustacchi	.devo_attach = pchtemp_attach,
329dc90e12Robert Mustacchi	.devo_detach = pchtemp_detach,
330dc90e12Robert Mustacchi	.devo_reset = nodev,
331dc90e12Robert Mustacchi	.devo_power = ddi_power,
3320267428Robert Mustacchi	.devo_quiesce = ddi_quiesce_not_needed
333dc90e12Robert Mustacchi};
334dc90e12Robert Mustacchi
335dc90e12Robert Mustacchistatic struct modldrv pchtemp_modldrv = {
336dc90e12Robert Mustacchi	.drv_modops = &mod_driverops,
337dc90e12Robert Mustacchi	.drv_linkinfo = "Intel PCH Thermal Sensor",
338dc90e12Robert Mustacchi	.drv_dev_ops = &pchtemp_dev_ops
339dc90e12Robert Mustacchi};
340dc90e12Robert Mustacchi
341dc90e12Robert Mustacchistatic struct modlinkage pchtemp_modlinkage = {
342dc90e12Robert Mustacchi	.ml_rev = MODREV_1,
343dc90e12Robert Mustacchi	.ml_linkage = { &pchtemp_modldrv, NULL }
344dc90e12Robert Mustacchi};
345dc90e12Robert Mustacchi
346dc90e12Robert Mustacchiint
347dc90e12Robert Mustacchi_init(void)
348dc90e12Robert Mustacchi{
349dc90e12Robert Mustacchi	int ret;
350dc90e12Robert Mustacchi
351dc90e12Robert Mustacchi	if (ddi_soft_state_init(&pchtemp_state, sizeof (pchtemp_t), 1) !=
352dc90e12Robert Mustacchi	    DDI_SUCCESS) {
353dc90e12Robert Mustacchi		return (ENOMEM);
354dc90e12Robert Mustacchi	}
355dc90e12Robert Mustacchi
356dc90e12Robert Mustacchi	if ((ret = mod_install(&pchtemp_modlinkage)) != 0) {
357dc90e12Robert Mustacchi		ddi_soft_state_fini(&pchtemp_state);
358dc90e12Robert Mustacchi		return (ret);
359dc90e12Robert Mustacchi	}
360dc90e12Robert Mustacchi
361dc90e12Robert Mustacchi	return (ret);
362dc90e12Robert Mustacchi}
363dc90e12Robert Mustacchi
364dc90e12Robert Mustacchiint
365dc90e12Robert Mustacchi_info(struct modinfo *modinfop)
366dc90e12Robert Mustacchi{
367dc90e12Robert Mustacchi	return (mod_info(&pchtemp_modlinkage, modinfop));
368dc90e12Robert Mustacchi}
369dc90e12Robert Mustacchi
370dc90e12Robert Mustacchiint
371dc90e12Robert Mustacchi_fini(void)
372dc90e12Robert Mustacchi{
373dc90e12Robert Mustacchi	int ret;
374dc90e12Robert Mustacchi
375dc90e12Robert Mustacchi	if ((ret = mod_remove(&pchtemp_modlinkage)) != 0) {
376dc90e12Robert Mustacchi		return (ret);
377dc90e12Robert Mustacchi	}
378dc90e12Robert Mustacchi
379dc90e12Robert Mustacchi	ddi_soft_state_fini(&pchtemp_state);
380dc90e12Robert Mustacchi	return (ret);
381dc90e12Robert Mustacchi}
382