2 * Copyright (c) 1998 - 2008 Søren Schmidt <sos@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/module.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
37 #include <sys/endian.h>
38 #include <sys/malloc.h>
40 #include <sys/mutex.h>
42 #include <sys/taskqueue.h>
44 #include <machine/stdarg.h>
45 #include <machine/resource.h>
46 #include <machine/bus.h>
48 #include <dev/pci/pcivar.h>
49 #include <dev/pci/pcireg.h>
50 #include <dev/ata/ata-all.h>
51 #include <dev/ata/ata-pci.h>
54 /* local prototypes */
55 static int ata_promise_chipinit(device_t dev);
56 static int ata_promise_ch_attach(device_t dev);
57 static int ata_promise_status(device_t dev);
58 static int ata_promise_dmastart(struct ata_request *request);
59 static int ata_promise_dmastop(struct ata_request *request);
60 static void ata_promise_dmareset(device_t dev);
61 static int ata_promise_setmode(device_t dev, int target, int mode);
62 static int ata_promise_tx2_ch_attach(device_t dev);
63 static int ata_promise_tx2_status(device_t dev);
64 static int ata_promise_mio_ch_attach(device_t dev);
65 static int ata_promise_mio_ch_detach(device_t dev);
66 static void ata_promise_mio_intr(void *data);
67 static int ata_promise_mio_status(device_t dev);
68 static int ata_promise_mio_command(struct ata_request *request);
69 static void ata_promise_mio_reset(device_t dev);
70 static int ata_promise_mio_pm_read(device_t dev, int port, int reg, u_int32_t *result);
71 static int ata_promise_mio_pm_write(device_t dev, int port, int reg, u_int32_t result);
72 static u_int32_t ata_promise_mio_softreset(device_t dev, int port);
73 static void ata_promise_mio_dmainit(device_t dev);
74 static void ata_promise_mio_setprd(void *xsc, bus_dma_segment_t *segs, int nsegs, int error);
75 static int ata_promise_mio_setmode(device_t dev, int target, int mode);
76 static int ata_promise_mio_getrev(device_t dev, int target);
77 static void ata_promise_sx4_intr(void *data);
78 static int ata_promise_sx4_command(struct ata_request *request);
79 static int ata_promise_apkt(u_int8_t *bytep, struct ata_request *request);
80 static void ata_promise_queue_hpkt(struct ata_pci_controller *ctlr, u_int32_t hpkt);
81 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 struct ata_chip_id *idx;
134 static 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 long 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_DEFAULT);
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)))
253 ctlr->r_type2 = SYS_RES_MEMORY;
254 ctlr->r_rid2 = PCIR_BAR(3);
255 if (!(ctlr->r_res2 = bus_alloc_resource_any(dev, ctlr->r_type2,
256 &ctlr->r_rid2, RF_ACTIVE)))
259 if (ctlr->chip->cfg2 == PR_SX4X) {
260 struct ata_promise_sx4 *hpkt;
261 u_int32_t dimm = ATA_INL(ctlr->r_res2, 0x000c0080);
263 if (bus_teardown_intr(dev, ctlr->r_irq, ctlr->handle) ||
264 bus_setup_intr(dev, ctlr->r_irq, ATA_INTR_FLAGS, NULL,
265 ata_promise_sx4_intr, ctlr, &ctlr->handle)) {
266 device_printf(dev, "unable to setup interrupt\n");
270 /* print info about cache memory */
271 device_printf(dev, "DIMM size %dMB @ 0x%08x%s\n",
272 (((dimm >> 16) & 0xff)-((dimm >> 24) & 0xff)+1) << 4,
273 ((dimm >> 24) & 0xff),
274 ATA_INL(ctlr->r_res2, 0x000c0088) & (1<<16) ?
275 " ECC enabled" : "" );
277 /* adjust cache memory parameters */
278 ATA_OUTL(ctlr->r_res2, 0x000c000c,
279 (ATA_INL(ctlr->r_res2, 0x000c000c) & 0xffff0000));
281 /* setup host packet controls */
282 hpkt = malloc(sizeof(struct ata_promise_sx4),
283 M_TEMP, M_NOWAIT | M_ZERO);
284 mtx_init(&hpkt->mtx, "ATA promise HPKT lock", NULL, MTX_DEF);
285 TAILQ_INIT(&hpkt->queue);
287 ctlr->chipset_data = hpkt;
288 ctlr->ch_attach = ata_promise_mio_ch_attach;
289 ctlr->ch_detach = ata_promise_mio_ch_detach;
290 ctlr->reset = ata_promise_mio_reset;
291 ctlr->setmode = ata_promise_setmode;
296 /* mio type controllers need an interrupt intercept */
297 if (bus_teardown_intr(dev, ctlr->r_irq, ctlr->handle) ||
298 bus_setup_intr(dev, ctlr->r_irq, ATA_INTR_FLAGS, NULL,
299 ata_promise_mio_intr, ctlr, &ctlr->handle)) {
300 device_printf(dev, "unable to setup interrupt\n");
304 switch (ctlr->chip->cfg2) {
306 ctlr->channels = ((ATA_INL(ctlr->r_res2, 0x48) & 0x01) > 0) +
307 ((ATA_INL(ctlr->r_res2, 0x48) & 0x02) > 0) + 2;
329 /* prime fake interrupt register */
330 ctlr->chipset_data = (void *)(uintptr_t)0xffffffff;
332 /* clear SATA status and unmask interrupts */
333 ATA_OUTL(ctlr->r_res2, stat_reg, 0x000000ff);
335 /* enable "long burst length" on gen2 chips */
336 if ((ctlr->chip->cfg2 == PR_SATA2) || (ctlr->chip->cfg2 == PR_CMBO2))
337 ATA_OUTL(ctlr->r_res2, 0x44, ATA_INL(ctlr->r_res2, 0x44) | 0x2000);
339 ctlr->ch_attach = ata_promise_mio_ch_attach;
340 ctlr->ch_detach = ata_promise_mio_ch_detach;
341 ctlr->reset = ata_promise_mio_reset;
342 ctlr->setmode = ata_promise_mio_setmode;
343 ctlr->getrev = ata_promise_mio_getrev;
350 bus_release_resource(dev, ctlr->r_type2, ctlr->r_rid2, ctlr->r_res2);
352 bus_release_resource(dev, ctlr->r_type1, ctlr->r_rid1, ctlr->r_res1);
357 ata_promise_ch_attach(device_t dev)
359 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
360 struct ata_channel *ch = device_get_softc(dev);
362 if (ata_pci_ch_attach(dev))
365 if (ctlr->chip->cfg1 == PR_NEW) {
366 ch->dma.start = ata_promise_dmastart;
367 ch->dma.stop = ata_promise_dmastop;
368 ch->dma.reset = ata_promise_dmareset;
371 ch->hw.status = ata_promise_status;
372 ch->flags |= ATA_NO_ATAPI_DMA;
373 ch->flags |= ATA_CHECKS_CABLE;
378 ata_promise_status(device_t dev)
380 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
381 struct ata_channel *ch = device_get_softc(dev);
383 if (ATA_INL(ctlr->r_res1, 0x1c) & (ch->unit ? 0x00004000 : 0x00000400)) {
384 return ata_pci_status(dev);
390 ata_promise_dmastart(struct ata_request *request)
392 struct ata_pci_controller *ctlr=device_get_softc(device_get_parent(request->parent));
393 struct ata_channel *ch = device_get_softc(request->parent);
395 if (request->flags & ATA_R_48BIT) {
396 ATA_OUTB(ctlr->r_res1, 0x11,
397 ATA_INB(ctlr->r_res1, 0x11) | (ch->unit ? 0x08 : 0x02));
398 ATA_OUTL(ctlr->r_res1, ch->unit ? 0x24 : 0x20,
399 ((request->flags & ATA_R_READ) ? 0x05000000 : 0x06000000) |
400 (request->bytecount >> 1));
402 ATA_IDX_OUTB(ch, ATA_BMSTAT_PORT, (ATA_IDX_INB(ch, ATA_BMSTAT_PORT) |
403 (ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR)));
404 ATA_IDX_OUTL(ch, ATA_BMDTP_PORT, request->dma->sg_bus);
405 ATA_IDX_OUTB(ch, ATA_BMCMD_PORT,
406 ((request->flags & ATA_R_READ) ? ATA_BMCMD_WRITE_READ : 0) |
407 ATA_BMCMD_START_STOP);
408 ch->dma.flags |= ATA_DMA_ACTIVE;
413 ata_promise_dmastop(struct ata_request *request)
415 struct ata_pci_controller *ctlr=device_get_softc(device_get_parent(request->parent));
416 struct ata_channel *ch = device_get_softc(request->parent);
419 if (request->flags & ATA_R_48BIT) {
420 ATA_OUTB(ctlr->r_res1, 0x11,
421 ATA_INB(ctlr->r_res1, 0x11) & ~(ch->unit ? 0x08 : 0x02));
422 ATA_OUTL(ctlr->r_res1, ch->unit ? 0x24 : 0x20, 0);
424 error = ATA_IDX_INB(ch, ATA_BMSTAT_PORT);
425 ATA_IDX_OUTB(ch, ATA_BMCMD_PORT,
426 ATA_IDX_INB(ch, ATA_BMCMD_PORT) & ~ATA_BMCMD_START_STOP);
427 ATA_IDX_OUTB(ch, ATA_BMSTAT_PORT, ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR);
428 ch->dma.flags &= ~ATA_DMA_ACTIVE;
433 ata_promise_dmareset(device_t dev)
435 struct ata_channel *ch = device_get_softc(dev);
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->flags &= ~ATA_DMA_ACTIVE;
444 ata_promise_setmode(device_t dev, int target, int mode)
446 device_t parent = device_get_parent(dev);
447 struct ata_pci_controller *ctlr = device_get_softc(parent);
448 struct ata_channel *ch = device_get_softc(dev);
449 int devno = (ch->unit << 1) + target;
450 u_int32_t timings[][2] = {
451 /* PR_OLD PR_NEW mode */
452 { 0x004ff329, 0x004fff2f }, /* PIO 0 */
453 { 0x004fec25, 0x004ff82a }, /* PIO 1 */
454 { 0x004fe823, 0x004ff026 }, /* PIO 2 */
455 { 0x004fe622, 0x004fec24 }, /* PIO 3 */
456 { 0x004fe421, 0x004fe822 }, /* PIO 4 */
457 { 0x004567f3, 0x004acef6 }, /* MWDMA 0 */
458 { 0x004467f3, 0x0048cef6 }, /* MWDMA 1 */
459 { 0x004367f3, 0x0046cef6 }, /* MWDMA 2 */
460 { 0x004367f3, 0x0046cef6 }, /* UDMA 0 */
461 { 0x004247f3, 0x00448ef6 }, /* UDMA 1 */
462 { 0x004127f3, 0x00436ef6 }, /* UDMA 2 */
463 { 0, 0x00424ef6 }, /* UDMA 3 */
464 { 0, 0x004127f3 }, /* UDMA 4 */
465 { 0, 0x004127f3 } /* UDMA 5 */
468 mode = min(mode, ctlr->chip->max_dma);
470 switch (ctlr->chip->cfg1) {
473 if (mode > ATA_UDMA2 && (pci_read_config(parent, 0x50, 2) &
474 (ch->unit ? 1 << 11 : 1 << 10))) {
475 ata_print_cable(dev, "controller");
481 ATA_IDX_OUTB(ch, ATA_BMDEVSPEC_0, 0x0b);
482 if (mode > ATA_UDMA2 &&
483 ATA_IDX_INB(ch, ATA_BMDEVSPEC_1) & 0x04) {
484 ata_print_cable(dev, "controller");
490 if (mode > ATA_UDMA2 &&
491 (ATA_INL(ctlr->r_res2,
492 (ctlr->chip->cfg2 & PR_SX4X ? 0x000c0260 : 0x0260) +
493 (ch->unit << 7)) & 0x01000000)) {
494 ata_print_cable(dev, "controller");
500 if (ctlr->chip->cfg1 < PR_TX)
501 pci_write_config(parent, 0x60 + (devno << 2),
502 timings[ata_mode2idx(mode)][ctlr->chip->cfg1], 4);
507 ata_promise_tx2_ch_attach(device_t dev)
509 struct ata_channel *ch = device_get_softc(dev);
511 if (ata_pci_ch_attach(dev))
514 ch->hw.status = ata_promise_tx2_status;
515 ch->flags |= ATA_CHECKS_CABLE;
520 ata_promise_tx2_status(device_t dev)
522 struct ata_channel *ch = device_get_softc(dev);
524 ATA_IDX_OUTB(ch, ATA_BMDEVSPEC_0, 0x0b);
525 if (ATA_IDX_INB(ch, ATA_BMDEVSPEC_1) & 0x20) {
526 return ata_pci_status(dev);
532 ata_promise_mio_ch_attach(device_t dev)
534 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
535 struct ata_channel *ch = device_get_softc(dev);
536 int offset = (ctlr->chip->cfg2 & PR_SX4X) ? 0x000c0000 : 0;
539 ata_promise_mio_dmainit(dev);
541 for (i = ATA_DATA; i <= ATA_COMMAND; i++) {
542 ch->r_io[i].res = ctlr->r_res2;
543 ch->r_io[i].offset = offset + 0x0200 + (i << 2) + (ch->unit << 7);
545 ch->r_io[ATA_CONTROL].res = ctlr->r_res2;
546 ch->r_io[ATA_CONTROL].offset = offset + 0x0238 + (ch->unit << 7);
547 ch->r_io[ATA_IDX_ADDR].res = ctlr->r_res2;
548 ata_default_registers(dev);
549 if ((ctlr->chip->cfg2 & (PR_SATA | PR_SATA2)) ||
550 ((ctlr->chip->cfg2 & (PR_CMBO | PR_CMBO2)) && ch->unit < 2)) {
551 ch->r_io[ATA_SSTATUS].res = ctlr->r_res2;
552 ch->r_io[ATA_SSTATUS].offset = 0x400 + (ch->unit << 8);
553 ch->r_io[ATA_SERROR].res = ctlr->r_res2;
554 ch->r_io[ATA_SERROR].offset = 0x404 + (ch->unit << 8);
555 ch->r_io[ATA_SCONTROL].res = ctlr->r_res2;
556 ch->r_io[ATA_SCONTROL].offset = 0x408 + (ch->unit << 8);
557 ch->flags |= ATA_NO_SLAVE;
558 ch->flags |= ATA_SATA;
560 ch->flags |= ATA_USE_16BIT;
561 ch->flags |= ATA_CHECKS_CABLE;
564 if (ctlr->chip->cfg2 & PR_SX4X) {
565 ch->hw.command = ata_promise_sx4_command;
568 ch->hw.command = ata_promise_mio_command;
569 ch->hw.status = ata_promise_mio_status;
570 ch->hw.softreset = ata_promise_mio_softreset;
571 ch->hw.pm_read = ata_promise_mio_pm_read;
572 ch->hw.pm_write = ata_promise_mio_pm_write;
578 ata_promise_mio_ch_detach(device_t dev)
586 ata_promise_mio_intr(void *data)
588 struct ata_pci_controller *ctlr = data;
589 struct ata_channel *ch;
594 * since reading interrupt status register on early "mio" chips
595 * clears the status bits we cannot read it for each channel later on
596 * in the generic interrupt routine.
598 vector = ATA_INL(ctlr->r_res2, 0x040);
599 ATA_OUTL(ctlr->r_res2, 0x040, vector);
600 ctlr->chipset_data = (void *)(uintptr_t)vector;
602 for (unit = 0; unit < ctlr->channels; unit++) {
603 if ((ch = ctlr->interrupt[unit].argument))
604 ctlr->interrupt[unit].function(ch);
607 ctlr->chipset_data = (void *)(uintptr_t)0xffffffff;
611 ata_promise_mio_status(device_t dev)
613 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
614 struct ata_channel *ch = device_get_softc(dev);
615 u_int32_t stat_reg, vector, status;
617 switch (ctlr->chip->cfg2) {
630 /* read and acknowledge interrupt */
631 vector = (uint32_t)(uintptr_t)ctlr->chipset_data;
633 /* read and clear interface status */
634 status = ATA_INL(ctlr->r_res2, stat_reg);
635 ATA_OUTL(ctlr->r_res2, stat_reg, status & (0x00000011 << ch->unit));
637 /* check for and handle disconnect events */
638 if (status & (0x00000001 << ch->unit)) {
640 device_printf(dev, "DISCONNECT requested\n");
641 taskqueue_enqueue(taskqueue_thread, &ch->conntask);
644 /* check for and handle connect events */
645 if (status & (0x00000010 << ch->unit)) {
647 device_printf(dev, "CONNECT requested\n");
648 taskqueue_enqueue(taskqueue_thread, &ch->conntask);
651 /* do we have any device action ? */
652 return (vector & (1 << (ch->unit + 1)));
656 ata_promise_mio_command(struct ata_request *request)
658 struct ata_pci_controller *ctlr=device_get_softc(device_get_parent(request->parent));
659 struct ata_channel *ch = device_get_softc(request->parent);
661 u_int32_t *wordp = (u_int32_t *)ch->dma.work;
663 ATA_OUTL(ctlr->r_res2, (ch->unit + 1) << 2, 0x00000001);
665 if ((ctlr->chip->cfg2 == PR_SATA2) ||
666 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2))) {
667 /* set portmultiplier port */
668 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), request->unit & 0x0f);
671 /* XXX SOS add ATAPI commands support later */
672 switch (request->u.ata.command) {
674 return ata_generic_command(request);
678 wordp[0] = htole32(0x04 | ((ch->unit + 1) << 16) | (0x00 << 24));
682 case ATA_WRITE_DMA48:
683 wordp[0] = htole32(0x00 | ((ch->unit + 1) << 16) | (0x00 << 24));
686 wordp[1] = htole32(request->dma->sg_bus);
688 ata_promise_apkt((u_int8_t*)wordp, request);
690 ATA_OUTL(ctlr->r_res2, 0x0240 + (ch->unit << 7), ch->dma.work_bus);
695 ata_promise_mio_reset(device_t dev)
697 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
698 struct ata_channel *ch = device_get_softc(dev);
699 struct ata_promise_sx4 *hpktp;
701 switch (ctlr->chip->cfg2) {
704 /* softreset channel ATA module */
705 hpktp = ctlr->chipset_data;
706 ATA_OUTL(ctlr->r_res2, 0xc0260 + (ch->unit << 7), ch->unit + 1);
708 ATA_OUTL(ctlr->r_res2, 0xc0260 + (ch->unit << 7),
709 (ATA_INL(ctlr->r_res2, 0xc0260 + (ch->unit << 7)) &
710 ~0x00003f9f) | (ch->unit + 1));
712 /* softreset HOST module */ /* XXX SOS what about other outstandings */
713 mtx_lock(&hpktp->mtx);
714 ATA_OUTL(ctlr->r_res2, 0xc012c,
715 (ATA_INL(ctlr->r_res2, 0xc012c) & ~0x00000f9f) | (1 << 11));
717 ATA_OUTL(ctlr->r_res2, 0xc012c,
718 (ATA_INL(ctlr->r_res2, 0xc012c) & ~0x00000f9f));
720 mtx_unlock(&hpktp->mtx);
721 ata_generic_reset(dev);
727 if ((ctlr->chip->cfg2 == PR_SATA) ||
728 ((ctlr->chip->cfg2 == PR_CMBO) && (ch->unit < 2))) {
730 /* mask plug/unplug intr */
731 ATA_OUTL(ctlr->r_res2, 0x06c, (0x00110000 << ch->unit));
734 /* softreset channels ATA module */
735 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7), (1 << 11));
737 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7),
738 (ATA_INL(ctlr->r_res2, 0x0260 + (ch->unit << 7)) &
739 ~0x00003f9f) | (ch->unit + 1));
741 if ((ctlr->chip->cfg2 == PR_SATA) ||
742 ((ctlr->chip->cfg2 == PR_CMBO) && (ch->unit < 2))) {
744 if (ata_sata_phy_reset(dev, -1, 1))
745 ata_generic_reset(dev);
747 /* reset and enable plug/unplug intr */
748 ATA_OUTL(ctlr->r_res2, 0x06c, (0x00000011 << ch->unit));
751 ata_generic_reset(dev);
756 if ((ctlr->chip->cfg2 == PR_SATA2) ||
757 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2))) {
758 /* set portmultiplier port */
759 //ATA_OUTL(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x0f);
761 /* mask plug/unplug intr */
762 ATA_OUTL(ctlr->r_res2, 0x060, (0x00110000 << ch->unit));
765 /* softreset channels ATA module */
766 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7), (1 << 11));
768 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7),
769 (ATA_INL(ctlr->r_res2, 0x0260 + (ch->unit << 7)) &
770 ~0x00003f9f) | (ch->unit + 1));
772 if ((ctlr->chip->cfg2 == PR_SATA2) ||
773 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2))) {
775 /* set PHY mode to "improved" */
776 ATA_OUTL(ctlr->r_res2, 0x414 + (ch->unit << 8),
777 (ATA_INL(ctlr->r_res2, 0x414 + (ch->unit << 8)) &
778 ~0x00000003) | 0x00000001);
780 if (ata_sata_phy_reset(dev, -1, 1)) {
781 u_int32_t signature = ch->hw.softreset(dev, ATA_PM);
784 device_printf(dev, "SIGNATURE: %08x\n", signature);
786 switch (signature >> 16) {
788 ch->devices = ATA_ATA_MASTER;
791 ch->devices = ATA_PORTMULTIPLIER;
792 ata_pm_identify(dev);
795 ch->devices = ATA_ATAPI_MASTER;
797 default: /* SOS XXX */
800 "No signature, assuming disk device\n");
801 ch->devices = ATA_ATA_MASTER;
804 device_printf(dev, "promise_mio_reset devices=%08x\n",
810 /* reset and enable plug/unplug intr */
811 ATA_OUTL(ctlr->r_res2, 0x060, (0x00000011 << ch->unit));
813 ///* set portmultiplier port */
814 ATA_OUTL(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x00);
817 ata_generic_reset(dev);
824 ata_promise_mio_pm_read(device_t dev, int port, int reg, u_int32_t *result)
826 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
827 struct ata_channel *ch = device_get_softc(dev);
830 /* set portmultiplier port */
831 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x0f);
833 ATA_IDX_OUTB(ch, ATA_FEATURE, reg);
834 ATA_IDX_OUTB(ch, ATA_DRIVE, port);
836 ATA_IDX_OUTB(ch, ATA_COMMAND, ATA_READ_PM);
838 while (timeout < 1000000) {
839 u_int8_t status = ATA_IDX_INB(ch, ATA_STATUS);
840 if (!(status & ATA_S_BUSY))
845 if (timeout >= 1000000)
848 *result = ATA_IDX_INB(ch, ATA_COUNT) |
849 (ATA_IDX_INB(ch, ATA_SECTOR) << 8) |
850 (ATA_IDX_INB(ch, ATA_CYL_LSB) << 16) |
851 (ATA_IDX_INB(ch, ATA_CYL_MSB) << 24);
856 ata_promise_mio_pm_write(device_t dev, int port, int reg, u_int32_t value)
858 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
859 struct ata_channel *ch = device_get_softc(dev);
862 /* set portmultiplier port */
863 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x0f);
865 ATA_IDX_OUTB(ch, ATA_FEATURE, reg);
866 ATA_IDX_OUTB(ch, ATA_DRIVE, port);
867 ATA_IDX_OUTB(ch, ATA_COUNT, value & 0xff);
868 ATA_IDX_OUTB(ch, ATA_SECTOR, (value >> 8) & 0xff);
869 ATA_IDX_OUTB(ch, ATA_CYL_LSB, (value >> 16) & 0xff);
870 ATA_IDX_OUTB(ch, ATA_CYL_MSB, (value >> 24) & 0xff);
872 ATA_IDX_OUTB(ch, ATA_COMMAND, ATA_WRITE_PM);
874 while (timeout < 1000000) {
875 u_int8_t status = ATA_IDX_INB(ch, ATA_STATUS);
876 if (!(status & ATA_S_BUSY))
881 if (timeout >= 1000000)
884 return ATA_IDX_INB(ch, ATA_ERROR);
887 /* must be called with ATA channel locked and state_mtx held */
889 ata_promise_mio_softreset(device_t dev, int port)
891 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
892 struct ata_channel *ch = device_get_softc(dev);
895 /* set portmultiplier port */
896 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), port & 0x0f);
898 /* softreset device on this channel */
899 ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_D_LBA | ATA_DEV(ATA_MASTER));
901 ATA_IDX_OUTB(ch, ATA_CONTROL, ATA_A_IDS | ATA_A_RESET);
903 ATA_IDX_OUTB(ch, ATA_CONTROL, ATA_A_IDS);
905 ATA_IDX_INB(ch, ATA_ERROR);
907 /* wait for BUSY to go inactive */
908 for (timeout = 0; timeout < 100; timeout++) {
911 err = ATA_IDX_INB(ch, ATA_ERROR);
912 stat = ATA_IDX_INB(ch, ATA_STATUS);
914 //if (stat == err && timeout > (stat & ATA_S_BUSY ? 100 : 10))
917 if (!(stat & ATA_S_BUSY)) {
918 //if ((err & 0x7f) == ATA_E_ILI) {
919 return ATA_IDX_INB(ch, ATA_COUNT) |
920 (ATA_IDX_INB(ch, ATA_SECTOR) << 8) |
921 (ATA_IDX_INB(ch, ATA_CYL_LSB) << 16) |
922 (ATA_IDX_INB(ch, ATA_CYL_MSB) << 24);
924 //else if (stat & 0x0f) {
925 //stat |= ATA_S_BUSY;
929 if (!(stat & ATA_S_BUSY) || (stat == 0xff && timeout > 10))
937 ata_promise_mio_dmainit(device_t dev)
939 struct ata_channel *ch = device_get_softc(dev);
942 /* note start and stop are not used here */
943 ch->dma.setprd = ata_promise_mio_setprd;
944 ch->dma.max_iosize = 65536;
948 #define MAXLASTSGSIZE (32 * sizeof(u_int32_t))
950 ata_promise_mio_setprd(void *xsc, bus_dma_segment_t *segs, int nsegs, int error)
952 struct ata_dmasetprd_args *args = xsc;
953 struct ata_dma_prdentry *prd = args->dmatab;
956 if ((args->error = error))
959 for (i = 0; i < nsegs; i++) {
960 prd[i].addr = htole32(segs[i].ds_addr);
961 prd[i].count = htole32(segs[i].ds_len);
963 if (segs[i - 1].ds_len > MAXLASTSGSIZE) {
964 //printf("split last SG element of %u\n", segs[i - 1].ds_len);
965 prd[i - 1].count = htole32(segs[i - 1].ds_len - MAXLASTSGSIZE);
966 prd[i].count = htole32(MAXLASTSGSIZE);
967 prd[i].addr = htole32(segs[i - 1].ds_addr +
968 (segs[i - 1].ds_len - MAXLASTSGSIZE));
972 prd[i - 1].count |= htole32(ATA_DMA_EOT);
973 KASSERT(nsegs <= ATA_DMA_ENTRIES, ("too many DMA segment entries\n"));
978 ata_promise_mio_setmode(device_t dev, int target, int mode)
980 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
981 struct ata_channel *ch = device_get_softc(dev);
983 if ( (ctlr->chip->cfg2 == PR_SATA) ||
984 ((ctlr->chip->cfg2 == PR_CMBO) && (ch->unit < 2)) ||
985 (ctlr->chip->cfg2 == PR_SATA2) ||
986 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2)))
987 mode = ata_sata_setmode(dev, target, mode);
989 mode = ata_promise_setmode(dev, target, mode);
994 ata_promise_mio_getrev(device_t dev, int target)
996 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
997 struct ata_channel *ch = device_get_softc(dev);
999 if ( (ctlr->chip->cfg2 == PR_SATA) ||
1000 ((ctlr->chip->cfg2 == PR_CMBO) && (ch->unit < 2)) ||
1001 (ctlr->chip->cfg2 == PR_SATA2) ||
1002 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2)))
1003 return (ata_sata_getrev(dev, target));
1009 ata_promise_sx4_intr(void *data)
1011 struct ata_pci_controller *ctlr = data;
1012 struct ata_channel *ch;
1013 u_int32_t vector = ATA_INL(ctlr->r_res2, 0x000c0480);
1016 for (unit = 0; unit < ctlr->channels; unit++) {
1017 if (vector & (1 << (unit + 1)))
1018 if ((ch = ctlr->interrupt[unit].argument))
1019 ctlr->interrupt[unit].function(ch);
1020 if (vector & (1 << (unit + 5)))
1021 if ((ch = ctlr->interrupt[unit].argument))
1022 ata_promise_queue_hpkt(ctlr,
1023 htole32((ch->unit * ATA_PDC_CHN_OFFSET) +
1024 ATA_PDC_HPKT_OFFSET));
1025 if (vector & (1 << (unit + 9))) {
1026 ata_promise_next_hpkt(ctlr);
1027 if ((ch = ctlr->interrupt[unit].argument))
1028 ctlr->interrupt[unit].function(ch);
1030 if (vector & (1 << (unit + 13))) {
1031 ata_promise_next_hpkt(ctlr);
1032 if ((ch = ctlr->interrupt[unit].argument))
1033 ATA_OUTL(ctlr->r_res2, 0x000c0240 + (ch->unit << 7),
1034 htole32((ch->unit * ATA_PDC_CHN_OFFSET) +
1035 ATA_PDC_APKT_OFFSET));
1041 ata_promise_sx4_command(struct ata_request *request)
1043 device_t gparent = device_get_parent(request->parent);
1044 struct ata_pci_controller *ctlr = device_get_softc(gparent);
1045 struct ata_channel *ch = device_get_softc(request->parent);
1046 struct ata_dma_prdentry *prd;
1047 caddr_t window = rman_get_virtual(ctlr->r_res1);
1049 int i, idx, length = 0;
1051 /* XXX SOS add ATAPI commands support later */
1052 switch (request->u.ata.command) {
1057 case ATA_ATA_IDENTIFY:
1061 case ATA_READ_MUL48:
1065 case ATA_WRITE_MUL48:
1066 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit + 1) << 2), 0x00000001);
1067 return ata_generic_command(request);
1069 case ATA_SETFEATURES:
1070 case ATA_FLUSHCACHE:
1071 case ATA_FLUSHCACHE48:
1074 wordp = (u_int32_t *)
1075 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_APKT_OFFSET);
1076 wordp[0] = htole32(0x08 | ((ch->unit + 1)<<16) | (0x00 << 24));
1079 ata_promise_apkt((u_int8_t *)wordp, request);
1080 ATA_OUTL(ctlr->r_res2, 0x000c0484, 0x00000001);
1081 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit + 1) << 2), 0x00000001);
1082 ATA_OUTL(ctlr->r_res2, 0x000c0240 + (ch->unit << 7),
1083 htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_APKT_OFFSET));
1087 case ATA_READ_DMA48:
1089 case ATA_WRITE_DMA48:
1090 prd = request->dma->sg;
1091 wordp = (u_int32_t *)
1092 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_HSG_OFFSET);
1095 wordp[idx++] = prd[i].addr;
1096 wordp[idx++] = prd[i].count;
1097 length += (prd[i].count & ~ATA_DMA_EOT);
1098 } while (!(prd[i++].count & ATA_DMA_EOT));
1100 wordp = (u_int32_t *)
1101 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_LSG_OFFSET);
1102 wordp[0] = htole32((ch->unit * ATA_PDC_BUF_OFFSET) + ATA_PDC_BUF_BASE);
1103 wordp[1] = htole32(request->bytecount | ATA_DMA_EOT);
1105 wordp = (u_int32_t *)
1106 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_ASG_OFFSET);
1107 wordp[0] = htole32((ch->unit * ATA_PDC_BUF_OFFSET) + ATA_PDC_BUF_BASE);
1108 wordp[1] = htole32(request->bytecount | ATA_DMA_EOT);
1110 wordp = (u_int32_t *)
1111 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_HPKT_OFFSET);
1112 if (request->flags & ATA_R_READ)
1113 wordp[0] = htole32(0x14 | ((ch->unit+9)<<16) | ((ch->unit+5)<<24));
1114 if (request->flags & ATA_R_WRITE)
1115 wordp[0] = htole32(0x00 | ((ch->unit+13)<<16) | (0x00<<24));
1116 wordp[1] = htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_HSG_OFFSET);
1117 wordp[2] = htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_LSG_OFFSET);
1120 wordp = (u_int32_t *)
1121 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_APKT_OFFSET);
1122 if (request->flags & ATA_R_READ)
1123 wordp[0] = htole32(0x04 | ((ch->unit+5)<<16) | (0x00<<24));
1124 if (request->flags & ATA_R_WRITE)
1125 wordp[0] = htole32(0x10 | ((ch->unit+1)<<16) | ((ch->unit+13)<<24));
1126 wordp[1] = htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_ASG_OFFSET);
1128 ata_promise_apkt((u_int8_t *)wordp, request);
1129 ATA_OUTL(ctlr->r_res2, 0x000c0484, 0x00000001);
1131 if (request->flags & ATA_R_READ) {
1132 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+5)<<2), 0x00000001);
1133 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+9)<<2), 0x00000001);
1134 ATA_OUTL(ctlr->r_res2, 0x000c0240 + (ch->unit << 7),
1135 htole32((ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_APKT_OFFSET));
1137 if (request->flags & ATA_R_WRITE) {
1138 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+1)<<2), 0x00000001);
1139 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+13)<<2), 0x00000001);
1140 ata_promise_queue_hpkt(ctlr,
1141 htole32((ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_HPKT_OFFSET));
1148 ata_promise_apkt(u_int8_t *bytep, struct ata_request *request)
1152 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_PDC_WAIT_NBUSY|ATA_DRIVE;
1153 bytep[i++] = ATA_D_IBM | ATA_D_LBA | ATA_DEV(request->unit);
1154 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_CTL;
1155 bytep[i++] = ATA_A_4BIT;
1157 if (request->flags & ATA_R_48BIT) {
1158 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_FEATURE;
1159 bytep[i++] = request->u.ata.feature >> 8;
1160 bytep[i++] = request->u.ata.feature;
1161 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_COUNT;
1162 bytep[i++] = request->u.ata.count >> 8;
1163 bytep[i++] = request->u.ata.count;
1164 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_SECTOR;
1165 bytep[i++] = request->u.ata.lba >> 24;
1166 bytep[i++] = request->u.ata.lba;
1167 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_CYL_LSB;
1168 bytep[i++] = request->u.ata.lba >> 32;
1169 bytep[i++] = request->u.ata.lba >> 8;
1170 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_CYL_MSB;
1171 bytep[i++] = request->u.ata.lba >> 40;
1172 bytep[i++] = request->u.ata.lba >> 16;
1173 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_DRIVE;
1174 bytep[i++] = ATA_D_LBA | ATA_DEV(request->unit);
1177 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_FEATURE;
1178 bytep[i++] = request->u.ata.feature;
1179 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_COUNT;
1180 bytep[i++] = request->u.ata.count;
1181 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_SECTOR;
1182 bytep[i++] = request->u.ata.lba;
1183 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_CYL_LSB;
1184 bytep[i++] = request->u.ata.lba >> 8;
1185 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_CYL_MSB;
1186 bytep[i++] = request->u.ata.lba >> 16;
1187 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_DRIVE;
1188 bytep[i++] = ATA_D_LBA | ATA_D_IBM | ATA_DEV(request->unit) |
1189 ((request->u.ata.lba >> 24)&0xf);
1191 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_END | ATA_COMMAND;
1192 bytep[i++] = request->u.ata.command;
1197 ata_promise_queue_hpkt(struct ata_pci_controller *ctlr, u_int32_t hpkt)
1199 struct ata_promise_sx4 *hpktp = ctlr->chipset_data;
1201 mtx_lock(&hpktp->mtx);
1203 struct host_packet *hp =
1204 malloc(sizeof(struct host_packet), M_TEMP, M_NOWAIT | M_ZERO);
1206 TAILQ_INSERT_TAIL(&hpktp->queue, hp, chain);
1210 ATA_OUTL(ctlr->r_res2, 0x000c0100, hpkt);
1212 mtx_unlock(&hpktp->mtx);
1216 ata_promise_next_hpkt(struct ata_pci_controller *ctlr)
1218 struct ata_promise_sx4 *hpktp = ctlr->chipset_data;
1219 struct host_packet *hp;
1221 mtx_lock(&hpktp->mtx);
1222 if ((hp = TAILQ_FIRST(&hpktp->queue))) {
1223 TAILQ_REMOVE(&hpktp->queue, hp, chain);
1224 ATA_OUTL(ctlr->r_res2, 0x000c0100, hp->addr);
1229 mtx_unlock(&hpktp->mtx);
1232 ATA_DECLARE_DRIVER(ata_promise);