aic7xxx_osm_pci.c 13.1 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3
/*
 * Linux driver attachment glue for PCI based controllers.
 *
Linus Torvalds's avatar
Linus Torvalds committed
4
 * Copyright (c) 2000-2001 Adaptec Inc.
Linus Torvalds's avatar
Linus Torvalds committed
5 6 7 8 9 10 11 12
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
Linus Torvalds's avatar
Linus Torvalds committed
13 14 15 16 17 18 19 20
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
Linus Torvalds's avatar
Linus Torvalds committed
21 22
 *
 * Alternatively, this software may be distributed under the terms of the
Linus Torvalds's avatar
Linus Torvalds committed
23 24
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
Linus Torvalds's avatar
Linus Torvalds committed
25
 *
Linus Torvalds's avatar
Linus Torvalds committed
26 27 28 29 30 31
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Linus Torvalds's avatar
Linus Torvalds committed
32 33
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Linus Torvalds's avatar
Linus Torvalds committed
34 35 36 37
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
Linus Torvalds's avatar
Linus Torvalds committed
38
 *
39
 * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c#47 $
Linus Torvalds's avatar
Linus Torvalds committed
40 41 42
 */

#include "aic7xxx_osm.h"
43
#include "aic7xxx_pci.h"
Linus Torvalds's avatar
Linus Torvalds committed
44 45 46 47 48 49 50 51 52

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
struct pci_device_id
{
};
#endif

static int	ahc_linux_pci_dev_probe(struct pci_dev *pdev,
					const struct pci_device_id *ent);
Linus Torvalds's avatar
Linus Torvalds committed
53 54 55 56 57
static int	ahc_linux_pci_reserve_io_region(struct ahc_softc *ahc,
						u_long *base);
static int	ahc_linux_pci_reserve_mem_region(struct ahc_softc *ahc,
						 u_long *bus_addr,
						 uint8_t **maddr);
Linus Torvalds's avatar
Linus Torvalds committed
58 59 60
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
static void	ahc_linux_pci_dev_remove(struct pci_dev *pdev);

61 62 63 64
/* Define the macro locally since it's different for different class of chips.
*/
#define ID(x)	ID_C(x, PCI_CLASS_STORAGE_SCSI)

Linus Torvalds's avatar
Linus Torvalds committed
65
static struct pci_device_id ahc_linux_pci_id_table[] = {
66
	/* aic7850 based controllers */
67
	ID(ID_AHA_2902_04_10_15_20C_30C),
68
	/* aic7860 based controllers */
69 70 71 72 73
	ID(ID_AHA_2930CU),
	ID(ID_AHA_1480A & ID_DEV_VENDOR_MASK),
	ID(ID_AHA_2940AU_0 & ID_DEV_VENDOR_MASK),
	ID(ID_AHA_2940AU_CN & ID_DEV_VENDOR_MASK),
	ID(ID_AHA_2930C_VAR & ID_DEV_VENDOR_MASK),
74
	/* aic7870 based controllers */
75 76 77 78 79 80
	ID(ID_AHA_2940),
	ID(ID_AHA_3940),
	ID(ID_AHA_398X),
	ID(ID_AHA_2944),
	ID(ID_AHA_3944),
	ID(ID_AHA_4944),
81
	/* aic7880 based controllers */
82 83 84 85 86 87 88 89 90
	ID(ID_AHA_2940U & ID_DEV_VENDOR_MASK),
	ID(ID_AHA_3940U & ID_DEV_VENDOR_MASK),
	ID(ID_AHA_2944U & ID_DEV_VENDOR_MASK),
	ID(ID_AHA_3944U & ID_DEV_VENDOR_MASK),
	ID(ID_AHA_398XU & ID_DEV_VENDOR_MASK),
	ID(ID_AHA_4944U & ID_DEV_VENDOR_MASK),
	ID(ID_AHA_2930U & ID_DEV_VENDOR_MASK),
	ID(ID_AHA_2940U_PRO & ID_DEV_VENDOR_MASK),
	ID(ID_AHA_2940U_CN & ID_DEV_VENDOR_MASK),
91
	/* aic7890 based controllers */
92 93 94 95 96
	ID(ID_AHA_2930U2),
	ID(ID_AHA_2940U2B),
	ID(ID_AHA_2940U2_OEM),
	ID(ID_AHA_2940U2),
	ID(ID_AHA_2950U2B),
97
	ID16(ID_AIC7890_ARO & ID_AIC7895_ARO_MASK),
98
	ID(ID_AAA_131U2),
99
	/* aic7890 based controllers */
100 101 102 103 104 105 106
	ID(ID_AHA_29160),
	ID(ID_AHA_29160_CPQ),
	ID(ID_AHA_29160N),
	ID(ID_AHA_29160C),
	ID(ID_AHA_29160B),
	ID(ID_AHA_19160B),
	ID(ID_AIC7892_ARO),
107
	/* aic7892 based controllers */
108 109 110 111 112 113 114 115 116
	ID(ID_AHA_2940U_DUAL),
	ID(ID_AHA_3940AU),
	ID(ID_AHA_3944AU),
	ID(ID_AIC7895_ARO),
	ID(ID_AHA_3950U2B_0),
	ID(ID_AHA_3950U2B_1),
	ID(ID_AHA_3950U2D_0),
	ID(ID_AHA_3950U2D_1),
	ID(ID_AIC7896_ARO),
117
	/* aic7899 based controllers */
118 119 120
	ID(ID_AHA_3960D),
	ID(ID_AHA_3960D_CPQ),
	ID(ID_AIC7899_ARO),
121
	/* Generic chip probes for devices we don't know exactly. */
122 123 124 125 126 127
	ID(ID_AIC7850 & ID_DEV_VENDOR_MASK),
	ID(ID_AIC7855 & ID_DEV_VENDOR_MASK),
	ID(ID_AIC7859 & ID_DEV_VENDOR_MASK),
	ID(ID_AIC7860 & ID_DEV_VENDOR_MASK),
	ID(ID_AIC7870 & ID_DEV_VENDOR_MASK),
	ID(ID_AIC7880 & ID_DEV_VENDOR_MASK),
128 129
 	ID16(ID_AIC7890 & ID_9005_GENERIC_MASK),
 	ID16(ID_AIC7892 & ID_9005_GENERIC_MASK),
130
	ID(ID_AIC7895 & ID_DEV_VENDOR_MASK),
131 132
	ID16(ID_AIC7896 & ID_9005_GENERIC_MASK),
	ID16(ID_AIC7899 & ID_9005_GENERIC_MASK),
133 134
	ID(ID_AIC7810 & ID_DEV_VENDOR_MASK),
	ID(ID_AIC7815 & ID_DEV_VENDOR_MASK),
Linus Torvalds's avatar
Linus Torvalds committed
135 136
	{ 0 }
};
137

Linus Torvalds's avatar
Linus Torvalds committed
138
MODULE_DEVICE_TABLE(pci, ahc_linux_pci_id_table);
Linus Torvalds's avatar
Linus Torvalds committed
139

Linus Torvalds's avatar
Linus Torvalds committed
140
struct pci_driver aic7xxx_pci_driver = {
141 142 143 144
	.name		= "aic7xxx",
	.probe		= ahc_linux_pci_dev_probe,
	.remove		= ahc_linux_pci_dev_remove,
	.id_table	= ahc_linux_pci_id_table
Linus Torvalds's avatar
Linus Torvalds committed
145 146 147 148 149 150
};

static void
ahc_linux_pci_dev_remove(struct pci_dev *pdev)
{
	struct ahc_softc *ahc;
151
	u_long l;
Linus Torvalds's avatar
Linus Torvalds committed
152 153 154 155 156 157

	/*
	 * We should be able to just perform
	 * the free directly, but check our
	 * list for extra sanity.
	 */
158
	ahc_list_lock(&l);
159
	ahc = ahc_find_softc((struct ahc_softc *)pci_get_drvdata(pdev));
160 161 162
	if (ahc != NULL) {
		u_long s;

163 164
		TAILQ_REMOVE(&ahc_tailq, ahc, links);
		ahc_list_unlock(&l);
165 166 167 168
		ahc_lock(ahc, &s);
		ahc_intr_enable(ahc, FALSE);
		ahc_unlock(ahc, &s);
		ahc_free(ahc);
169 170
	} else
		ahc_list_unlock(&l);
Linus Torvalds's avatar
Linus Torvalds committed
171 172 173 174 175 176
}
#endif /* !LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) */

static int
ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
{
Linus Torvalds's avatar
Linus Torvalds committed
177
	char		 buf[80];
178
	dma_addr_t	 mask_39bit;
Linus Torvalds's avatar
Linus Torvalds committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
	struct		 ahc_softc *ahc;
	ahc_dev_softc_t	 pci;
	struct		 ahc_pci_identity *entry;
	char		*name;
	int		 error;

	/*
	 * Some BIOSen report the same device multiple times.
	 */
	TAILQ_FOREACH(ahc, &ahc_tailq, links) {
		struct pci_dev *probed_pdev;

		probed_pdev = ahc->dev_softc;
		if (probed_pdev->bus->number == pdev->bus->number
		 && probed_pdev->devfn == pdev->devfn)
			break;
	}
	if (ahc != NULL) {
		/* Skip duplicate. */
		return (-ENODEV);
	}
Linus Torvalds's avatar
Linus Torvalds committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227

	pci = pdev;
	entry = ahc_find_pci_device(pci);
	if (entry == NULL)
		return (-ENODEV);

	/*
	 * Allocate a softc for this card and
	 * set it up for attachment by our
	 * common detect routine.
	 */
	sprintf(buf, "ahc_pci:%d:%d:%d",
		ahc_get_pci_bus(pci),
		ahc_get_pci_slot(pci),
		ahc_get_pci_function(pci));
	name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
	if (name == NULL)
		return (-ENOMEM);
	strcpy(name, buf);
	ahc = ahc_alloc(NULL, name);
	if (ahc == NULL)
		return (-ENOMEM);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
	if (pci_enable_device(pdev)) {
		ahc_free(ahc);
		return (-ENODEV);
	}
	pci_set_master(pdev);
Linus Torvalds's avatar
Linus Torvalds committed
228

229 230
	mask_39bit = 0x7FFFFFFFFFULL;
	if (sizeof(dma_addr_t) > 4
Linus Torvalds's avatar
Linus Torvalds committed
231
	 && ahc_linux_get_memsize() > 0x80000000
232
	 && pci_set_dma_mask(pdev, mask_39bit) == 0) {
Linus Torvalds's avatar
Linus Torvalds committed
233
		ahc->flags |= AHC_39BIT_ADDRESSING;
234
		ahc->platform_data->hw_dma_mask = mask_39bit;
235
	} else {
236
		if (pci_set_dma_mask(pdev, 0xFFFFFFFF)) {
237 238 239
			printk(KERN_WARNING "aic7xxx: No suitable DMA available.\n");
                	return (-ENODEV);
		}
240
		ahc->platform_data->hw_dma_mask = 0xFFFFFFFF;
Linus Torvalds's avatar
Linus Torvalds committed
241
	}
Linus Torvalds's avatar
Linus Torvalds committed
242 243 244 245 246 247 248 249
#endif
	ahc->dev_softc = pci;
	error = ahc_pci_config(ahc, entry);
	if (error != 0) {
		ahc_free(ahc);
		return (-error);
	}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
Linus Torvalds's avatar
Linus Torvalds committed
250
	pci_set_drvdata(pdev, ahc);
251 252
	if (aic7xxx_detect_complete) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
253
		ahc_linux_register_host(ahc, &aic7xxx_driver_template);
254 255 256 257 258 259
#else
		printf("aic7xxx: ignoring PCI device found after "
		       "initialization\n");
		return (-ENODEV);
#endif
	}
Linus Torvalds's avatar
Linus Torvalds committed
260 261 262 263 264
#endif
	return (0);
}

int
265
ahc_linux_pci_init(void)
Linus Torvalds's avatar
Linus Torvalds committed
266 267
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
268 269
	/* Translate error or zero return into zero or one */
	return pci_module_init(&aic7xxx_pci_driver) ? 0 : 1;
Linus Torvalds's avatar
Linus Torvalds committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
#else
	struct pci_dev *pdev;
	u_int class;
	int found;

	/* If we don't have a PCI bus, we can't find any adapters. */
	if (pci_present() == 0)
		return (0);

	found = 0;
	pdev = NULL;
	class = PCI_CLASS_STORAGE_SCSI << 8;
	while ((pdev = pci_find_class(class, pdev)) != NULL) {
		ahc_dev_softc_t pci;
		int error;

		pci = pdev;
		error = ahc_linux_pci_dev_probe(pdev, /*pci_devid*/NULL);
		if (error == 0)
			found++;
	}
	return (found);
#endif
}

295 296 297 298 299 300
void
ahc_linux_pci_exit(void)
{
	pci_unregister_driver(&aic7xxx_pci_driver);
}

Linus Torvalds's avatar
Linus Torvalds committed
301 302
static int
ahc_linux_pci_reserve_io_region(struct ahc_softc *ahc, u_long *base)
Linus Torvalds's avatar
Linus Torvalds committed
303
{
304 305 306
	if (aic7xxx_allow_memio == 0)
		return (ENOMEM);

Linus Torvalds's avatar
Linus Torvalds committed
307 308 309 310 311
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
	*base = pci_resource_start(ahc->dev_softc, 0);
#else
	*base = ahc_pci_read_config(ahc->dev_softc, PCIR_MAPS, 4);
	*base &= PCI_BASE_ADDRESS_IO_MASK;
Linus Torvalds's avatar
Linus Torvalds committed
312
#endif
313
	if (*base == 0)
Linus Torvalds's avatar
Linus Torvalds committed
314 315 316 317
		return (ENOMEM);
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
	if (check_region(*base, 256) != 0)
		return (ENOMEM);
318
	request_region(*base, 256, "aic7xxx");
Linus Torvalds's avatar
Linus Torvalds committed
319 320 321 322 323 324
#else
	if (request_region(*base, 256, "aic7xxx") == 0)
		return (ENOMEM);
#endif
	return (0);
}
Linus Torvalds's avatar
Linus Torvalds committed
325

Linus Torvalds's avatar
Linus Torvalds committed
326 327 328 329 330 331 332 333 334 335 336
static int
ahc_linux_pci_reserve_mem_region(struct ahc_softc *ahc,
				 u_long *bus_addr,
				 uint8_t **maddr)
{
	u_long	start;
	u_long	base_page;
	u_long	base_offset;
	int	error;

	error = 0;
Linus Torvalds's avatar
Linus Torvalds committed
337 338 339 340 341 342 343 344 345 346 347
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
	start = pci_resource_start(ahc->dev_softc, 1);
	base_page = start & PAGE_MASK;
	base_offset = start - base_page;
#else
	start = ahc_pci_read_config(ahc->dev_softc, PCIR_MAPS+4, 4);
	base_offset = start & PCI_BASE_ADDRESS_MEM_MASK;
	base_page = base_offset & PAGE_MASK;
	base_offset -= base_page;
#endif
	if (start != 0) {
Linus Torvalds's avatar
Linus Torvalds committed
348
		*bus_addr = start;
Linus Torvalds's avatar
Linus Torvalds committed
349
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
Linus Torvalds's avatar
Linus Torvalds committed
350 351 352 353 354
		if (request_mem_region(start, 0x1000, "aic7xxx") == 0)
			error = ENOMEM;
#endif
		if (error == 0) {
			*maddr = ioremap_nocache(base_page, base_offset + 256);
355
			if (*maddr == NULL) {
Linus Torvalds's avatar
Linus Torvalds committed
356
				error = ENOMEM;
357 358 359 360
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
				release_mem_region(start, 0x1000);
#endif
			} else
Linus Torvalds's avatar
Linus Torvalds committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
				*maddr += base_offset;
		}
	} else
		error = ENOMEM;
	return (error);
}

int
ahc_pci_map_registers(struct ahc_softc *ahc)
{
	uint32_t command;
	u_long	 base;
	uint8_t	*maddr;
	int	 error;

	/*
377
	 * If its allowed, we prefer memory mapped access.
Linus Torvalds's avatar
Linus Torvalds committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
	 */
	command = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, 4);
	command &= ~(PCIM_CMD_PORTEN|PCIM_CMD_MEMEN);
	base = 0;
	maddr = NULL;
	error = ahc_linux_pci_reserve_mem_region(ahc, &base, &maddr);
	if (error == 0) {
		ahc->platform_data->mem_busaddr = base;
		ahc->tag = BUS_SPACE_MEMIO;
		ahc->bsh.maddr = maddr;
		ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND,
				     command | PCIM_CMD_MEMEN, 4);

		/*
		 * Do a quick test to see if memory mapped
		 * I/O is functioning correctly.
		 */
395
		if (ahc_pci_test_register_access(ahc) != 0) {
Linus Torvalds's avatar
Linus Torvalds committed
396 397

			printf("aic7xxx: PCI Device %d:%d:%d "
398
			       "failed memory mapped test.  Using PIO.\n",
Linus Torvalds's avatar
Linus Torvalds committed
399 400
			       ahc_get_pci_bus(ahc->dev_softc),
			       ahc_get_pci_slot(ahc->dev_softc),
Linus Torvalds's avatar
Linus Torvalds committed
401
			       ahc_get_pci_function(ahc->dev_softc));
402 403 404 405 406 407
			iounmap((void *)((u_long)maddr & PAGE_MASK));
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
			release_mem_region(ahc->platform_data->mem_busaddr,
					   0x1000);
#endif
			ahc->bsh.maddr = NULL;
Linus Torvalds's avatar
Linus Torvalds committed
408
			maddr = NULL;
Linus Torvalds's avatar
Linus Torvalds committed
409 410
		} else
			command |= PCIM_CMD_MEMEN;
Linus Torvalds's avatar
Linus Torvalds committed
411 412
	} else {
		printf("aic7xxx: PCI%d:%d:%d MEM region 0x%lx "
413
		       "unavailable. Cannot memory map device.\n",
Linus Torvalds's avatar
Linus Torvalds committed
414 415 416 417
		       ahc_get_pci_bus(ahc->dev_softc),
		       ahc_get_pci_slot(ahc->dev_softc),
		       ahc_get_pci_function(ahc->dev_softc),
		       base);
Linus Torvalds's avatar
Linus Torvalds committed
418 419 420
	}

	/*
421
	 * We always prefer memory mapped access.
Linus Torvalds's avatar
Linus Torvalds committed
422 423
	 */
	if (maddr == NULL) {
424 425 426 427 428 429 430

		error = ahc_linux_pci_reserve_io_region(ahc, &base);
		if (error == 0) {
			ahc->tag = BUS_SPACE_PIO;
			ahc->bsh.ioport = base;
			command |= PCIM_CMD_PORTEN;
		} else {
Linus Torvalds's avatar
Linus Torvalds committed
431
			printf("aic7xxx: PCI%d:%d:%d IO region 0x%lx[0..255] "
Linus Torvalds's avatar
Linus Torvalds committed
432
			       "unavailable. Cannot map device.\n",
Linus Torvalds's avatar
Linus Torvalds committed
433 434 435 436 437 438
			       ahc_get_pci_bus(ahc->dev_softc),
			       ahc_get_pci_slot(ahc->dev_softc),
			       ahc_get_pci_function(ahc->dev_softc),
			       base);
		}
	}
Linus Torvalds's avatar
Linus Torvalds committed
439 440
	ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, command, 4);
	return (error);
Linus Torvalds's avatar
Linus Torvalds committed
441 442 443 444 445 446 447
}

int
ahc_pci_map_int(struct ahc_softc *ahc)
{
	int error;

448
	error = request_irq(ahc->dev_softc->irq, ahc_linux_isr,
Linus Torvalds's avatar
Linus Torvalds committed
449
			    SA_SHIRQ, "aic7xxx", ahc);
450 451
	if (error == 0)
		ahc->platform_data->irq = ahc->dev_softc->irq;
Linus Torvalds's avatar
Linus Torvalds committed
452 453 454
	
	return (-error);
}
Linus Torvalds's avatar
Linus Torvalds committed
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493

void
ahc_power_state_change(struct ahc_softc *ahc, ahc_power_state new_state)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
	pci_set_power_state(ahc->dev_softc, new_state);
#else
	uint32_t cap;
	u_int cap_offset;

	/*
	 * Traverse the capability list looking for
	 * the power management capability.
	 */
	cap = 0;
	cap_offset = ahc_pci_read_config(ahc->dev_softc,
					 PCIR_CAP_PTR, /*bytes*/1);
	while (cap_offset != 0) {

		cap = ahc_pci_read_config(ahc->dev_softc,
					  cap_offset, /*bytes*/4);
		if ((cap & 0xFF) == 1
		 && ((cap >> 16) & 0x3) > 0) {
			uint32_t pm_control;

			pm_control = ahc_pci_read_config(ahc->dev_softc,
							 cap_offset + 4,
							 /*bytes*/4);
			pm_control &= ~0x3;
			pm_control |= new_state;
			ahc_pci_write_config(ahc->dev_softc,
					     cap_offset + 4,
					     pm_control, /*bytes*/2);
			break;
		}
		cap_offset = (cap >> 8) & 0xFF;
	}
#endif 
}