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 void ata_promise_setmode(device_t dev, 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 void ata_promise_mio_setmode(device_t dev, int mode);
76 static void ata_promise_sx4_intr(void *data);
77 static int ata_promise_sx4_command(struct ata_request *request);
78 static int ata_promise_apkt(u_int8_t *bytep, struct ata_request *request);
79 static void ata_promise_queue_hpkt(struct ata_pci_controller *ctlr, u_int32_t hpkt);
80 static void ata_promise_next_hpkt(struct ata_pci_controller *ctlr);
98 * Promise chipset support functions
100 #define ATA_PDC_APKT_OFFSET 0x00000010
101 #define ATA_PDC_HPKT_OFFSET 0x00000040
102 #define ATA_PDC_ASG_OFFSET 0x00000080
103 #define ATA_PDC_LSG_OFFSET 0x000000c0
104 #define ATA_PDC_HSG_OFFSET 0x00000100
105 #define ATA_PDC_CHN_OFFSET 0x00000400
106 #define ATA_PDC_BUF_BASE 0x00400000
107 #define ATA_PDC_BUF_OFFSET 0x00100000
108 #define ATA_PDC_MAX_HPKT 8
109 #define ATA_PDC_WRITE_REG 0x00
110 #define ATA_PDC_WRITE_CTL 0x0e
111 #define ATA_PDC_WRITE_END 0x08
112 #define ATA_PDC_WAIT_NBUSY 0x10
113 #define ATA_PDC_WAIT_READY 0x18
114 #define ATA_PDC_1B 0x20
115 #define ATA_PDC_2B 0x40
119 TAILQ_ENTRY(host_packet) chain;
122 struct ata_promise_sx4 {
124 TAILQ_HEAD(, host_packet) queue;
129 ata_promise_probe(device_t dev)
131 struct ata_pci_controller *ctlr = device_get_softc(dev);
132 struct ata_chip_id *idx;
133 static struct ata_chip_id ids[] =
134 {{ ATA_PDC20246, 0, PR_OLD, 0x00, ATA_UDMA2, "PDC20246" },
135 { ATA_PDC20262, 0, PR_NEW, 0x00, ATA_UDMA4, "PDC20262" },
136 { ATA_PDC20263, 0, PR_NEW, 0x00, ATA_UDMA4, "PDC20263" },
137 { ATA_PDC20265, 0, PR_NEW, 0x00, ATA_UDMA5, "PDC20265" },
138 { ATA_PDC20267, 0, PR_NEW, 0x00, ATA_UDMA5, "PDC20267" },
139 { ATA_PDC20268, 0, PR_TX, PR_TX4, ATA_UDMA5, "PDC20268" },
140 { ATA_PDC20269, 0, PR_TX, 0x00, ATA_UDMA6, "PDC20269" },
141 { ATA_PDC20270, 0, PR_TX, PR_TX4, ATA_UDMA5, "PDC20270" },
142 { ATA_PDC20271, 0, PR_TX, 0x00, ATA_UDMA6, "PDC20271" },
143 { ATA_PDC20275, 0, PR_TX, 0x00, ATA_UDMA6, "PDC20275" },
144 { ATA_PDC20276, 0, PR_TX, PR_SX6K, ATA_UDMA6, "PDC20276" },
145 { ATA_PDC20277, 0, PR_TX, 0x00, ATA_UDMA6, "PDC20277" },
146 { ATA_PDC20318, 0, PR_MIO, PR_SATA, ATA_SA150, "PDC20318" },
147 { ATA_PDC20319, 0, PR_MIO, PR_SATA, ATA_SA150, "PDC20319" },
148 { ATA_PDC20371, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20371" },
149 { ATA_PDC20375, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20375" },
150 { ATA_PDC20376, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20376" },
151 { ATA_PDC20377, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20377" },
152 { ATA_PDC20378, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20378" },
153 { ATA_PDC20379, 0, PR_MIO, PR_CMBO, ATA_SA150, "PDC20379" },
154 { ATA_PDC20571, 0, PR_MIO, PR_CMBO2, ATA_SA150, "PDC20571" },
155 { ATA_PDC20575, 0, PR_MIO, PR_CMBO2, ATA_SA150, "PDC20575" },
156 { ATA_PDC20579, 0, PR_MIO, PR_CMBO2, ATA_SA150, "PDC20579" },
157 { ATA_PDC20771, 0, PR_MIO, PR_CMBO2, ATA_SA300, "PDC20771" },
158 { ATA_PDC40775, 0, PR_MIO, PR_CMBO2, ATA_SA300, "PDC40775" },
159 { ATA_PDC20617, 0, PR_MIO, PR_PATA, ATA_UDMA6, "PDC20617" },
160 { ATA_PDC20618, 0, PR_MIO, PR_PATA, ATA_UDMA6, "PDC20618" },
161 { ATA_PDC20619, 0, PR_MIO, PR_PATA, ATA_UDMA6, "PDC20619" },
162 { ATA_PDC20620, 0, PR_MIO, PR_PATA, ATA_UDMA6, "PDC20620" },
163 { ATA_PDC20621, 0, PR_MIO, PR_SX4X, ATA_UDMA5, "PDC20621" },
164 { ATA_PDC20622, 0, PR_MIO, PR_SX4X, ATA_SA150, "PDC20622" },
165 { ATA_PDC40518, 0, PR_MIO, PR_SATA2, ATA_SA150, "PDC40518" },
166 { ATA_PDC40519, 0, PR_MIO, PR_SATA2, ATA_SA150, "PDC40519" },
167 { ATA_PDC40718, 0, PR_MIO, PR_SATA2, ATA_SA300, "PDC40718" },
168 { ATA_PDC40719, 0, PR_MIO, PR_SATA2, ATA_SA300, "PDC40719" },
169 { ATA_PDC40779, 0, PR_MIO, PR_SATA2, ATA_SA300, "PDC40779" },
170 { 0, 0, 0, 0, 0, 0}};
174 if (pci_get_vendor(dev) != ATA_PROMISE_ID)
177 if (!(idx = ata_match_chip(dev, ids)))
180 /* if we are on a SuperTrak SX6000 dont attach */
181 if ((idx->cfg2 & PR_SX6K) && pci_get_class(GRANDPARENT(dev))==PCIC_BRIDGE &&
182 !BUS_READ_IVAR(device_get_parent(GRANDPARENT(dev)),
183 GRANDPARENT(dev), PCI_IVAR_DEVID, &devid) &&
187 strcpy(buffer, "Promise ");
188 strcat(buffer, idx->text);
190 /* if we are on a FastTrak TX4, adjust the interrupt resource */
191 if ((idx->cfg2 & PR_TX4) && pci_get_class(GRANDPARENT(dev))==PCIC_BRIDGE &&
192 !BUS_READ_IVAR(device_get_parent(GRANDPARENT(dev)),
193 GRANDPARENT(dev), PCI_IVAR_DEVID, &devid) &&
194 ((devid == ATA_DEC_21150) || (devid == ATA_DEC_21150_1))) {
195 static long start = 0, end = 0;
197 if (pci_get_slot(dev) == 1) {
198 bus_get_resource(dev, SYS_RES_IRQ, 0, &start, &end);
199 strcat(buffer, " (channel 0+1)");
201 else if (pci_get_slot(dev) == 2 && start && end) {
202 bus_set_resource(dev, SYS_RES_IRQ, 0, start, end);
203 strcat(buffer, " (channel 2+3)");
209 sprintf(buffer, "%s %s controller", buffer, ata_mode2str(idx->max_dma));
210 device_set_desc_copy(dev, buffer);
212 ctlr->chipinit = ata_promise_chipinit;
213 return (BUS_PROBE_DEFAULT);
217 ata_promise_chipinit(device_t dev)
219 struct ata_pci_controller *ctlr = device_get_softc(dev);
220 int fake_reg, stat_reg;
222 if (ata_setup_interrupt(dev, ata_generic_intr))
225 switch (ctlr->chip->cfg1) {
228 ATA_OUTB(ctlr->r_res1, 0x11, ATA_INB(ctlr->r_res1, 0x11) | 0x0a);
232 /* enable burst mode */
233 ATA_OUTB(ctlr->r_res1, 0x1f, ATA_INB(ctlr->r_res1, 0x1f) | 0x01);
234 ctlr->ch_attach = ata_promise_ch_attach;
235 ctlr->ch_detach = ata_pci_ch_detach;
236 ctlr->setmode = ata_promise_setmode;
240 ctlr->ch_attach = ata_promise_tx2_ch_attach;
241 ctlr->ch_detach = ata_pci_ch_detach;
242 ctlr->setmode = ata_promise_setmode;
246 ctlr->r_type1 = SYS_RES_MEMORY;
247 ctlr->r_rid1 = PCIR_BAR(4);
248 if (!(ctlr->r_res1 = bus_alloc_resource_any(dev, ctlr->r_type1,
249 &ctlr->r_rid1, RF_ACTIVE)))
252 ctlr->r_type2 = SYS_RES_MEMORY;
253 ctlr->r_rid2 = PCIR_BAR(3);
254 if (!(ctlr->r_res2 = bus_alloc_resource_any(dev, ctlr->r_type2,
255 &ctlr->r_rid2, RF_ACTIVE)))
258 if (ctlr->chip->cfg2 == PR_SX4X) {
259 struct ata_promise_sx4 *hpkt;
260 u_int32_t dimm = ATA_INL(ctlr->r_res2, 0x000c0080);
262 if (bus_teardown_intr(dev, ctlr->r_irq, ctlr->handle) ||
263 bus_setup_intr(dev, ctlr->r_irq, ATA_INTR_FLAGS, NULL,
264 ata_promise_sx4_intr, ctlr, &ctlr->handle)) {
265 device_printf(dev, "unable to setup interrupt\n");
269 /* print info about cache memory */
270 device_printf(dev, "DIMM size %dMB @ 0x%08x%s\n",
271 (((dimm >> 16) & 0xff)-((dimm >> 24) & 0xff)+1) << 4,
272 ((dimm >> 24) & 0xff),
273 ATA_INL(ctlr->r_res2, 0x000c0088) & (1<<16) ?
274 " ECC enabled" : "" );
276 /* adjust cache memory parameters */
277 ATA_OUTL(ctlr->r_res2, 0x000c000c,
278 (ATA_INL(ctlr->r_res2, 0x000c000c) & 0xffff0000));
280 /* setup host packet controls */
281 hpkt = malloc(sizeof(struct ata_promise_sx4),
282 M_TEMP, M_NOWAIT | M_ZERO);
283 mtx_init(&hpkt->mtx, "ATA promise HPKT lock", NULL, MTX_DEF);
284 TAILQ_INIT(&hpkt->queue);
286 ctlr->chipset_data = hpkt;
287 ctlr->ch_attach = ata_promise_mio_ch_attach;
288 ctlr->ch_detach = ata_promise_mio_ch_detach;
289 ctlr->reset = ata_promise_mio_reset;
290 ctlr->setmode = ata_promise_setmode;
295 /* mio type controllers need an interrupt intercept */
296 if (bus_teardown_intr(dev, ctlr->r_irq, ctlr->handle) ||
297 bus_setup_intr(dev, ctlr->r_irq, ATA_INTR_FLAGS, NULL,
298 ata_promise_mio_intr, ctlr, &ctlr->handle)) {
299 device_printf(dev, "unable to setup interrupt\n");
303 switch (ctlr->chip->cfg2) {
305 ctlr->channels = ((ATA_INL(ctlr->r_res2, 0x48) & 0x01) > 0) +
306 ((ATA_INL(ctlr->r_res2, 0x48) & 0x02) > 0) + 2;
330 /* prime fake interrupt register */
331 ATA_OUTL(ctlr->r_res2, fake_reg, 0xffffffff);
333 /* clear SATA status and unmask interrupts */
334 ATA_OUTL(ctlr->r_res2, stat_reg, 0x000000ff);
336 /* enable "long burst length" on gen2 chips */
337 if ((ctlr->chip->cfg2 == PR_SATA2) || (ctlr->chip->cfg2 == PR_CMBO2))
338 ATA_OUTL(ctlr->r_res2, 0x44, ATA_INL(ctlr->r_res2, 0x44) | 0x2000);
340 ctlr->ch_attach = ata_promise_mio_ch_attach;
341 ctlr->ch_detach = ata_promise_mio_ch_detach;
342 ctlr->reset = ata_promise_mio_reset;
343 ctlr->setmode = ata_promise_mio_setmode;
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;
376 ata_promise_status(device_t dev)
378 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
379 struct ata_channel *ch = device_get_softc(dev);
381 if (ATA_INL(ctlr->r_res1, 0x1c) & (ch->unit ? 0x00004000 : 0x00000400)) {
382 return ata_pci_status(dev);
388 ata_promise_dmastart(struct ata_request *request)
390 struct ata_pci_controller *ctlr=device_get_softc(GRANDPARENT(request->dev));
391 struct ata_channel *ch = device_get_softc(request->parent);
392 struct ata_device *atadev = device_get_softc(request->dev);
394 if (atadev->flags & ATA_D_48BIT_ACTIVE) {
395 ATA_OUTB(ctlr->r_res1, 0x11,
396 ATA_INB(ctlr->r_res1, 0x11) | (ch->unit ? 0x08 : 0x02));
397 ATA_OUTL(ctlr->r_res1, ch->unit ? 0x24 : 0x20,
398 ((request->flags & ATA_R_READ) ? 0x05000000 : 0x06000000) |
399 (request->bytecount >> 1));
401 ATA_IDX_OUTB(ch, ATA_BMSTAT_PORT, (ATA_IDX_INB(ch, ATA_BMSTAT_PORT) |
402 (ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR)));
403 ATA_IDX_OUTL(ch, ATA_BMDTP_PORT, request->dma->sg_bus);
404 ATA_IDX_OUTB(ch, ATA_BMCMD_PORT,
405 ((request->flags & ATA_R_READ) ? ATA_BMCMD_WRITE_READ : 0) |
406 ATA_BMCMD_START_STOP);
407 ch->dma.flags |= ATA_DMA_ACTIVE;
412 ata_promise_dmastop(struct ata_request *request)
414 struct ata_pci_controller *ctlr=device_get_softc(GRANDPARENT(request->dev));
415 struct ata_channel *ch = device_get_softc(request->parent);
416 struct ata_device *atadev = device_get_softc(request->dev);
419 if (atadev->flags & ATA_D_48BIT_ACTIVE) {
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 mode)
446 device_t gparent = GRANDPARENT(dev);
447 struct ata_pci_controller *ctlr = device_get_softc(gparent);
448 struct ata_channel *ch = device_get_softc(device_get_parent(dev));
449 struct ata_device *atadev = device_get_softc(dev);
450 int devno = (ch->unit << 1) + atadev->unit;
452 u_int32_t timings[][2] = {
453 /* PR_OLD PR_NEW mode */
454 { 0x004ff329, 0x004fff2f }, /* PIO 0 */
455 { 0x004fec25, 0x004ff82a }, /* PIO 1 */
456 { 0x004fe823, 0x004ff026 }, /* PIO 2 */
457 { 0x004fe622, 0x004fec24 }, /* PIO 3 */
458 { 0x004fe421, 0x004fe822 }, /* PIO 4 */
459 { 0x004567f3, 0x004acef6 }, /* MWDMA 0 */
460 { 0x004467f3, 0x0048cef6 }, /* MWDMA 1 */
461 { 0x004367f3, 0x0046cef6 }, /* MWDMA 2 */
462 { 0x004367f3, 0x0046cef6 }, /* UDMA 0 */
463 { 0x004247f3, 0x00448ef6 }, /* UDMA 1 */
464 { 0x004127f3, 0x00436ef6 }, /* UDMA 2 */
465 { 0, 0x00424ef6 }, /* UDMA 3 */
466 { 0, 0x004127f3 }, /* UDMA 4 */
467 { 0, 0x004127f3 } /* UDMA 5 */
470 mode = ata_limit_mode(dev, mode, ctlr->chip->max_dma);
472 switch (ctlr->chip->cfg1) {
475 if (mode > ATA_UDMA2 && (pci_read_config(gparent, 0x50, 2) &
476 (ch->unit ? 1 << 11 : 1 << 10))) {
477 ata_print_cable(dev, "controller");
480 if (ata_atapi(dev) && mode > ATA_PIO_MAX)
481 mode = ata_limit_mode(dev, mode, ATA_PIO_MAX);
485 ATA_IDX_OUTB(ch, ATA_BMDEVSPEC_0, 0x0b);
486 if (mode > ATA_UDMA2 &&
487 ATA_IDX_INB(ch, ATA_BMDEVSPEC_1) & 0x04) {
488 ata_print_cable(dev, "controller");
494 if (mode > ATA_UDMA2 &&
495 (ATA_INL(ctlr->r_res2,
496 (ctlr->chip->cfg2 & PR_SX4X ? 0x000c0260 : 0x0260) +
497 (ch->unit << 7)) & 0x01000000)) {
498 ata_print_cable(dev, "controller");
504 error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
507 device_printf(dev, "%ssetting %s on %s chip\n",
508 (error) ? "FAILURE " : "",
509 ata_mode2str(mode), ctlr->chip->text);
511 if (ctlr->chip->cfg1 < PR_TX)
512 pci_write_config(gparent, 0x60 + (devno << 2),
513 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;
532 ata_promise_tx2_status(device_t dev)
534 struct ata_channel *ch = device_get_softc(dev);
536 ATA_IDX_OUTB(ch, ATA_BMDEVSPEC_0, 0x0b);
537 if (ATA_IDX_INB(ch, ATA_BMDEVSPEC_1) & 0x20) {
538 return ata_pci_status(dev);
544 ata_promise_mio_ch_attach(device_t dev)
546 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
547 struct ata_channel *ch = device_get_softc(dev);
548 int offset = (ctlr->chip->cfg2 & PR_SX4X) ? 0x000c0000 : 0;
551 ata_promise_mio_dmainit(dev);
553 for (i = ATA_DATA; i <= ATA_COMMAND; i++) {
554 ch->r_io[i].res = ctlr->r_res2;
555 ch->r_io[i].offset = offset + 0x0200 + (i << 2) + (ch->unit << 7);
557 ch->r_io[ATA_CONTROL].res = ctlr->r_res2;
558 ch->r_io[ATA_CONTROL].offset = offset + 0x0238 + (ch->unit << 7);
559 ch->r_io[ATA_IDX_ADDR].res = ctlr->r_res2;
560 ata_default_registers(dev);
561 if ((ctlr->chip->cfg2 & (PR_SATA | PR_SATA2)) ||
562 ((ctlr->chip->cfg2 & (PR_CMBO | PR_CMBO2)) && ch->unit < 2)) {
563 ch->r_io[ATA_SSTATUS].res = ctlr->r_res2;
564 ch->r_io[ATA_SSTATUS].offset = 0x400 + (ch->unit << 8);
565 ch->r_io[ATA_SERROR].res = ctlr->r_res2;
566 ch->r_io[ATA_SERROR].offset = 0x404 + (ch->unit << 8);
567 ch->r_io[ATA_SCONTROL].res = ctlr->r_res2;
568 ch->r_io[ATA_SCONTROL].offset = 0x408 + (ch->unit << 8);
569 ch->flags |= ATA_NO_SLAVE;
571 ch->flags |= ATA_USE_16BIT;
574 if (ctlr->chip->cfg2 & PR_SX4X) {
575 ch->hw.command = ata_promise_sx4_command;
578 ch->hw.command = ata_promise_mio_command;
579 ch->hw.status = ata_promise_mio_status;
580 ch->hw.softreset = ata_promise_mio_softreset;
581 ch->hw.pm_read = ata_promise_mio_pm_read;
582 ch->hw.pm_write = ata_promise_mio_pm_write;
588 ata_promise_mio_ch_detach(device_t dev)
596 ata_promise_mio_intr(void *data)
598 struct ata_pci_controller *ctlr = data;
599 struct ata_channel *ch;
603 switch (ctlr->chip->cfg2) {
617 * since reading interrupt status register on early "mio" chips
618 * clears the status bits we cannot read it for each channel later on
619 * in the generic interrupt routine.
620 * store the bits in an unused register in the chip so we can read
621 * it from there safely to get around this "feature".
623 vector = ATA_INL(ctlr->r_res2, 0x040);
624 ATA_OUTL(ctlr->r_res2, 0x040, vector);
625 ATA_OUTL(ctlr->r_res2, fake_reg, vector);
627 for (unit = 0; unit < ctlr->channels; unit++) {
628 if ((ch = ctlr->interrupt[unit].argument))
629 ctlr->interrupt[unit].function(ch);
632 ATA_OUTL(ctlr->r_res2, fake_reg, 0xffffffff);
636 ata_promise_mio_status(device_t dev)
638 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
639 struct ata_channel *ch = device_get_softc(dev);
640 u_int32_t fake_reg, stat_reg, vector, status;
642 switch (ctlr->chip->cfg2) {
657 /* read and acknowledge interrupt */
658 vector = ATA_INL(ctlr->r_res2, fake_reg);
660 /* read and clear interface status */
661 status = ATA_INL(ctlr->r_res2, stat_reg);
662 ATA_OUTL(ctlr->r_res2, stat_reg, status & (0x00000011 << ch->unit));
664 /* check for and handle disconnect events */
665 if (status & (0x00000001 << ch->unit)) {
667 device_printf(dev, "DISCONNECT requested\n");
668 taskqueue_enqueue(taskqueue_thread, &ch->conntask);
671 /* check for and handle connect events */
672 if (status & (0x00000010 << ch->unit)) {
674 device_printf(dev, "CONNECT requested\n");
675 taskqueue_enqueue(taskqueue_thread, &ch->conntask);
678 /* do we have any device action ? */
679 return (vector & (1 << (ch->unit + 1)));
683 ata_promise_mio_command(struct ata_request *request)
685 struct ata_pci_controller *ctlr=device_get_softc(GRANDPARENT(request->dev));
686 struct ata_channel *ch = device_get_softc(request->parent);
687 struct ata_device *atadev = device_get_softc(request->dev);
689 u_int32_t *wordp = (u_int32_t *)ch->dma.work;
691 ATA_OUTL(ctlr->r_res2, (ch->unit + 1) << 2, 0x00000001);
693 if ((ctlr->chip->cfg2 == PR_SATA2) ||
694 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2))) {
695 /* set portmultiplier port */
696 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), atadev->unit & 0x0f);
699 /* XXX SOS add ATAPI commands support later */
700 switch (request->u.ata.command) {
702 return ata_generic_command(request);
706 wordp[0] = htole32(0x04 | ((ch->unit + 1) << 16) | (0x00 << 24));
710 case ATA_WRITE_DMA48:
711 wordp[0] = htole32(0x00 | ((ch->unit + 1) << 16) | (0x00 << 24));
714 wordp[1] = htole32(request->dma->sg_bus);
716 ata_promise_apkt((u_int8_t*)wordp, request);
718 ATA_OUTL(ctlr->r_res2, 0x0240 + (ch->unit << 7), ch->dma.work_bus);
723 ata_promise_mio_reset(device_t dev)
725 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
726 struct ata_channel *ch = device_get_softc(dev);
727 struct ata_promise_sx4 *hpktp;
729 switch (ctlr->chip->cfg2) {
732 /* softreset channel ATA module */
733 hpktp = ctlr->chipset_data;
734 ATA_OUTL(ctlr->r_res2, 0xc0260 + (ch->unit << 7), ch->unit + 1);
736 ATA_OUTL(ctlr->r_res2, 0xc0260 + (ch->unit << 7),
737 (ATA_INL(ctlr->r_res2, 0xc0260 + (ch->unit << 7)) &
738 ~0x00003f9f) | (ch->unit + 1));
740 /* softreset HOST module */ /* XXX SOS what about other outstandings */
741 mtx_lock(&hpktp->mtx);
742 ATA_OUTL(ctlr->r_res2, 0xc012c,
743 (ATA_INL(ctlr->r_res2, 0xc012c) & ~0x00000f9f) | (1 << 11));
745 ATA_OUTL(ctlr->r_res2, 0xc012c,
746 (ATA_INL(ctlr->r_res2, 0xc012c) & ~0x00000f9f));
748 mtx_unlock(&hpktp->mtx);
749 ata_generic_reset(dev);
755 if ((ctlr->chip->cfg2 == PR_SATA) ||
756 ((ctlr->chip->cfg2 == PR_CMBO) && (ch->unit < 2))) {
758 /* mask plug/unplug intr */
759 ATA_OUTL(ctlr->r_res2, 0x06c, (0x00110000 << ch->unit));
762 /* softreset channels ATA module */
763 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7), (1 << 11));
765 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7),
766 (ATA_INL(ctlr->r_res2, 0x0260 + (ch->unit << 7)) &
767 ~0x00003f9f) | (ch->unit + 1));
769 if ((ctlr->chip->cfg2 == PR_SATA) ||
770 ((ctlr->chip->cfg2 == PR_CMBO) && (ch->unit < 2))) {
772 if (ata_sata_phy_reset(dev, -1, 1))
773 ata_generic_reset(dev);
775 /* reset and enable plug/unplug intr */
776 ATA_OUTL(ctlr->r_res2, 0x06c, (0x00000011 << ch->unit));
779 ata_generic_reset(dev);
784 if ((ctlr->chip->cfg2 == PR_SATA2) ||
785 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2))) {
786 /* set portmultiplier port */
787 //ATA_OUTL(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x0f);
789 /* mask plug/unplug intr */
790 ATA_OUTL(ctlr->r_res2, 0x060, (0x00110000 << ch->unit));
793 /* softreset channels ATA module */
794 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7), (1 << 11));
796 ATA_OUTL(ctlr->r_res2, 0x0260 + (ch->unit << 7),
797 (ATA_INL(ctlr->r_res2, 0x0260 + (ch->unit << 7)) &
798 ~0x00003f9f) | (ch->unit + 1));
800 if ((ctlr->chip->cfg2 == PR_SATA2) ||
801 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2))) {
803 /* set PHY mode to "improved" */
804 ATA_OUTL(ctlr->r_res2, 0x414 + (ch->unit << 8),
805 (ATA_INL(ctlr->r_res2, 0x414 + (ch->unit << 8)) &
806 ~0x00000003) | 0x00000001);
808 if (ata_sata_phy_reset(dev, -1, 1)) {
809 u_int32_t signature = ch->hw.softreset(dev, ATA_PM);
812 device_printf(dev, "SIGNATURE: %08x\n", signature);
814 switch (signature >> 16) {
816 ch->devices = ATA_ATA_MASTER;
819 ch->devices = ATA_PORTMULTIPLIER;
820 ata_pm_identify(dev);
823 ch->devices = ATA_ATAPI_MASTER;
825 default: /* SOS XXX */
828 "No signature, assuming disk device\n");
829 ch->devices = ATA_ATA_MASTER;
832 device_printf(dev, "promise_mio_reset devices=%08x\n",
837 /* reset and enable plug/unplug intr */
838 ATA_OUTL(ctlr->r_res2, 0x060, (0x00000011 << ch->unit));
840 ///* set portmultiplier port */
841 ATA_OUTL(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x00);
844 ata_generic_reset(dev);
851 ata_promise_mio_pm_read(device_t dev, int port, int reg, u_int32_t *result)
853 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
854 struct ata_channel *ch = device_get_softc(dev);
857 /* set portmultiplier port */
858 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x0f);
860 ATA_IDX_OUTB(ch, ATA_FEATURE, reg);
861 ATA_IDX_OUTB(ch, ATA_DRIVE, port);
863 ATA_IDX_OUTB(ch, ATA_COMMAND, ATA_READ_PM);
865 while (timeout < 1000000) {
866 u_int8_t status = ATA_IDX_INB(ch, ATA_STATUS);
867 if (!(status & ATA_S_BUSY))
872 if (timeout >= 1000000)
875 *result = ATA_IDX_INB(ch, ATA_COUNT) |
876 (ATA_IDX_INB(ch, ATA_SECTOR) << 8) |
877 (ATA_IDX_INB(ch, ATA_CYL_LSB) << 16) |
878 (ATA_IDX_INB(ch, ATA_CYL_MSB) << 24);
883 ata_promise_mio_pm_write(device_t dev, int port, int reg, u_int32_t value)
885 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
886 struct ata_channel *ch = device_get_softc(dev);
889 /* set portmultiplier port */
890 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x0f);
892 ATA_IDX_OUTB(ch, ATA_FEATURE, reg);
893 ATA_IDX_OUTB(ch, ATA_DRIVE, port);
894 ATA_IDX_OUTB(ch, ATA_COUNT, value & 0xff);
895 ATA_IDX_OUTB(ch, ATA_SECTOR, (value >> 8) & 0xff);
896 ATA_IDX_OUTB(ch, ATA_CYL_LSB, (value >> 16) & 0xff);
897 ATA_IDX_OUTB(ch, ATA_CYL_MSB, (value >> 24) & 0xff);
899 ATA_IDX_OUTB(ch, ATA_COMMAND, ATA_WRITE_PM);
901 while (timeout < 1000000) {
902 u_int8_t status = ATA_IDX_INB(ch, ATA_STATUS);
903 if (!(status & ATA_S_BUSY))
908 if (timeout >= 1000000)
911 return ATA_IDX_INB(ch, ATA_ERROR);
914 /* must be called with ATA channel locked and state_mtx held */
916 ata_promise_mio_softreset(device_t dev, int port)
918 struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
919 struct ata_channel *ch = device_get_softc(dev);
922 /* set portmultiplier port */
923 ATA_OUTB(ctlr->r_res2, 0x4e8 + (ch->unit << 8), port & 0x0f);
925 /* softreset device on this channel */
926 ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_D_LBA | ATA_DEV(ATA_MASTER));
928 ATA_IDX_OUTB(ch, ATA_CONTROL, ATA_A_IDS | ATA_A_RESET);
930 ATA_IDX_OUTB(ch, ATA_CONTROL, ATA_A_IDS);
932 ATA_IDX_INB(ch, ATA_ERROR);
934 /* wait for BUSY to go inactive */
935 for (timeout = 0; timeout < 100; timeout++) {
938 err = ATA_IDX_INB(ch, ATA_ERROR);
939 stat = ATA_IDX_INB(ch, ATA_STATUS);
941 //if (stat == err && timeout > (stat & ATA_S_BUSY ? 100 : 10))
944 if (!(stat & ATA_S_BUSY)) {
945 //if ((err & 0x7f) == ATA_E_ILI) {
946 return ATA_IDX_INB(ch, ATA_COUNT) |
947 (ATA_IDX_INB(ch, ATA_SECTOR) << 8) |
948 (ATA_IDX_INB(ch, ATA_CYL_LSB) << 16) |
949 (ATA_IDX_INB(ch, ATA_CYL_MSB) << 24);
951 //else if (stat & 0x0f) {
952 //stat |= ATA_S_BUSY;
956 if (!(stat & ATA_S_BUSY) || (stat == 0xff && timeout > 10))
964 ata_promise_mio_dmainit(device_t dev)
966 struct ata_channel *ch = device_get_softc(dev);
969 /* note start and stop are not used here */
970 ch->dma.setprd = ata_promise_mio_setprd;
974 #define MAXLASTSGSIZE (32 * sizeof(u_int32_t))
976 ata_promise_mio_setprd(void *xsc, bus_dma_segment_t *segs, int nsegs, int error)
978 struct ata_dmasetprd_args *args = xsc;
979 struct ata_dma_prdentry *prd = args->dmatab;
982 if ((args->error = error))
985 for (i = 0; i < nsegs; i++) {
986 prd[i].addr = htole32(segs[i].ds_addr);
987 prd[i].count = htole32(segs[i].ds_len);
989 if (segs[i - 1].ds_len > MAXLASTSGSIZE) {
990 //printf("split last SG element of %u\n", segs[i - 1].ds_len);
991 prd[i - 1].count = htole32(segs[i - 1].ds_len - MAXLASTSGSIZE);
992 prd[i].count = htole32(MAXLASTSGSIZE);
993 prd[i].addr = htole32(segs[i - 1].ds_addr +
994 (segs[i - 1].ds_len - MAXLASTSGSIZE));
998 prd[i - 1].count |= htole32(ATA_DMA_EOT);
999 KASSERT(nsegs <= ATA_DMA_ENTRIES, ("too many DMA segment entries\n"));
1000 args->nsegs = nsegs;
1004 ata_promise_mio_setmode(device_t dev, int mode)
1006 device_t gparent = GRANDPARENT(dev);
1007 struct ata_pci_controller *ctlr = device_get_softc(gparent);
1008 struct ata_channel *ch = device_get_softc(device_get_parent(dev));
1010 if ( (ctlr->chip->cfg2 == PR_SATA) ||
1011 ((ctlr->chip->cfg2 == PR_CMBO) && (ch->unit < 2)) ||
1012 (ctlr->chip->cfg2 == PR_SATA2) ||
1013 ((ctlr->chip->cfg2 == PR_CMBO2) && (ch->unit < 2)))
1014 ata_sata_setmode(dev, mode);
1016 ata_promise_setmode(dev, mode);
1020 ata_promise_sx4_intr(void *data)
1022 struct ata_pci_controller *ctlr = data;
1023 struct ata_channel *ch;
1024 u_int32_t vector = ATA_INL(ctlr->r_res2, 0x000c0480);
1027 for (unit = 0; unit < ctlr->channels; unit++) {
1028 if (vector & (1 << (unit + 1)))
1029 if ((ch = ctlr->interrupt[unit].argument))
1030 ctlr->interrupt[unit].function(ch);
1031 if (vector & (1 << (unit + 5)))
1032 if ((ch = ctlr->interrupt[unit].argument))
1033 ata_promise_queue_hpkt(ctlr,
1034 htole32((ch->unit * ATA_PDC_CHN_OFFSET) +
1035 ATA_PDC_HPKT_OFFSET));
1036 if (vector & (1 << (unit + 9))) {
1037 ata_promise_next_hpkt(ctlr);
1038 if ((ch = ctlr->interrupt[unit].argument))
1039 ctlr->interrupt[unit].function(ch);
1041 if (vector & (1 << (unit + 13))) {
1042 ata_promise_next_hpkt(ctlr);
1043 if ((ch = ctlr->interrupt[unit].argument))
1044 ATA_OUTL(ctlr->r_res2, 0x000c0240 + (ch->unit << 7),
1045 htole32((ch->unit * ATA_PDC_CHN_OFFSET) +
1046 ATA_PDC_APKT_OFFSET));
1052 ata_promise_sx4_command(struct ata_request *request)
1054 device_t gparent = GRANDPARENT(request->dev);
1055 struct ata_pci_controller *ctlr = device_get_softc(gparent);
1056 struct ata_channel *ch = device_get_softc(request->parent);
1057 struct ata_dma_prdentry *prd;
1058 caddr_t window = rman_get_virtual(ctlr->r_res1);
1060 int i, idx, length = 0;
1062 /* XXX SOS add ATAPI commands support later */
1063 switch (request->u.ata.command) {
1068 case ATA_ATA_IDENTIFY:
1072 case ATA_READ_MUL48:
1076 case ATA_WRITE_MUL48:
1077 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit + 1) << 2), 0x00000001);
1078 return ata_generic_command(request);
1080 case ATA_SETFEATURES:
1081 case ATA_FLUSHCACHE:
1082 case ATA_FLUSHCACHE48:
1085 wordp = (u_int32_t *)
1086 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_APKT_OFFSET);
1087 wordp[0] = htole32(0x08 | ((ch->unit + 1)<<16) | (0x00 << 24));
1090 ata_promise_apkt((u_int8_t *)wordp, request);
1091 ATA_OUTL(ctlr->r_res2, 0x000c0484, 0x00000001);
1092 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit + 1) << 2), 0x00000001);
1093 ATA_OUTL(ctlr->r_res2, 0x000c0240 + (ch->unit << 7),
1094 htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_APKT_OFFSET));
1098 case ATA_READ_DMA48:
1100 case ATA_WRITE_DMA48:
1101 prd = request->dma->sg;
1102 wordp = (u_int32_t *)
1103 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_HSG_OFFSET);
1106 wordp[idx++] = prd[i].addr;
1107 wordp[idx++] = prd[i].count;
1108 length += (prd[i].count & ~ATA_DMA_EOT);
1109 } while (!(prd[i++].count & ATA_DMA_EOT));
1111 wordp = (u_int32_t *)
1112 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_LSG_OFFSET);
1113 wordp[0] = htole32((ch->unit * ATA_PDC_BUF_OFFSET) + ATA_PDC_BUF_BASE);
1114 wordp[1] = htole32(request->bytecount | ATA_DMA_EOT);
1116 wordp = (u_int32_t *)
1117 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_ASG_OFFSET);
1118 wordp[0] = htole32((ch->unit * ATA_PDC_BUF_OFFSET) + ATA_PDC_BUF_BASE);
1119 wordp[1] = htole32(request->bytecount | ATA_DMA_EOT);
1121 wordp = (u_int32_t *)
1122 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_HPKT_OFFSET);
1123 if (request->flags & ATA_R_READ)
1124 wordp[0] = htole32(0x14 | ((ch->unit+9)<<16) | ((ch->unit+5)<<24));
1125 if (request->flags & ATA_R_WRITE)
1126 wordp[0] = htole32(0x00 | ((ch->unit+13)<<16) | (0x00<<24));
1127 wordp[1] = htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_HSG_OFFSET);
1128 wordp[2] = htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_LSG_OFFSET);
1131 wordp = (u_int32_t *)
1132 (window + (ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_APKT_OFFSET);
1133 if (request->flags & ATA_R_READ)
1134 wordp[0] = htole32(0x04 | ((ch->unit+5)<<16) | (0x00<<24));
1135 if (request->flags & ATA_R_WRITE)
1136 wordp[0] = htole32(0x10 | ((ch->unit+1)<<16) | ((ch->unit+13)<<24));
1137 wordp[1] = htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_ASG_OFFSET);
1139 ata_promise_apkt((u_int8_t *)wordp, request);
1140 ATA_OUTL(ctlr->r_res2, 0x000c0484, 0x00000001);
1142 if (request->flags & ATA_R_READ) {
1143 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+5)<<2), 0x00000001);
1144 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+9)<<2), 0x00000001);
1145 ATA_OUTL(ctlr->r_res2, 0x000c0240 + (ch->unit << 7),
1146 htole32((ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_APKT_OFFSET));
1148 if (request->flags & ATA_R_WRITE) {
1149 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+1)<<2), 0x00000001);
1150 ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit+13)<<2), 0x00000001);
1151 ata_promise_queue_hpkt(ctlr,
1152 htole32((ch->unit * ATA_PDC_CHN_OFFSET) + ATA_PDC_HPKT_OFFSET));
1159 ata_promise_apkt(u_int8_t *bytep, struct ata_request *request)
1161 struct ata_device *atadev = device_get_softc(request->dev);
1164 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_PDC_WAIT_NBUSY|ATA_DRIVE;
1165 bytep[i++] = ATA_D_IBM | ATA_D_LBA | ATA_DEV(atadev->unit);
1166 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_CTL;
1167 bytep[i++] = ATA_A_4BIT;
1169 if (atadev->flags & ATA_D_48BIT_ACTIVE) {
1170 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_FEATURE;
1171 bytep[i++] = request->u.ata.feature >> 8;
1172 bytep[i++] = request->u.ata.feature;
1173 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_COUNT;
1174 bytep[i++] = request->u.ata.count >> 8;
1175 bytep[i++] = request->u.ata.count;
1176 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_SECTOR;
1177 bytep[i++] = request->u.ata.lba >> 24;
1178 bytep[i++] = request->u.ata.lba;
1179 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_CYL_LSB;
1180 bytep[i++] = request->u.ata.lba >> 32;
1181 bytep[i++] = request->u.ata.lba >> 8;
1182 bytep[i++] = ATA_PDC_2B | ATA_PDC_WRITE_REG | ATA_CYL_MSB;
1183 bytep[i++] = request->u.ata.lba >> 40;
1184 bytep[i++] = request->u.ata.lba >> 16;
1185 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_DRIVE;
1186 bytep[i++] = ATA_D_LBA | ATA_DEV(atadev->unit);
1189 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_FEATURE;
1190 bytep[i++] = request->u.ata.feature;
1191 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_COUNT;
1192 bytep[i++] = request->u.ata.count;
1193 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_SECTOR;
1194 bytep[i++] = request->u.ata.lba;
1195 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_CYL_LSB;
1196 bytep[i++] = request->u.ata.lba >> 8;
1197 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_CYL_MSB;
1198 bytep[i++] = request->u.ata.lba >> 16;
1199 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_DRIVE;
1200 bytep[i++] = (atadev->flags & ATA_D_USE_CHS ? 0 : ATA_D_LBA) |
1201 ATA_D_IBM | ATA_DEV(atadev->unit) |
1202 ((request->u.ata.lba >> 24)&0xf);
1204 bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_END | ATA_COMMAND;
1205 bytep[i++] = request->u.ata.command;
1210 ata_promise_queue_hpkt(struct ata_pci_controller *ctlr, u_int32_t hpkt)
1212 struct ata_promise_sx4 *hpktp = ctlr->chipset_data;
1214 mtx_lock(&hpktp->mtx);
1216 struct host_packet *hp =
1217 malloc(sizeof(struct host_packet), M_TEMP, M_NOWAIT | M_ZERO);
1219 TAILQ_INSERT_TAIL(&hpktp->queue, hp, chain);
1223 ATA_OUTL(ctlr->r_res2, 0x000c0100, hpkt);
1225 mtx_unlock(&hpktp->mtx);
1229 ata_promise_next_hpkt(struct ata_pci_controller *ctlr)
1231 struct ata_promise_sx4 *hpktp = ctlr->chipset_data;
1232 struct host_packet *hp;
1234 mtx_lock(&hpktp->mtx);
1235 if ((hp = TAILQ_FIRST(&hpktp->queue))) {
1236 TAILQ_REMOVE(&hpktp->queue, hp, chain);
1237 ATA_OUTL(ctlr->r_res2, 0x000c0100, hp->addr);
1242 mtx_unlock(&hpktp->mtx);
1245 ATA_DECLARE_DRIVER(ata_promise);