rockbox/firmware/target/arm/imx233/ata-target.h
Michael Sevakis 1654efc313 Unify storage threads into one
* Editing a bunch of drivers' thread routines in order to
implement a new feature is tedious.

* No matter the number of storage drivers, they share one thread.
No extra threads needed for CONFIG_STORAGE_MULTI.

* Each has an event callback called by the storage thread.

* A default callback is provided to fake sleeping in order to
trigger idle callbacks. It could also do other default processing.
Changes to it will be part of driver code without editing each
one.

* Drivers may sleep and wake as they please as long as they give
a low pulse on their storage bit to ask to go into sleep mode.
Idle callback is called on its behalf and driver immediately put
into sleep mode.

* Drivers may indicate they are to continue receiving events in
USB mode, otherwise they receve nothing until disconnect (they
do receive SYS_USB_DISCONNECTED no matter what).

* Rework a few things to keep the callback implementation sane
and maintainable. ata.c was dreadful with all those bools; make
it a state machine and easier to follow. Remove last_user_activity;
it has no purpose that isn't served by keeping the disk active
through last_disk_activity instead.

* Even-out stack sizes partly because of a lack of a decent place
to define them by driver or SoC or whatever; it doesn't seem too
critical to do that anyway. Many are simply too large while at
least one isn't really adequate. They may be individually
overridden if necessary (figure out where). The thread uses the
greatest size demanded. Newer file code is much more frugal with
stack space. I barely see use crack 50% after idle callbacks
(usually mid-40s). Card insert/eject doesn't demand much.

* No forcing of idle callbacks. If it isn't necessary for one or
more non-disk storage types, it really isn't any more necessary for
disk storage. Besides, it makes the whole thing easier to implement.

Change-Id: Id30c284d82a8af66e47f2cfe104c52cbd8aa7215
2017-10-26 14:35:41 -04:00

74 lines
2.6 KiB
C

/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2013 Amaury Pouly
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef ATA_TARGET_H
#define ATA_TARGET_H
#include "config.h"
#ifdef HAVE_ATA_DMA
/* FIXME does this chips does MWDMA ? */
#define ATA_MAX_MWDMA 2
#define ATA_MAX_UDMA 4
#endif
uint8_t imx233_ata_inb(unsigned reg);
uint16_t imx233_ata_inw(unsigned reg);
void imx233_ata_outb(unsigned reg, uint8_t v);
void imx233_ata_outw(unsigned reg, uint16_t v);
#define IMX233_ATA_REG(cs,addr) ((cs) << 3 | (addr))
#define IMX233_ATA_REG_CS(reg) ((reg) >> 3)
#define IMX233_ATA_REG_ADDR(reg) ((reg) & 0x7)
/* use register address (see ATA spec) */
#define ATA_DATA IMX233_ATA_REG(0, 0)
#define ATA_ERROR IMX233_ATA_REG(0, 1)
#define ATA_NSECTOR IMX233_ATA_REG(0, 2)
#define ATA_SECTOR IMX233_ATA_REG(0, 3)
#define ATA_LCYL IMX233_ATA_REG(0, 4)
#define ATA_HCYL IMX233_ATA_REG(0, 5)
#define ATA_SELECT IMX233_ATA_REG(0, 6)
#define ATA_COMMAND IMX233_ATA_REG(0, 7)
#define ATA_CONTROL IMX233_ATA_REG(1, 6)
/* keep consistent with definition of IMX233_ATA_REG */
#define ATA_OUT8(reg, data) imx233_ata_outb(reg, data)
#define ATA_OUT16(reg, data) imx233_ata_outw(reg, data)
#define ATA_IN8(reg) imx233_ata_inb(reg)
#define ATA_IN16(reg) imx233_ata_inw(reg)
#define ATA_SET_PIO_TIMING
#define ATA_TARGET_POLLING
void ata_set_pio_timings(int mode);
void ata_reset(void);
void ata_enable(bool on);
bool ata_is_coldstart(void);
#ifdef HAVE_ATA_DMA
void ata_dma_set_mode(unsigned char mode);
bool ata_dma_setup(void *addr, unsigned long bytes, bool write);
bool ata_dma_finish(void);
#endif
int ata_wait_for_bsy(void);
int ata_wait_for_rdy(void);
void ata_device_init(void);
#endif /* ATA_TARGET_H */