| 1 | /*
|
|---|
| 2 | * Copyright (c) 2012 Petr Jerman
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - 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.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 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.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @file
|
|---|
| 30 | * Header for AHCI driver.
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | #ifndef __AHCI_H__
|
|---|
| 34 | #define __AHCI_H__
|
|---|
| 35 |
|
|---|
| 36 | #include <sys/types.h>
|
|---|
| 37 | #include <devman.h>
|
|---|
| 38 | #include <ddf/interrupt.h>
|
|---|
| 39 | #include <stdio.h>
|
|---|
| 40 | #include "ahci_hw.h"
|
|---|
| 41 |
|
|---|
| 42 | /** AHCI Device. */
|
|---|
| 43 | typedef struct {
|
|---|
| 44 | /** Pointer to ddf device. */
|
|---|
| 45 | ddf_dev_t *dev;
|
|---|
| 46 |
|
|---|
| 47 | /** Pointer to AHCI memory registers. */
|
|---|
| 48 | volatile ahci_memregs_t *memregs;
|
|---|
| 49 |
|
|---|
| 50 | /** Pointers to sata devices. */
|
|---|
| 51 | void *sata_devs[AHCI_MAX_PORTS];
|
|---|
| 52 | } ahci_dev_t;
|
|---|
| 53 |
|
|---|
| 54 | /** SATA Device. */
|
|---|
| 55 | typedef struct {
|
|---|
| 56 | /** Pointer to AHCI device. */
|
|---|
| 57 | ahci_dev_t *ahci;
|
|---|
| 58 |
|
|---|
| 59 | /** SATA port number (0-31). */
|
|---|
| 60 | uint8_t port_num;
|
|---|
| 61 |
|
|---|
| 62 | /** Device in invalid state (disconnected and so on). */
|
|---|
| 63 | bool is_invalid_device;
|
|---|
| 64 |
|
|---|
| 65 | /** Pointer to SATA port. */
|
|---|
| 66 | volatile ahci_port_t *port;
|
|---|
| 67 |
|
|---|
| 68 | /** Pointer to command header. */
|
|---|
| 69 | volatile ahci_cmdhdr_t *cmd_header;
|
|---|
| 70 |
|
|---|
| 71 | /** Pointer to command table. */
|
|---|
| 72 | volatile uint32_t *cmd_table;
|
|---|
| 73 |
|
|---|
| 74 | /** Mutex for single operation on device. */
|
|---|
| 75 | fibril_mutex_t lock;
|
|---|
| 76 |
|
|---|
| 77 | /** Mutex for event signaling condition variable. */
|
|---|
| 78 | fibril_mutex_t event_lock;
|
|---|
| 79 |
|
|---|
| 80 | /** Event signaling condition variable. */
|
|---|
| 81 | fibril_condvar_t event_condvar;
|
|---|
| 82 |
|
|---|
| 83 | /** Event interrupt state. */
|
|---|
| 84 | ahci_port_is_t event_pxis;
|
|---|
| 85 |
|
|---|
| 86 | /** Block device service id. */
|
|---|
| 87 | service_id_t service_id;
|
|---|
| 88 |
|
|---|
| 89 | /** Number of device data blocks. */
|
|---|
| 90 | uint64_t blocks;
|
|---|
| 91 |
|
|---|
| 92 | /** Size of device data blocks. */
|
|---|
| 93 | size_t block_size;
|
|---|
| 94 |
|
|---|
| 95 | /** Name of SATA device. */
|
|---|
| 96 | char model[STR_BOUNDS(40) + 1];
|
|---|
| 97 |
|
|---|
| 98 | /** Device in invalid state (disconnected and so on). */
|
|---|
| 99 | bool is_packet_device;
|
|---|
| 100 |
|
|---|
| 101 | /** Highest UDMA mode supported. */
|
|---|
| 102 | uint8_t highest_udma_mode;
|
|---|
| 103 | } sata_dev_t;
|
|---|
| 104 |
|
|---|
| 105 | #endif
|
|---|