Linux mmc Driver Framework -- important data structure

Posted by aa-true-vicious on Tue, 25 Feb 2020 16:05:33 +0100

Linux mmc Driver Framework

Summary

data structure describe
struct mmc_host Used to represent an mmc host controller
struct mmc_card Used to represent an mmc device (card)
struct mmc_ios IO bus related settings
struct mmc_driver Used to represent mmc card drive
struct mmc_bus_ops Bus operation function set, including mmc, sd and sdio
struct mmc_host_ops The Host controller operation function set is used to describe the card controller operation interface function, register the operation function from the Host controller layer to the core layer, so as to isolate the core layer from the specific Host controller
struct mmc_command Represents an mmc command
struct mmc_data Represents an mmc data
struct mmc_request Represents an mmc request
struct sdio_func A sdio card can support many Functions. A Function corresponds to the struct sdio ﹣ func structure of the software. The final reaction to the driver model is a device

mmc_host

struct mmc_host {
	int			index;
	const struct mmc_host_ops *ops;			/* host Set of controller operation functions*/
	u32			ocr_avail;
	u32			ocr_avail_sdio;				/* SDIO-specific OCR */
	u32			ocr_avail_sd;				/* SD-specific OCR */
	u32			ocr_avail_mmc;				/* MMC-specific OCR */
	u32			caps;						/* Host Capacity marker */
	u32			caps2;						/* Host Capacity flag bit 2, 32 bit is not enough to fill another 32 bit */
	struct mmc_ios		ios;				/* current io bus settings */
	int			rescan_disable;				/* disable card detection */
	int			rescan_entered;				/* used with nonremovable devices */
	struct mmc_card		*card;				/* Used to represent an mmc device (card) attached to the current host */
	struct delayed_work	detect;				/* Card detection function */
	int			detect_change;				/* Card detection mark */
	struct mmc_slot		slot;
	const struct mmc_bus_ops *bus_ops;		/* Current bus operation function set, mmc/sd/sdio */
	struct mmc_supply	supply;
	unsigned int		slotno;				/* used for sdio acpi binding */
	int			dsr_req;					/* DSR value is valid */
	u32			dsr;						/* optional driver stage (DSR) value */
	unsigned long		private[0] ____cacheline_aligned;
}

mmc_card

struct mmc_card {
    struct mmc_host     *host;        		/* host data structure corresponding to device (card) */
    struct device       dev;          		/* the device */
    u32                 ocr;          		/* Current OCR settings*/
    unsigned int        rca;          		/* relative card address of device */
    unsigned int        type;         		/* Card Type: MMC, SD, SDIO, COMBO */
    unsigned int        state;        		/* Current card status */
    unsigned int        quirks;       		/* card quirks */
    struct mmc_cid      cid;          		/* card identification */
    struct mmc_csd      csd;          		/* card specific */
    struct mmc_ext_csd  ext_csd;      		/* mmc v4 extended card specific */
    struct sd_scr       scr;          		/* extra SD information */
    struct sd_ssr       ssr;          		/* yet more SD information */
    struct sd_switch_caps sw_caps;    		/* switch (CMD6) caps */
    unsigned int        sdio_funcs;   		/* number of SDIO functions */
    struct sdio_cccr    cccr;         		/* common card info */
    struct sdio_cis     cis;          		/* common tuple info */
    struct sdio_func    *sdio_func[7];     	/* SDIO functions (devices) */
    unsigned int        sd_bus_speed;      	/* Bus Speed Mode set for the card */
    unsigned int        mmc_avail_type;    	/* supported device type by both host and card */
    unsigned int        drive_strength;    	/* for UHS-I, HS200 or HS400 */
};

mmc_ios

struct mmc_ios {
	unsigned int	clock;					/* clock frequency */
	unsigned short	vdd;
	unsigned char	bus_mode;				/* Command output mode: open drain mode, pull-up mode */
	unsigned char	chip_select;			/* SPI Chip selection */
	unsigned char	power_mode;				/* Power supply mode: UNDEFINED, OFF, UP, ON */
	unsigned char	bus_width;				/* Data bus width: 1, 4, 8 */
	unsigned char	timing;					/* timing specification used */
	unsigned char	signal_voltage;			/* Signal voltage value (1.8V or 3.3V) */
	unsigned char	drv_type;				/* Driving malignant type (A, B, C, D) */
	bool enhanced_strobe;					/* hs400es selection */
}

mmc_dirver

struct mmc_driver {
	struct device_driver drv;
	int (*probe)(struct mmc_card *card);
	void (*remove)(struct mmc_card *card);
	void (*shutdown)(struct mmc_card *card);
};

mmc_bus_ops

struct mmc_bus_ops {
	void (*remove)(struct mmc_host *);
	void (*detect)(struct mmc_host *);
	int (*pre_suspend)(struct mmc_host *);
	int (*suspend)(struct mmc_host *);
	int (*resume)(struct mmc_host *);
	int (*runtime_suspend)(struct mmc_host *);
	int (*runtime_resume)(struct mmc_host *);
	int (*power_save)(struct mmc_host *);
	int (*power_restore)(struct mmc_host *);
	int (*alive)(struct mmc_host *);
	int (*shutdown)(struct mmc_host *);
	int (*reset)(struct mmc_host *);
};

mmc_host_ops

struct mmc_host_ops {
    void    (*post_req)(struct mmc_host *, struct mmc_request *, int err);
    void    (*pre_req)(struct mmc_host *, struct mmc_request *, bool is_first_req);
    void    (*request)(struct mmc_host *host, struct mmc_request *req);
    void    (*set_ios)(struct mmc_host *, struct mmc_ios *);
    int     (*get_ro)(struct mmc_host *);
    int     (*get_cd)(struct mmc_host *);
    void    (*enable_sdio_irq)(struct mmc_host *, int enable);
    void    (*init_card)(struct mmc_host *, struct mmc_card *card);
    int     (*start_signal_voltage_switch)(struct mmc_host *, struct mmc_ios *);
    int     (*card_busy)(struct mmc_host *);
    int     (*execute_tuning)(struct mmc_host *, u32 opcode);
    int     (*prepare_hs400_tuning)(struct mmc_host *host, struct mmc_ios *ios);
    void    (*hs400_enhanced_strobe)(struct mmc_host *, struct mmc_ios *);
    int     (*select_drive_strength)(struct mmc_card *card,
                  unsigned int max_dtr, int host_drv, int card_drv, int *drv_type);
    void    (*hw_reset)(struct mmc_host *);
    void    (*card_event)(struct mmc_host *);
    int     (*multi_io_quirk)(struct mmc_card *, unsigned int direction, int blk_size);
};

mmc_command

struct mmc_command {
	u32			opcode;						/* command Operation code */
	u32			arg;						/* command Parameters carried */
	u32			resp[4];					/* command After sending, if you need to answer, the result will be saved in the resp array. You can save up to 128bits of answers */
	unsigned int	flags;					/* Expected response type */
	unsigned int	retries;				/* Maximum number of resends */
	int				error;					/* If it is still an error, the reason for the error is returned through this field */
	unsigned int	busy_timeout;			/* busy detect timeout in ms */
	bool			sanitize_busy;			/* Set this flag only for blocking sanitize request */
	struct mmc_data		*data;				/* data segment associated with cmd */
	struct mmc_request	*mrq;				/* associated request */
}

mmc_data

struct mmc_data {
	unsigned int		timeout_ns;			/* data timeout (in ns, max 80ms) */
	unsigned int		timeout_clks;		/* data timeout (in clocks) */
	unsigned int		blksz;				/* data block size */
	unsigned int		blocks;				/* number of blocks */
	unsigned int		blk_addr;			/* block address */
	int					error;				/* If there is a data error, the error value is saved in this field */
	unsigned int		flags;				/* To indicate the direction of data transmission, use the following macro definitions */

#define MMC_DATA_WRITE		BIT(8)
#define MMC_DATA_READ		BIT(9)
/* Extra flags used by CQE */
#define MMC_DATA_QBR		BIT(10)			/* CQE queue barrier*/
#define MMC_DATA_PRIO		BIT(11)			/* CQE high priority */
#define MMC_DATA_REL_WR		BIT(12)			/* Reliable write */
#define MMC_DATA_DAT_TAG	BIT(13)			/* Tag request */
#define MMC_DATA_FORCED_PRG	BIT(14)			/* Forced programming */

	unsigned int		bytes_xfered;

	struct mmc_command	*stop;				/* stop command */
	struct mmc_request	*mrq;				/* associated request */

	unsigned int		sg_len;				/* sg Length of array */
	int					sg_count;			/* sg Number of arrays */
	struct scatterlist	*sg;				/* Save the data array to be transferred */
	s32					host_cookie;		/* host private data */
}

mmc_request

struct mmc_request {
	struct mmc_command	*cmd;				/* start command,Must set */
	struct mmc_data		*data;				/* Data transmitted, not required */
	struct mmc_command	*stop;
 
	void *done_data;						/* completion data */
	void (*done)(struct mmc_request *);		/* Callback function at the completion of the transfer to notify the originator of the transfer request */
};

sdio_func

struct sdio_func {
	struct mmc_card		*card;		/* the card this device belongs to */
	struct device		dev;		/* the device */
	sdio_irq_handler_t	*irq_handler;	/* IRQ callback */
	unsigned int		num;		/* function number */
	unsigned char		class;		/* standard interface class */
	unsigned short		vendor;		/* vendor id */
	unsigned short		device;		/* device id */
	unsigned		max_blksize;	/* maximum block size */
	unsigned		cur_blksize;	/* current block size */
	unsigned		enable_timeout;	/* max enable timeout in msec */
	unsigned int		state;		/* function state */
#define SDIO_STATE_PRESENT	(1<<0)		/* present in sysfs */
	u8			*tmpbuf;	/* DMA:able scratch buffer */
	unsigned		num_info;	/* number of info strings */
	const char		**info;		/* info strings */
	struct sdio_func_tuple *tuples;
}
Published 9 original articles, won praise 0, visited 313
Private letter follow

Topics: iOS Linux Programming