2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1998 - 2008 Søren Schmidt <sos@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/module.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
38 #include <sys/endian.h>
39 #include <sys/malloc.h>
41 #include <sys/mutex.h>
43 #include <sys/taskqueue.h>
45 #include <machine/stdarg.h>
46 #include <machine/resource.h>
47 #include <machine/bus.h>
49 #include <dev/pci/pcivar.h>
50 #include <dev/pci/pcireg.h>
51 #include <dev/ata/ata-all.h>
52 #include <dev/ata/ata-pci.h>
55 /* local prototypes */
56 static int ata_promise_chipinit(device_t dev);
57 static int ata_promise_ch_attach(device_t dev);
58 static int ata_promise_status(device_t dev);
59 static int ata_promise_dmastart(struct ata_request *request);
60 static int ata_promise_dmastop(struct ata_request *request);
61 static void ata_promise_dmareset(device_t dev);
62 static int ata_promise_setmode(device_t dev, int target, int mode);
63 static int ata_promise_tx2_ch_attach(device_t dev);
64 static int ata_promise_tx2_status(device_t dev);
65 static int ata_promise_mio_ch_attach(device_t dev);
66 static int ata_promise_mio_ch_detach(device_t dev);
67 static void ata_promise_mio_intr(void *data);
68 static int ata_promise_mio_status(device_t dev);
69 static int ata_promise_mio_command(struct ata_request *request);
70 static void ata_promise_mio_reset(device_t dev);
71 static int ata_promise_mio_pm_read(device_t dev, int port, int reg, u_int32_t *result);
72 static int ata_promise_mio_pm_write(device_t dev, int port, int reg, u_int32_t result);
73 static u_int32_t ata_promise_mio_softreset(device_t dev, int port);
74 static void ata_promise_mio_dmainit(device_t dev);
75 static void ata_promise_mio_setprd(void *xsc, bus_dma_segment_t *segs, int nsegs, int error);
76 static int ata_promise_mio_setmode(device_t dev, int target, int mode);
77 static int ata_promise_mio_getrev(device_t dev, int target);
78 static void ata_promise_sx4_intr(void *data);
79 static int ata_promise_sx4_command(struct ata_request *request);
80 static int ata_promise_apkt(u_int8_t *bytep, struct ata_request *request);
81 static void ata_promise_queue_hpkt(struct ata_pci_controller *ctlr, u_int32_t hpkt);
82 static void ata_promise_next_hpkt(struct ata_pci_controller *ctlr);
99 * Promise chipset support functions
101 #define ATA_PDC_APKT_OFFSET 0x00000010
102 #define ATA_PDC_HPKT_OFFSET 0x00000040
103 #define ATA_PDC_ASG_OFFSET 0x00000080
104 #define ATA_PDC_LSG_OFFSET 0x000000c0
105 #define ATA_PDC_HSG_OFFSET 0x00000100
106 #define ATA_PDC_CHN_OFFSET 0x00000400
107 #define ATA_PDC_BUF_BASE 0x00400000
108 #define ATA_PDC_BUF_OFFSET 0x00100000
109 #define ATA_PDC_MAX_HPKT 8
110 #define ATA_PDC_WRITE_REG 0x00
111 #define ATA_PDC_WRITE_CTL 0x0e
112 #define ATA_PDC_WRITE_END 0x08
113 #define ATA_PDC_WAIT_NBUSY 0x10
114 #define ATA_PDC_WAIT_READY 0x18
115 #define ATA_PDC_1B 0x20
116 #define ATA_PDC_2B 0x40
120 TAILQ_ENTRY(host_packet) chain;
123 struct ata_promise_sx4 {
125 TAILQ_HEAD(, host_packet) queue;
130 ata_promise_probe(device_t dev)
132 struct ata_pci_controller *ctlr = device_get_softc(dev);
133 const struct ata_chip_id *idx;
134 static const struct ata_chip_id ids[] =
135 {{ ATA_PDC20246, 0, PR_OLD, 0x00, ATA_UDMA2, "PDC20246" },
136 { ATA_PDC20262, 0, PR_NEW, 0x00, ATA_UDMA4, "PDC20262" },
137 { ATA_PDC20263, 0, PR_NEW, 0x00, ATA_UDMA4, "PDC20263" },
138 { ATA_PDC20265, 0, PR_NEW, 0x00, ATA_UDMA5, "PDC20265" },
139 { ATA_PDC20267, 0, PR_NEW, 0x00, ATA_UDMA5, "PDC20267" },
140 { ATA_PDC20268, 0, PR_TX, PR_TX4, ATA_UDMA5, "PDC20268" },
141 { ATA_PDC20269, 0, PR_TX, 0x00, ATA_UDMA6, "PDC20269" },
142 { ATA_PDC20270, 0, PR_TX, PR_TX4, ATA_UDMA5, "PDC20270" },
143 { ATA_PDC20271, 0, PR_TX, 0x00, ATA_UDMA6, "PDC20271" },
144 { ATA_PDC20275, 0, PR_TX, 0x00, ATA_UDMA6, "PDC20275" },
145 { ATA_PDC20276, 0, PR_TX, PR_SX6K, ATA_UDMA6, "PDC20276" },
146 { ATA_PDC20277, 0, PR_TX, 0x00, ATA_UDMA6, "PDC20277" },
147 { ATA_PDC20318, 0, PR_MIO, PR_SATA, ATA_SA150, "PDC20318" },
148 { ATA_PDC20319, 0, PR_MIO, PR_SATA, ATA_SA150, "PDC20319" },
149 { ATA_PDC20371, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20371" },
150 { ATA_PDC20375, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20375" },
151 { ATA_PDC20376, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20376" },
152 { ATA_PDC20377, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20377" },
153 { ATA_PDC20378, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20378" },
154 { ATA_PDC20379, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20379" },
155 { ATA_PDC20571, 0, PR_MIO, PR_CMBO2, ATA_SA150, "PDC20571" },
156 { ATA_PDC20575, 0, PR_MIO, PR_CMBO2, ATA_SA150, "PDC20575" },
157 { ATA_PDC20579, 0, PR_MIO, PR_CMBO2, ATA_SA150, "PDC20579" },
158 { ATA_PDC20771, 0, PR_MIO, PR_CMBO2, ATA_SA300, "PDC20771" },
159 { ATA_PDC40775, 0, PR_MIO, PR_CMBO2, ATA_SA300, "PDC40775" },
160 { ATA_PDC20617, 0, PR_MIO, PR_PATA, ATA_UDMA6, "PDC20617" },
161 { ATA_PDC20618, 0, PR_MIO, PR_PATA, ATA_UDMA6, "PDC20618" },
162 { ATA_PDC20619, 0, PR_MIO, PR_PATA, ATA_UDMA6, "PDC20619" },
163 { ATA_PDC20620, 0, PR_MIO, PR_PATA, ATA_UDMA6, "PDC20620" },
164 { ATA_PDC20621, 0, PR_MIO, PR_SX4X, ATA_UDMA5, "PDC20621" },
165 { ATA_PDC20622, 0, PR_MIO, PR_SX4X, ATA_SA150, "PDC20622" },
166 { ATA_PDC40518, 0, PR_MIO, PR_SATA2, ATA_SA150, "PDC40518" },
167 { ATA_PDC40519, 0, PR_MIO, PR_SATA2, ATA_SA150, "PDC40519" },
168 { ATA_PDC40718, 0, PR_MIO, PR_SATA2, ATA_SA300, "PDC40718" },
169 { ATA_PDC40719, 0, PR_MIO, PR_SATA2, ATA_SA300, "PDC40719" },
170 { ATA_PDC40779, 0, PR_MIO, PR_SATA2, ATA_SA300, "PDC40779" },
171 { 0, 0, 0, 0, 0, 0}};
175 if (pci_get_vendor(dev) != ATA_PROMISE_ID)
178 if (!(idx = ata_match_chip(dev, ids)))
181 /* if we are on a SuperTrak SX6000 dont attach */
182 if ((idx->cfg2 & PR_SX6K) && pci_get_class(GRANDPARENT(dev))==PCIC_BRIDGE &&
183 !BUS_READ_IVAR(device_get_parent(GRANDPARENT(dev)),
184 GRANDPARENT(dev), PCI_IVAR_DEVID, &devid) &&
188 strcpy(buffer, "Promise ");
189 strcat(buffer, idx->text);
191 /* if we are on a FastTrak TX4, adjust the interrupt resource */
192 if ((idx->cfg2 & PR_TX4) && pci_get_class(GRANDPARENT(dev))==PCIC_BRIDGE &&
193 !BUS_READ_IVAR(device_get_parent(GRANDPARENT(dev)),
194 GRANDPARENT(dev), PCI_IVAR_DEVID, &devid) &&
195 ((devid == ATA_DEC_21150) || (devid == ATA_DEC_21150_1))) {
196 static rman_res_t start = 0, end = 0;
198 if (pci_get_slot(dev) == 1) {
199 bus_get_resource(dev, SYS_RES_IRQ, 0, &start, &end);
200 strcat(buffer, " (channel 0+1)");
202 else if (pci_get_slot(dev) == 2 && start && end) {
203 bus_set_resource(dev, SYS_RES_IRQ, 0, start, end);
204 strcat(buffer, " (channel 2+3)");
210 sprintf(buffer, "%s %s controller", buffer, ata_mode2str(idx->max_dma));
211 device_set_desc_copy(dev, buffer);
213 ctlr->chipinit = ata_promise_chipinit;
214 return (BUS_PROBE_LOW_PRIORITY);
218 ata_promise_chipinit(device_t dev)
220 struct ata_pci_controller *ctlr = device_get_softc(dev);
223 if (ata_setup_interrupt(dev, ata_generic_intr))
226 switch (ctlr->chip->cfg1) {
229 ATA_OUTB(ctlr->r_res1, 0x11, ATA_INB(ctlr->r_res1, 0x11) | 0x0a);
233 /* enable burst mode */
234 ATA_OUTB(ctlr->r_res1, 0x1f, ATA_INB(ctlr->r_res1, 0x1f) | 0x01);
235 ctlr->ch_attach = ata_promise_ch_attach;
236 ctlr->ch_detach = ata_pci_ch_detach;
237 ctlr->setmode = ata_promise_setmode;
241 ctlr->ch_attach = ata_promise_tx2_ch_attach;
242 ctlr->ch_detach = ata_pci_ch_detach;
243 ctlr->setmode = ata_promise_setmode;
247 ctlr->r_type1 = SYS_RES_MEMORY;
248 ctlr->r_rid1 = PCIR_BAR(4);
249 if (!(ctlr->r_res1 = bus_alloc_resource_any(dev, ctlr->r_type1,
250 &ctlr->r_rid1, RF_ACTIVE)))
254 if (ctlr->chip->cfg2 == PR_SX4X &&
255 !bus_space_map(rman_get_bustag(ctlr->r_res1),
256 rman_get_bushandle(ctlr->r_res1), rman_get_size(ctlr->r_res1),
257 BUS_SPACE_MAP_LINEAR, NULL))
261 ctlr->r_type2 = SYS_RES_MEMORY;
262 ctlr->r_rid2 = PCIR_BAR(3);
263 if (!(ctlr->r_res2 = bus_alloc_resource_any(dev, ctlr->r_type2,
264 &ctlr->r_rid2, RF_ACTIVE)))
267 if (ctlr->chip->cfg2 == PR_SX4X) {
268 struct ata_promise_sx4 *hpkt;
269 u_int32_t dimm = ATA_INL(ctlr->r_res2, 0x000c0080);
271 if (bus_teardown_intr(dev, ctlr->r_irq, ctlr->handle) ||
272 bus_setup_intr(dev, ctlr->r_irq, ATA_INTR_FLAGS, NULL,
273 ata_promise_sx4_intr, ctlr, &ctlr->handle)) {
274 device_printf(dev, "unable to setup interrupt\n");
278 /* print info about cache memory */
279 device_printf(dev, "DIMM size %dMB @ 0x%08x%s\n",
280 (((dimm >> 16) & 0xff)-((dimm >> 24) & 0xff)+1) << 4,
281 ((dimm >> 24) & 0xff),
282 ATA_INL(ctlr->r_res2, 0x000c0088) & (1<<16) ?
283 " ECC enabled" : "" );
285 /* adjust cache memory parameters */
286 ATA_OUTL(ctlr->r_res2, 0x000c000c,
287 (ATA_INL(ctlr->r_res2, 0x000c000c) & 0xffff0000));
289 /* setup host packet controls */
290 hpkt = malloc(sizeof(struct ata_promise_sx4),
291 M_ATAPCI, M_NOWAIT | M_ZERO);
293 device_printf(dev, "Cannot allocate HPKT\n");
296 mtx_init(&hpkt->mtx, "ATA promise HPKT lock", NULL, MTX_DEF);
297 TAILQ_INIT(&hpkt->queue);
299 ctlr->chipset_data = hpkt;
300 ctlr->ch_attach = ata_promise_mio_ch_attach;
301 ctlr->ch_detach = ata_promise_mio_ch_detach;
302 ctlr->reset = ata_promise_mio_reset;
303 ctlr->setmode = ata_promise_setmode;
308 /* mio type controllers need an interrupt intercept */
309 if (bus_teardown_intr(dev, ctlr->r_irq, ctlr->handle) ||
310 bus_setup_intr(dev, ctlr->r_irq, ATA_INTR_FLAGS, NULL,
311 ata_promise_mio_intr, ctlr, &ctlr->handle)) {
312 device_printf(dev, "unable to setup interrupt\n");
316 switch (ctlr->chip->cfg2) {
318 ctlr->channels = ((ATA_INL(ctlr->r_res2, 0x48) & 0x01) > 0) +
319 ((ATA_INL(ctlr->r_res2, 0x48) & 0x02) > 0) + 2;
341 /* prime fake interrupt register */
342 ctlr->chipset_data = (void *)(uintptr_t)0xffffffff;
344 /* clear SATA status and unmask interrupts */
345 ATA_OUTL(ctlr->r_res2, stat_reg, 0x000000ff);
347 /* enable "long burst length" on gen2 chips */
348 if ((ctlr->chip->cfg2 == PR_SATA2) || (ctlr->chip->cfg2 == PR_CMBO2))
349 ATA_OUTL(ctlr->r_res2, 0x44, ATA_INL(ctlr->r_res2, 0x44) | 0x2000);
351 ctlr->ch_attach = ata_promise_mio_ch_attach;
352 ctlr->ch_detach = ata_promise_mio_ch_detach;
353 ctlr->reset = ata_promise_mio_reset;
354 ctlr->setmode = ata_promise_mio_setmode;
355 ctlr->getrev = ata_promise_mio_getrev;
362 bus_release_resource(dev, ctlr->r_type2, ctlr->r_rid2, ctlr->r_res2);
364 bus_release_resource(dev, ctlr->r_type1, ctlr->r_rid1, ctlr->r_res1);
369 ata_promise_ch_attach(device_t dev)
371 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
372 struct ata_channel *ch = device_get_softc(dev);
374 if (ata_pci_ch_attach(dev))
377 if (ctlr->chip->cfg1 == PR_NEW) {
378 ch->dma.start = ata_promise_dmastart;
379 ch->dma.stop = ata_promise_dmastop;
380 ch->dma.reset = ata_promise_dmareset;
383 ch->hw.status = ata_promise_status;
384 ch->flags |= ATA_NO_ATAPI_DMA;
385 ch->flags |= ATA_CHECKS_CABLE;
390 ata_promise_status(device_t dev)
392 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
393 struct ata_channel *ch = device_get_softc(dev);
395 if (ATA_INL(ctlr->r_res1, 0x1c) & (ch->unit ? 0x00004000 : 0x00000400)) {
396 return ata_pci_status(dev);
402 ata_promise_dmastart(struct ata_request *request)
404 struct ata_pci_controller *ctlr=device_get_softc(device_get_parent(request->parent));
405 struct ata_channel *ch = device_get_softc(request->parent);
407 if (request->flags & ATA_R_48BIT) {
408 ATA_OUTB(ctlr->r_res1, 0x11,
409 ATA_INB(ctlr->r_res1, 0x11) | (ch->unit ? 0x08 : 0x02));
410 ATA_OUTL(ctlr->r_res1, ch->unit ? 0x24 : 0x20,
411 ((request->flags & ATA_R_READ) ? 0x05000000 : 0x06000000) |
412 (request->bytecount >> 1));
414 ATA_IDX_OUTB(ch, ATA_BMSTAT_PORT, (ATA_IDX_INB(ch, ATA_BMSTAT_PORT) |
415 (ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR)));
416 ATA_IDX_OUTL(ch, ATA_BMDTP_PORT, request->dma->sg_bus);
417 ATA_IDX_OUTB(ch, ATA_BMCMD_PORT,
418 ((request->flags & ATA_R_READ) ? ATA_BMCMD_WRITE_READ : 0) |
419 ATA_BMCMD_START_STOP);
420 ch->dma.flags |= ATA_DMA_ACTIVE;
425 ata_promise_dmastop(struct ata_request *request)
427 struct ata_pci_controller *ctlr=device_get_softc(device_get_parent(request->parent));
428 struct ata_channel *ch = device_get_softc(request->parent);
431 if (request->flags & ATA_R_48BIT) {
432 ATA_OUTB(ctlr->r_res1, 0x11,
433 ATA_INB(ctlr->r_res1, 0x11) & ~(ch->unit ? 0x08 : 0x02));
434 ATA_OUTL(ctlr->r_res1, ch->unit ? 0x24 : 0x20, 0);
436 error = ATA_IDX_INB(ch, ATA_BMSTAT_PORT);
437 ATA_IDX_OUTB(ch, ATA_BMCMD_PORT,
438 ATA_IDX_INB(ch, ATA_BMCMD_PORT) & ~ATA_BMCMD_START_STOP);
439 ATA_IDX_OUTB(ch, ATA_BMSTAT_PORT, ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR);
440 ch->dma.flags &= ~ATA_DMA_ACTIVE;
445 ata_promise_dmareset(device_t dev)
447 struct ata_channel *ch = device_get_softc(dev);
449 ATA_IDX_OUTB(ch, ATA_BMCMD_PORT,
450 ATA_IDX_INB(ch, ATA_BMCMD_PORT) & ~ATA_BMCMD_START_STOP);
451 ATA_IDX_OUTB(ch, ATA_BMSTAT_PORT, ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR);
452 ch->flags &= ~ATA_DMA_ACTIVE;
456 ata_promise_setmode(device_t dev, int target, int mode)
458 device_t parent = device_get_parent(dev);
459 struct ata_pci_controller *ctlr = device_get_softc(parent);
460 struct ata_channel *ch = device_get_softc(dev);
461 int devno = (ch->unit << 1) + target;
462 static const uint32_t timings[][2] = {
463 /* PR_OLD PR_NEW mode */
464 { 0x004ff329, 0x004fff2f }, /* PIO 0 */
465 { 0x004fec25, 0x004ff82a }, /* PIO 1 */
466 { 0x004fe823, 0x004ff026 }, /* PIO 2 */
467 { 0x004fe622, 0x004fec24 }, /* PIO 3 */
468 { 0x004fe421, 0x004fe822 }, /* PIO 4 */
469 { 0x004567f3, 0x004acef6 }, /* MWDMA 0 */
470 { 0x004467f3, 0x0048cef6 }, /* MWDMA 1 */
471 { 0x004367f3, 0x0046cef6 }, /* MWDMA 2 */
472 { 0x004367f3, 0x0046cef6 }, /* UDMA 0 */
473 { 0x004247f3, 0x00448ef6 }, /* UDMA 1 */
474 { 0x004127f3, 0x00436ef6 }, /* UDMA 2 */
475 { 0, 0x00424ef6 }, /* UDMA 3 */
476 { 0, 0x004127f3 }, /* UDMA 4 */
477 { 0, 0x004127f3 } /* UDMA 5 */
480 mode = min(mode, ctlr->chip->max_dma);
482 switch (ctlr->chip->cfg1) {
485 if (ata_dma_check_80pin && mode > ATA_UDMA2 &&
486 (pci_read_config(parent, 0x50, 2) &
487 (ch->unit ? 1 << 11 : 1 << 10))) {
488 ata_print_cable(dev, "controller");
494 ATA_IDX_OUTB(ch, ATA_BMDEVSPEC_0, 0x0b);
495 if (ata_dma_check_80pin && mode > ATA_UDMA2 &&
496 ATA_IDX_INB(ch, ATA_BMDEVSPEC_1) & 0x04) {
497 ata_print_cable(dev, "controller");
503 if (ata_dma_check_80pin && mode > ATA_UDMA2 &&
504 (ATA_INL(ctlr->r_res2,
505 (ctlr->chip->cfg2 & PR_SX4X ? 0x000c0260 : 0x0260) +
506 (ch->unit << 7)) & 0x01000000)) {
507 ata_print_cable(dev, "controller");
513 if (ctlr->chip->cfg1 < PR_TX)
514 pci_write_config(parent, 0x60 + (devno << 2),
515 timings[ata_mode2idx(mode)][ctlr->chip->cfg1], 4);
520 ata_promise_tx2_ch_attach(device_t dev)
522 struct ata_channel *ch = device_get_softc(dev);
524 if (ata_pci_ch_attach(dev))
527 ch->hw.status = ata_promise_tx2_status;
528 ch->flags |= ATA_CHECKS_CABLE;
533 ata_promise_tx2_status(device_t dev)
535 struct ata_channel *ch = device_get_softc(dev);
537 ATA_IDX_OUTB(ch, ATA_BMDEVSPEC_0, 0x0b);
538 if (ATA_IDX_INB(ch, ATA_BMDEVSPEC_1) & 0x20) {
539 return ata_pci_status(dev);
545 ata_promise_mio_ch_attach(device_t dev)
547 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
548 struct ata_channel *ch = device_get_softc(dev);
549 int offset = (ctlr->chip->cfg2 & PR_SX4X) ? 0x000c0000 : 0;
552 ata_promise_mio_dmainit(dev);
554 for (i = ATA_DATA; i <= ATA_COMMAND; i++) {
555 ch->r_io[i].res = ctlr->r_res2;
556 ch->r_io[i].offset = offset + 0x0200 + (i << 2) + (ch->unit << 7);
558 ch->r_io[ATA_CONTROL].res = ctlr->r_res2;
559 ch->r_io[ATA_CONTROL].offset = offset + 0x0238 + (ch->unit << 7);
560 ch->r_io[ATA_IDX_ADDR].res = ctlr->r_res2;
561 ata_default_registers(dev);
562 if ((ctlr->chip->cfg2 & (PR_SATA | PR_SATA2)) ||
563 ((ctlr->chip->cfg2 & (PR_CMBO | PR_CMBO2)) && ch->unit < 2)) {
564 ch->r_io[ATA_SSTATUS].res = ctlr->r_res2;
565 ch->r_io[ATA_SSTATUS].offset = 0x400 + (ch->unit << 8);
566 ch->r_io[ATA_SERROR].res = ctlr->r_res2;
567 ch->r_io[ATA_SERROR].offset = 0x404 + (ch->unit << 8);
568 ch->r_io[ATA_SCONTROL].res = ctlr->r_res2;
569 ch->r_io[ATA_SCONTROL].offset = 0x408 + (ch->unit << 8);
570 ch->flags |= ATA_NO_SLAVE;
571 ch->flags |= ATA_SATA;
573 ch->flags |= ATA_USE_16BIT;
574 ch->flags |= ATA_CHECKS_CABLE;
577 if (ctlr->chip->cfg2 & PR_SX4X) {
578 ch->hw.command = ata_promise_sx4_command;
581 ch->hw.command = ata_promise_mio_command;
582 ch->hw.status = ata_promise_mio_status;
583 ch->hw.softreset = ata_promise_mio_softreset;
584 ch->hw.pm_read = ata_promise_mio_pm_read;
585 ch->hw.pm_write = ata_promise_mio_pm_write;
591 ata_promise_mio_ch_detach(device_t dev)
599 ata_promise_mio_intr(void *data)
601 struct ata_pci_controller *ctlr = data;
602 struct ata_channel *ch;
607 * since reading interrupt status register on early "mio" chips
608 * clears the status bits we cannot read it for each channel later on
609 * in the generic interrupt routine.
611 vector = ATA_INL(ctlr->r_res2, 0x040);
612 ATA_OUTL(ctlr->r_res2, 0x040, vector);
613 ctlr->chipset_data = (void *)(uintptr_t)vector;
615 for (unit = 0; unit < ctlr->channels; unit++) {
616 if ((ch = ctlr->interrupt[unit].argument))
617 ctlr->interrupt[unit].function(ch);
620 ctlr->chipset_data = (void *)(uintptr_t)0xffffffff;
624 ata_promise_mio_status(device_t dev)
626 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
627 struct ata_channel *ch = device_get_softc(dev);
628 u_int32_t stat_reg, vector, status;
630 switch (ctlr->chip->cfg2) {
643 /* read and acknowledge interrupt */
644 vector = (uint32_t)(uintptr_t)ctlr->chipset_data;
646 /* read and clear interface status */
647 status = ATA_INL(ctlr->r_res2, stat_reg);
648 ATA_OUTL(ctlr->r_res2, stat_reg, status & (0x00000011 << ch->unit));
650 /* check for and handle disconnect events */
651 if (status & (0x00000001 << ch->unit)) {
653 device_printf(dev, "DISCONNECT requested\n");
654 taskqueue_enqueue(taskqueue_thread, &ch->conntask);
657 /* check for and handle connect events */
658 if (status & (0x00000010 << ch->unit)) {
660 device_printf(dev, "CONNECT requested\n");
661 taskqueue_enqueue(taskqueue_thread, &ch->conntask);
664 /* do we have any device action ? */
665 return (vector & (1 << (ch->unit + 1)));
669 ata_promise_mio_command(struct ata_request *request)
671 struct ata_pci_controller *ctlr=device_get_softc(device_get_parent(request->parent));
672 struct ata_channel *ch = device_get_softc(request->parent);
674 u_int32_t *wordp = (u_int32_t *)ch->dma.work;
676 ATA_OUTL(ctlr->r_res2, (ch->unit + 1) << 2, 0x00000001);
678 if ((ctlr->chip->cfg2 == PR_SATA2) ||
679 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2))) {
680 /* set portmultiplier port */
681 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), request->unit & 0x0f);
684 /* XXX SOS add ATAPI commands support later */
685 switch (request->u.ata.command) {
687 return ata_generic_command(request);
691 wordp[0] = htole32(0x04 | ((ch->unit + 1) << 16) | (0x00 << 24));
695 case ATA_WRITE_DMA48:
696 wordp[0] = htole32(0x00 | ((ch->unit + 1) << 16) | (0x00 << 24));
699 wordp[1] = htole32(request->dma->sg_bus);
701 ata_promise_apkt((u_int8_t*)wordp, request);
703 ATA_OUTL(ctlr->r_res2, 0x0240 + (ch->unit << 7), ch->dma.work_bus);
708 ata_promise_mio_reset(device_t dev)
710 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
711 struct ata_channel *ch = device_get_softc(dev);
712 struct ata_promise_sx4 *hpktp;
714 switch (ctlr->chip->cfg2) {
717 /* softreset channel ATA module */
718 hpktp = ctlr->chipset_data;
719 ATA_OUTL(ctlr->r_res2, 0xc0260 + (ch->unit << 7), ch->unit + 1);
721 ATA_OUTL(ctlr->r_res2, 0xc0260 + (ch->unit << 7),
722 (ATA_INL(ctlr->r_res2, 0xc0260 + (ch->unit << 7)) &
723 ~0x00003f9f) | (ch->unit + 1));
725 /* softreset HOST module */ /* XXX SOS what about other outstandings */
726 mtx_lock(&hpktp->mtx);
727 ATA_OUTL(ctlr->r_res2, 0xc012c,
728 (ATA_INL(ctlr->r_res2, 0xc012c) & ~0x00000f9f) | (1 << 11));
730 ATA_OUTL(ctlr->r_res2, 0xc012c,
731 (ATA_INL(ctlr->r_res2, 0xc012c) & ~0x00000f9f));
733 mtx_unlock(&hpktp->mtx);
734 ata_generic_reset(dev);
740 if ((ctlr->chip->cfg2 == PR_SATA) ||
741 ((ctlr->chip->cfg2 == PR_CMBO) && (ch->unit < 2))) {
743 /* mask plug/unplug intr */
744 ATA_OUTL(ctlr->r_res2, 0x06c, (0x00110000 << ch->unit));
747 /* softreset channels ATA module */
748 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7), (1 << 11));
750 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7),
751 (ATA_INL(ctlr->r_res2, 0x0260 + (ch->unit << 7)) &
752 ~0x00003f9f) | (ch->unit + 1));
754 if ((ctlr->chip->cfg2 == PR_SATA) ||
755 ((ctlr->chip->cfg2 == PR_CMBO) && (ch->unit < 2))) {
757 if (ata_sata_phy_reset(dev, -1, 1))
758 ata_generic_reset(dev);
762 /* reset and enable plug/unplug intr */
763 ATA_OUTL(ctlr->r_res2, 0x06c, (0x00000011 << ch->unit));
766 ata_generic_reset(dev);
771 if ((ctlr->chip->cfg2 == PR_SATA2) ||
772 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2))) {
773 /* set portmultiplier port */
774 //ATA_OUTL(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x0f);
776 /* mask plug/unplug intr */
777 ATA_OUTL(ctlr->r_res2, 0x060, (0x00110000 << ch->unit));
780 /* softreset channels ATA module */
781 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7), (1 << 11));
783 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7),
784 (ATA_INL(ctlr->r_res2, 0x0260 + (ch->unit << 7)) &
785 ~0x00003f9f) | (ch->unit + 1));
787 if ((ctlr->chip->cfg2 == PR_SATA2) ||
788 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2))) {
790 /* set PHY mode to "improved" */
791 ATA_OUTL(ctlr->r_res2, 0x414 + (ch->unit << 8),
792 (ATA_INL(ctlr->r_res2, 0x414 + (ch->unit << 8)) &
793 ~0x00000003) | 0x00000001);
795 if (ata_sata_phy_reset(dev, -1, 1)) {
796 u_int32_t signature = ch->hw.softreset(dev, ATA_PM);
799 device_printf(dev, "SIGNATURE: %08x\n", signature);
801 switch (signature >> 16) {
803 ch->devices = ATA_ATA_MASTER;
806 ch->devices = ATA_PORTMULTIPLIER;
807 ata_pm_identify(dev);
810 ch->devices = ATA_ATAPI_MASTER;
812 default: /* SOS XXX */
815 "No signature, assuming disk device\n");
816 ch->devices = ATA_ATA_MASTER;
819 device_printf(dev, "promise_mio_reset devices=%08x\n",
825 /* reset and enable plug/unplug intr */
826 ATA_OUTL(ctlr->r_res2, 0x060, (0x00000011 << ch->unit));
828 ///* set portmultiplier port */
829 ATA_OUTL(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x00);
832 ata_generic_reset(dev);
839 ata_promise_mio_pm_read(device_t dev, int port, int reg, u_int32_t *result)
841 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
842 struct ata_channel *ch = device_get_softc(dev);
846 *result = ATA_IDX_INL(ch, reg);
864 /* set portmultiplier port */
865 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x0f);
867 ATA_IDX_OUTB(ch, ATA_FEATURE, reg);
868 ATA_IDX_OUTB(ch, ATA_DRIVE, port);
870 ATA_IDX_OUTB(ch, ATA_COMMAND, ATA_READ_PM);
872 while (timeout < 1000000) {
873 u_int8_t status = ATA_IDX_INB(ch, ATA_STATUS);
874 if (!(status & ATA_S_BUSY))
879 if (timeout >= 1000000)
882 *result = ATA_IDX_INB(ch, ATA_COUNT) |
883 (ATA_IDX_INB(ch, ATA_SECTOR) << 8) |
884 (ATA_IDX_INB(ch, ATA_CYL_LSB) << 16) |
885 (ATA_IDX_INB(ch, ATA_CYL_MSB) << 24);
890 ata_promise_mio_pm_write(device_t dev, int port, int reg, u_int32_t value)
892 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
893 struct ata_channel *ch = device_get_softc(dev);
897 ATA_IDX_OUTL(ch, reg, value);
915 /* set portmultiplier port */
916 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x0f);
918 ATA_IDX_OUTB(ch, ATA_FEATURE, reg);
919 ATA_IDX_OUTB(ch, ATA_DRIVE, port);
920 ATA_IDX_OUTB(ch, ATA_COUNT, value & 0xff);
921 ATA_IDX_OUTB(ch, ATA_SECTOR, (value >> 8) & 0xff);
922 ATA_IDX_OUTB(ch, ATA_CYL_LSB, (value >> 16) & 0xff);
923 ATA_IDX_OUTB(ch, ATA_CYL_MSB, (value >> 24) & 0xff);
925 ATA_IDX_OUTB(ch, ATA_COMMAND, ATA_WRITE_PM);
927 while (timeout < 1000000) {
928 u_int8_t status = ATA_IDX_INB(ch, ATA_STATUS);
929 if (!(status & ATA_S_BUSY))
934 if (timeout >= 1000000)
937 return ATA_IDX_INB(ch, ATA_ERROR);
940 /* must be called with ATA channel locked and state_mtx held */
942 ata_promise_mio_softreset(device_t dev, int port)
944 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
945 struct ata_channel *ch = device_get_softc(dev);
948 /* set portmultiplier port */
949 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), port & 0x0f);
951 /* softreset device on this channel */
952 ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_D_LBA | ATA_DEV(ATA_MASTER));
954 ATA_IDX_OUTB(ch, ATA_CONTROL, ATA_A_IDS | ATA_A_RESET);
956 ATA_IDX_OUTB(ch, ATA_CONTROL, ATA_A_IDS);
958 ATA_IDX_INB(ch, ATA_ERROR);
960 /* wait for BUSY to go inactive */
961 for (timeout = 0; timeout < 100; timeout++) {
962 u_int8_t /* err, */ stat;
964 /* err = */ ATA_IDX_INB(ch, ATA_ERROR);
965 stat = ATA_IDX_INB(ch, ATA_STATUS);
967 //if (stat == err && timeout > (stat & ATA_S_BUSY ? 100 : 10))
970 if (!(stat & ATA_S_BUSY)) {
971 //if ((err & 0x7f) == ATA_E_ILI) {
972 return ATA_IDX_INB(ch, ATA_COUNT) |
973 (ATA_IDX_INB(ch, ATA_SECTOR) << 8) |
974 (ATA_IDX_INB(ch, ATA_CYL_LSB) << 16) |
975 (ATA_IDX_INB(ch, ATA_CYL_MSB) << 24);
977 //else if (stat & 0x0f) {
978 //stat |= ATA_S_BUSY;
982 if (!(stat & ATA_S_BUSY) || (stat == 0xff && timeout > 10))
990 ata_promise_mio_dmainit(device_t dev)
992 struct ata_channel *ch = device_get_softc(dev);
994 /* note start and stop are not used here */
995 ch->dma.setprd = ata_promise_mio_setprd;
996 ch->dma.max_iosize = 65536;
1000 #define MAXLASTSGSIZE (32 * sizeof(u_int32_t))
1002 ata_promise_mio_setprd(void *xsc, bus_dma_segment_t *segs, int nsegs, int error)
1004 struct ata_dmasetprd_args *args = xsc;
1005 struct ata_dma_prdentry *prd = args->dmatab;
1008 if ((args->error = error))
1011 for (i = 0; i < nsegs; i++) {
1012 prd[i].addr = htole32(segs[i].ds_addr);
1013 prd[i].count = htole32(segs[i].ds_len);
1015 if (segs[i - 1].ds_len > MAXLASTSGSIZE) {
1016 //printf("split last SG element of %u\n", segs[i - 1].ds_len);
1017 prd[i - 1].count = htole32(segs[i - 1].ds_len - MAXLASTSGSIZE);
1018 prd[i].count = htole32(MAXLASTSGSIZE);
1019 prd[i].addr = htole32(segs[i - 1].ds_addr +
1020 (segs[i - 1].ds_len - MAXLASTSGSIZE));
1024 prd[i - 1].count |= htole32(ATA_DMA_EOT);
1025 KASSERT(nsegs <= ATA_DMA_ENTRIES, ("too many DMA segment entries\n"));
1026 args->nsegs = nsegs;
1030 ata_promise_mio_setmode(device_t dev, int target, int mode)
1032 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
1033 struct ata_channel *ch = device_get_softc(dev);
1035 if ( (ctlr->chip->cfg2 == PR_SATA) ||
1036 ((ctlr->chip->cfg2 == PR_CMBO) && (ch->unit < 2)) ||
1037 (ctlr->chip->cfg2 == PR_SATA2) ||
1038 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2)))
1039 mode = ata_sata_setmode(dev, target, mode);
1041 mode = ata_promise_setmode(dev, target, mode);
1046 ata_promise_mio_getrev(device_t dev, int target)
1048 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
1049 struct ata_channel *ch = device_get_softc(dev);
1051 if ( (ctlr->chip->cfg2 == PR_SATA) ||
1052 ((ctlr->chip->cfg2 == PR_CMBO) && (ch->unit < 2)) ||
1053 (ctlr->chip->cfg2 == PR_SATA2) ||
1054 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2)))
1055 return (ata_sata_getrev(dev, target));
1061 ata_promise_sx4_intr(void *data)
1063 struct ata_pci_controller *ctlr = data;
1064 struct ata_channel *ch;
1065 u_int32_t vector = ATA_INL(ctlr->r_res2, 0x000c0480);
1068 for (unit = 0; unit < ctlr->channels; unit++) {
1069 if (vector & (1 << (unit + 1)))
1070 if ((ch = ctlr->interrupt[unit].argument))
1071 ctlr->interrupt[unit].function(ch);
1072 if (vector & (1 << (unit + 5)))
1073 if ((ch = ctlr->interrupt[unit].argument))
1074 ata_promise_queue_hpkt(ctlr,
1075 htole32((ch->unit * ATA_PDC_CHN_OFFSET) +
1076 ATA_PDC_HPKT_OFFSET));
1077 if (vector & (1 << (unit + 9))) {
1078 ata_promise_next_hpkt(ctlr);
1079 if ((ch = ctlr->interrupt[unit].argument))
1080 ctlr->interrupt[unit].function(ch);
1082 if (vector & (1 << (unit + 13))) {
1083 ata_promise_next_hpkt(ctlr);
1084 if ((ch = ctlr->interrupt[unit].argument))
1085 ATA_OUTL(ctlr->r_res2, 0x000c0240 + (ch->unit << 7),
1086 htole32((ch->unit * ATA_PDC_CHN_OFFSET) +
1087 ATA_PDC_APKT_OFFSET));
1093 ata_promise_sx4_command(struct ata_request *request)
1095 device_t gparent = device_get_parent(request->parent);
1096 struct ata_pci_controller *ctlr = device_get_softc(gparent);
1097 struct ata_channel *ch = device_get_softc(request->parent);
1098 struct ata_dma_prdentry *prd;
1099 caddr_t window = rman_get_virtual(ctlr->r_res1);
1101 int i, idx, length = 0;
1103 /* XXX SOS add ATAPI commands support later */
1104 switch (request->u.ata.command) {
1109 case ATA_ATA_IDENTIFY:
1113 case ATA_READ_MUL48:
1117 case ATA_WRITE_MUL48:
1118 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit + 1) << 2), 0x00000001);
1119 return ata_generic_command(request);
1121 case ATA_SETFEATURES:
1122 case ATA_FLUSHCACHE:
1123 case ATA_FLUSHCACHE48:
1126 wordp = (u_int32_t *)
1127 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_APKT_OFFSET);
1128 wordp[0] = htole32(0x08 | ((ch->unit + 1)<<16) | (0x00 << 24));
1131 ata_promise_apkt((u_int8_t *)wordp, request);
1132 ATA_OUTL(ctlr->r_res2, 0x000c0484, 0x00000001);
1133 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit + 1) << 2), 0x00000001);
1134 ATA_OUTL(ctlr->r_res2, 0x000c0240 + (ch->unit << 7),
1135 htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_APKT_OFFSET));
1139 case ATA_READ_DMA48:
1141 case ATA_WRITE_DMA48:
1142 prd = request->dma->sg;
1143 wordp = (u_int32_t *)
1144 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_HSG_OFFSET);
1147 wordp[idx++] = prd[i].addr;
1148 wordp[idx++] = prd[i].count;
1149 length += (prd[i].count & ~ATA_DMA_EOT);
1150 } while (!(prd[i++].count & ATA_DMA_EOT));
1152 wordp = (u_int32_t *)
1153 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_LSG_OFFSET);
1154 wordp[0] = htole32((ch->unit * ATA_PDC_BUF_OFFSET) + ATA_PDC_BUF_BASE);
1155 wordp[1] = htole32(request->bytecount | ATA_DMA_EOT);
1157 wordp = (u_int32_t *)
1158 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_ASG_OFFSET);
1159 wordp[0] = htole32((ch->unit * ATA_PDC_BUF_OFFSET) + ATA_PDC_BUF_BASE);
1160 wordp[1] = htole32(request->bytecount | ATA_DMA_EOT);
1162 wordp = (u_int32_t *)
1163 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_HPKT_OFFSET);
1164 if (request->flags & ATA_R_READ)
1165 wordp[0] = htole32(0x14 | ((ch->unit+9)<<16) | ((ch->unit+5)<<24));
1166 if (request->flags & ATA_R_WRITE)
1167 wordp[0] = htole32(0x00 | ((ch->unit+13)<<16) | (0x00<<24));
1168 wordp[1] = htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_HSG_OFFSET);
1169 wordp[2] = htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_LSG_OFFSET);
1172 wordp = (u_int32_t *)
1173 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_APKT_OFFSET);
1174 if (request->flags & ATA_R_READ)
1175 wordp[0] = htole32(0x04 | ((ch->unit+5)<<16) | (0x00<<24));
1176 if (request->flags & ATA_R_WRITE)
1177 wordp[0] = htole32(0x10 | ((ch->unit+1)<<16) | ((ch->unit+13)<<24));
1178 wordp[1] = htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_ASG_OFFSET);
1180 ata_promise_apkt((u_int8_t *)wordp, request);
1181 ATA_OUTL(ctlr->r_res2, 0x000c0484, 0x00000001);
1183 if (request->flags & ATA_R_READ) {
1184 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+5)<<2), 0x00000001);
1185 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+9)<<2), 0x00000001);
1186 ATA_OUTL(ctlr->r_res2, 0x000c0240 + (ch->unit << 7),
1187 htole32((ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_APKT_OFFSET));
1189 if (request->flags & ATA_R_WRITE) {
1190 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+1)<<2), 0x00000001);
1191 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+13)<<2), 0x00000001);
1192 ata_promise_queue_hpkt(ctlr,
1193 htole32((ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_HPKT_OFFSET));
1200 ata_promise_apkt(u_int8_t *bytep, struct ata_request *request)
1204 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_PDC_WAIT_NBUSY|ATA_DRIVE;
1205 bytep[i++] = ATA_D_IBM | ATA_D_LBA | ATA_DEV(request->unit);
1206 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_CTL;
1207 bytep[i++] = ATA_A_4BIT;
1209 if (request->flags & ATA_R_48BIT) {
1210 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_FEATURE;
1211 bytep[i++] = request->u.ata.feature >> 8;
1212 bytep[i++] = request->u.ata.feature;
1213 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_COUNT;
1214 bytep[i++] = request->u.ata.count >> 8;
1215 bytep[i++] = request->u.ata.count;
1216 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_SECTOR;
1217 bytep[i++] = request->u.ata.lba >> 24;
1218 bytep[i++] = request->u.ata.lba;
1219 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_CYL_LSB;
1220 bytep[i++] = request->u.ata.lba >> 32;
1221 bytep[i++] = request->u.ata.lba >> 8;
1222 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_CYL_MSB;
1223 bytep[i++] = request->u.ata.lba >> 40;
1224 bytep[i++] = request->u.ata.lba >> 16;
1225 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_DRIVE;
1226 bytep[i++] = ATA_D_LBA | ATA_DEV(request->unit);
1229 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_FEATURE;
1230 bytep[i++] = request->u.ata.feature;
1231 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_COUNT;
1232 bytep[i++] = request->u.ata.count;
1233 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_SECTOR;
1234 bytep[i++] = request->u.ata.lba;
1235 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_CYL_LSB;
1236 bytep[i++] = request->u.ata.lba >> 8;
1237 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_CYL_MSB;
1238 bytep[i++] = request->u.ata.lba >> 16;
1239 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_DRIVE;
1240 bytep[i++] = ATA_D_LBA | ATA_D_IBM | ATA_DEV(request->unit) |
1241 ((request->u.ata.lba >> 24)&0xf);
1243 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_END | ATA_COMMAND;
1244 bytep[i++] = request->u.ata.command;
1249 ata_promise_queue_hpkt(struct ata_pci_controller *ctlr, u_int32_t hpkt)
1251 struct ata_promise_sx4 *hpktp = ctlr->chipset_data;
1253 mtx_lock(&hpktp->mtx);
1255 struct host_packet *hp =
1256 malloc(sizeof(struct host_packet), M_TEMP, M_NOWAIT | M_ZERO);
1258 TAILQ_INSERT_TAIL(&hpktp->queue, hp, chain);
1262 ATA_OUTL(ctlr->r_res2, 0x000c0100, hpkt);
1264 mtx_unlock(&hpktp->mtx);
1268 ata_promise_next_hpkt(struct ata_pci_controller *ctlr)
1270 struct ata_promise_sx4 *hpktp = ctlr->chipset_data;
1271 struct host_packet *hp;
1273 mtx_lock(&hpktp->mtx);
1274 if ((hp = TAILQ_FIRST(&hpktp->queue))) {
1275 TAILQ_REMOVE(&hpktp->queue, hp, chain);
1276 ATA_OUTL(ctlr->r_res2, 0x000c0100, hp->addr);
1281 mtx_unlock(&hpktp->mtx);
1284 ATA_DECLARE_DRIVER(ata_promise);