Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
/*
|
2015-03-25 11:12:52 +01:00
|
|
|
* \brief AHCI-port driver for ATA devices
|
|
|
|
* \author Sebastian Sumpf
|
|
|
|
* \date 2015-04-29
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-01-16 15:33:56 +01:00
|
|
|
* Copyright (C) 2015-2017 Genode Labs GmbH
|
2015-03-25 11:12:52 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2015-03-25 11:12:52 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ATA_DRIVER_H_
|
|
|
|
#define _ATA_DRIVER_H_
|
|
|
|
|
2016-07-20 19:10:08 +02:00
|
|
|
#include <base/log.h>
|
2015-03-25 11:12:52 +01:00
|
|
|
#include "ahci.h"
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
2015-10-06 15:36:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return data of 'identify_device' ATA command
|
|
|
|
*/
|
|
|
|
struct Identity : Genode::Mmio
|
|
|
|
{
|
|
|
|
Identity(Genode::addr_t base) : Mmio(base) { }
|
|
|
|
|
2016-02-11 20:03:38 +01:00
|
|
|
struct Serial_number : Register_array<0x14, 8, 20, 8> { };
|
|
|
|
struct Model_number : Register_array<0x36, 8, 40, 8> { };
|
|
|
|
|
2015-10-06 15:36:34 +02:00
|
|
|
struct Queue_depth : Register<0x96, 16>
|
|
|
|
{
|
|
|
|
struct Max_depth : Bitfield<0, 5> { };
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Sata_caps : Register<0x98, 16>
|
|
|
|
{
|
|
|
|
struct Ncq_support : Bitfield<8, 1> { };
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Sector_count : Register<0xc8, 64> { };
|
|
|
|
|
|
|
|
struct Logical_block : Register<0xd4, 16>
|
|
|
|
{
|
|
|
|
struct Per_physical : Bitfield<0, 3> { }; /* 2^X logical per physical */
|
|
|
|
struct Longer_512 : Bitfield<12, 1> { };
|
|
|
|
struct Multiple : Bitfield<13, 1> { }; /* multiple logical blocks per physical */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Logical_words : Register<0xea, 32> { }; /* words (16 bit) per logical block */
|
|
|
|
|
|
|
|
struct Alignment : Register<0x1a2, 16>
|
|
|
|
{
|
|
|
|
struct Logical_offset : Bitfield<0, 14> { }; /* offset first logical block in physical */
|
|
|
|
};
|
|
|
|
|
|
|
|
void info()
|
|
|
|
{
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
using Genode::log;
|
|
|
|
|
|
|
|
log(" queue depth: ", read<Queue_depth::Max_depth>() + 1, " "
|
|
|
|
"ncq: ", read<Sata_caps::Ncq_support>());
|
|
|
|
log(" numer of sectors: ", read<Sector_count>());
|
|
|
|
log(" multiple logical blocks per physical: ",
|
|
|
|
read<Logical_block::Multiple>() ? "yes" : "no");
|
|
|
|
log(" logical blocks per physical: ",
|
|
|
|
1U << read<Logical_block::Per_physical>());
|
|
|
|
log(" logical block size is above 512 byte: ",
|
|
|
|
read<Logical_block::Longer_512>() ? "yes" : "no");
|
|
|
|
log(" words (16bit) per logical block: ",
|
|
|
|
read<Logical_words>());
|
|
|
|
log(" offset of first logical block within physical: ",
|
|
|
|
read<Alignment::Logical_offset>());
|
2015-10-06 15:36:34 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-11 20:03:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 16-bit word big endian device ASCII characters
|
|
|
|
*/
|
|
|
|
template <typename DEVICE_STRING>
|
|
|
|
struct String
|
|
|
|
{
|
|
|
|
char buf[DEVICE_STRING::ITEMS + 1];
|
|
|
|
|
|
|
|
String(Identity & info)
|
|
|
|
{
|
|
|
|
long j = 0;
|
|
|
|
for (unsigned long i = 0; i < DEVICE_STRING::ITEMS; i++) {
|
|
|
|
/* read and swap even and uneven characters */
|
|
|
|
char c = (char)info.read<DEVICE_STRING>(i ^ 1);
|
|
|
|
if (Genode::is_whitespace(c) && j == 0)
|
|
|
|
continue;
|
|
|
|
buf[j++] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[j] = 0;
|
|
|
|
|
|
|
|
/* remove trailing white spaces */
|
|
|
|
while ((j > 0) && (buf[--j] == ' '))
|
|
|
|
buf[j] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator == (char const *other) const
|
|
|
|
{
|
|
|
|
return strcmp(buf, other) == 0;
|
|
|
|
}
|
2016-07-20 19:10:08 +02:00
|
|
|
|
|
|
|
void print(Genode::Output &out) const { Genode::print(out, (char const *)buf); }
|
2017-05-14 17:02:59 +02:00
|
|
|
char const *cstring() { return buf; }
|
2016-02-11 20:03:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-10-06 15:36:34 +02:00
|
|
|
/**
|
|
|
|
* Commands to distinguish between ncq and non-ncq operation
|
|
|
|
*/
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
struct Io_command : Interface
|
2015-10-06 15:36:34 +02:00
|
|
|
{
|
|
|
|
virtual void command(Port &por,
|
|
|
|
Command_table &table,
|
|
|
|
bool read,
|
|
|
|
Block::sector_t block_number,
|
|
|
|
size_t count,
|
|
|
|
unsigned slot) = 0;
|
|
|
|
|
|
|
|
virtual void handle_irq(Port &port, Port::Is::access_t status) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Ncq_command : Io_command
|
|
|
|
{
|
|
|
|
void command(Port &port,
|
|
|
|
Command_table &table,
|
|
|
|
bool read,
|
|
|
|
Block::sector_t block_number,
|
|
|
|
size_t count,
|
|
|
|
unsigned slot) override
|
|
|
|
{
|
|
|
|
table.fis.fpdma(read, block_number, count, slot);
|
2019-11-24 04:06:31 +01:00
|
|
|
/* ensure that 'Cmd::St' is 1 before writing 'Sact' */
|
|
|
|
port.start();
|
2015-10-06 15:36:34 +02:00
|
|
|
/* set pending */
|
|
|
|
port.write<Port::Sact>(1U << slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_irq(Port &port, Port::Is::access_t status) override
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Check for completions of other requests immediately
|
|
|
|
*/
|
|
|
|
while (Port::Is::Sdbs::get(status = port.read<Port::Is>()))
|
|
|
|
port.ack_irq();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Dma_ext_command : Io_command
|
|
|
|
{
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
void command(Port &,
|
2015-10-06 15:36:34 +02:00
|
|
|
Command_table &table,
|
|
|
|
bool read,
|
|
|
|
Block::sector_t block_number,
|
|
|
|
size_t count,
|
|
|
|
unsigned /* slot */) override
|
|
|
|
{
|
|
|
|
table.fis.dma_ext(read, block_number, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_irq(Port &port, Port::Is::access_t status) override
|
|
|
|
{
|
|
|
|
if (Port::Is::Dma_ext_irq::get(status))
|
|
|
|
port.ack_irq();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drivers using ncq- and non-ncq commands
|
|
|
|
*/
|
2015-03-25 11:12:52 +01:00
|
|
|
struct Ata_driver : Port_driver
|
|
|
|
{
|
2016-05-29 09:50:14 +02:00
|
|
|
Genode::Allocator &alloc;
|
|
|
|
|
2016-02-11 20:03:38 +01:00
|
|
|
typedef ::String<Identity::Serial_number> Serial_string;
|
|
|
|
typedef ::String<Identity::Model_number> Model_string;
|
|
|
|
|
2019-04-03 16:05:10 +02:00
|
|
|
Genode::Constructible<Identity> identity { };
|
|
|
|
Genode::Constructible<Serial_string> serial { };
|
|
|
|
Genode::Constructible<Model_string> model { };
|
2016-02-11 20:03:38 +01:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
Io_command *io_cmd = nullptr;
|
|
|
|
Block::Packet_descriptor pending[32];
|
2015-03-25 11:12:52 +01:00
|
|
|
|
2017-05-14 17:02:59 +02:00
|
|
|
Signal_context_capability device_identified;
|
|
|
|
|
2019-01-21 10:48:39 +01:00
|
|
|
Ata_driver(Genode::Allocator &alloc,
|
|
|
|
Genode::Ram_allocator &ram,
|
|
|
|
Ahci_root &root,
|
|
|
|
unsigned &sem,
|
|
|
|
Genode::Region_map &rm,
|
|
|
|
Hba &hba,
|
|
|
|
Platform::Hba &platform_hba,
|
|
|
|
unsigned number,
|
2017-05-14 17:02:59 +02:00
|
|
|
Genode::Signal_context_capability device_identified)
|
2017-03-06 12:45:27 +01:00
|
|
|
: Port_driver(ram, root, sem, rm, hba, platform_hba, number),
|
2017-05-14 17:02:59 +02:00
|
|
|
alloc(alloc), device_identified(device_identified)
|
2015-03-25 11:12:52 +01:00
|
|
|
{
|
|
|
|
Port::init();
|
|
|
|
identify_device();
|
|
|
|
}
|
|
|
|
|
2015-10-06 15:36:34 +02:00
|
|
|
~Ata_driver()
|
|
|
|
{
|
|
|
|
if (io_cmd)
|
2016-05-29 09:50:14 +02:00
|
|
|
destroy(&alloc, io_cmd);
|
2015-10-06 15:36:34 +02:00
|
|
|
}
|
|
|
|
|
2015-03-25 11:12:52 +01:00
|
|
|
unsigned find_free_cmd_slot()
|
|
|
|
{
|
|
|
|
for (unsigned slot = 0; slot < cmd_slots; slot++)
|
2016-05-31 18:53:57 +02:00
|
|
|
if (!pending[slot].size())
|
2015-03-25 11:12:52 +01:00
|
|
|
return slot;
|
|
|
|
|
|
|
|
throw Block::Driver::Request_congestion();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ack_packets()
|
|
|
|
{
|
|
|
|
unsigned slots = Port::read<Ci>() | Port::read<Sact>();
|
|
|
|
|
|
|
|
for (unsigned slot = 0; slot < cmd_slots; slot++) {
|
2016-05-31 18:53:57 +02:00
|
|
|
if ((slots & (1U << slot)) || !pending[slot].size())
|
2015-03-25 11:12:52 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Block::Packet_descriptor p = pending[slot];
|
|
|
|
pending[slot] = Block::Packet_descriptor();
|
|
|
|
ack_packet(p, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void overlap_check(Block::sector_t block_number,
|
|
|
|
size_t count)
|
|
|
|
{
|
|
|
|
Block::sector_t end = block_number + count - 1;
|
|
|
|
|
|
|
|
for (unsigned slot = 0; slot < cmd_slots; slot++) {
|
2016-05-31 18:53:57 +02:00
|
|
|
if (!pending[slot].size())
|
2015-03-25 11:12:52 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Block::sector_t pending_start = pending[slot].block_number();
|
|
|
|
Block::sector_t pending_end = pending_start + pending[slot].block_count() - 1;
|
|
|
|
/* check if a pending packet overlaps */
|
|
|
|
if ((block_number >= pending_start && block_number <= pending_end) ||
|
|
|
|
(end >= pending_start && end <= pending_end) ||
|
|
|
|
(pending_start >= block_number && pending_start <= end) ||
|
|
|
|
(pending_end >= block_number && pending_end <= end)) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
|
|
|
|
Genode::warning("overlap: "
|
|
|
|
"pending ", pending[slot].block_number(),
|
|
|
|
" + ", pending[slot].block_count(), ", "
|
|
|
|
"request: ", block_number, " + ", count);
|
2015-03-25 11:12:52 +01:00
|
|
|
throw Block::Driver::Request_congestion();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void io(bool read,
|
|
|
|
Block::sector_t block_number,
|
|
|
|
size_t count,
|
|
|
|
addr_t phys,
|
|
|
|
Block::Packet_descriptor &packet)
|
|
|
|
{
|
|
|
|
sanity_check(block_number, count);
|
|
|
|
overlap_check(block_number, count);
|
|
|
|
|
|
|
|
unsigned slot = find_free_cmd_slot();
|
|
|
|
pending[slot] = packet;
|
|
|
|
|
|
|
|
/* setup fis */
|
|
|
|
Command_table table(command_table_addr(slot), phys, count * block_size());
|
2015-10-06 15:36:34 +02:00
|
|
|
|
|
|
|
/* set ATA command */
|
|
|
|
io_cmd->command(*this, table, read, block_number, count, slot);
|
2015-03-25 11:12:52 +01:00
|
|
|
|
|
|
|
/* set or clear write flag in command header */
|
|
|
|
Command_header header(command_header_addr(slot));
|
|
|
|
header.write<Command_header::Bits::W>(read ? 0 : 1);
|
|
|
|
header.clear_byte_count();
|
|
|
|
|
|
|
|
execute(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
** Port_driver **
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
void handle_irq() override
|
|
|
|
{
|
|
|
|
Is::access_t status = Port::read<Is>();
|
|
|
|
|
2015-10-06 15:36:34 +02:00
|
|
|
switch (state) {
|
2015-03-25 11:12:52 +01:00
|
|
|
|
2015-10-06 15:36:34 +02:00
|
|
|
case IDENTIFY:
|
2015-03-25 11:12:52 +01:00
|
|
|
|
2016-07-06 15:42:09 +02:00
|
|
|
if (Port::Is::Dss::get(status)
|
|
|
|
|| Port::Is::Pss::get(status)
|
|
|
|
|| Port::Is::Dhrs::get(status)) {
|
2019-04-03 16:05:10 +02:00
|
|
|
identity.construct(device_info);
|
|
|
|
serial.construct(*identity);
|
|
|
|
model.construct(*identity);
|
2016-02-11 20:03:38 +01:00
|
|
|
|
|
|
|
if (verbose) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
Genode::log(" model number: ", Genode::Cstring(model->buf));
|
|
|
|
Genode::log(" serial number: ", Genode::Cstring(serial->buf));
|
2019-04-03 16:05:10 +02:00
|
|
|
identity->info();
|
2016-02-11 20:03:38 +01:00
|
|
|
}
|
2015-10-06 15:36:34 +02:00
|
|
|
|
|
|
|
check_device();
|
|
|
|
if (ncq_support())
|
2016-05-29 09:50:14 +02:00
|
|
|
io_cmd = new (&alloc) Ncq_command();
|
2015-10-06 15:36:34 +02:00
|
|
|
else
|
2016-05-29 09:50:14 +02:00
|
|
|
io_cmd = new (&alloc) Dma_ext_command();
|
2015-10-06 15:36:34 +02:00
|
|
|
|
2016-01-05 15:32:15 +01:00
|
|
|
ack_irq();
|
2017-05-14 17:02:59 +02:00
|
|
|
|
|
|
|
Genode::Signal_transmitter(device_identified).submit();
|
2015-10-06 15:36:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case READY:
|
|
|
|
|
|
|
|
io_cmd->handle_irq(*this, status);
|
2015-03-25 11:12:52 +01:00
|
|
|
ack_packets();
|
2015-10-06 15:36:34 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-03-25 11:12:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2015-10-06 15:36:34 +02:00
|
|
|
bool ncq_support()
|
2015-03-25 11:12:52 +01:00
|
|
|
{
|
2019-04-03 16:05:10 +02:00
|
|
|
return identity->read<Identity::Sata_caps::Ncq_support>() && hba.ncq();
|
2015-10-06 15:36:34 +02:00
|
|
|
}
|
2015-03-25 11:12:52 +01:00
|
|
|
|
2015-10-06 15:36:34 +02:00
|
|
|
void check_device()
|
|
|
|
{
|
2015-03-25 11:12:52 +01:00
|
|
|
cmd_slots = min((int)cmd_slots,
|
2019-04-03 16:05:10 +02:00
|
|
|
identity->read<Identity::Queue_depth::Max_depth >() + 1);
|
2015-10-06 15:36:34 +02:00
|
|
|
|
|
|
|
/* no native command queueing */
|
|
|
|
if (!ncq_support())
|
|
|
|
cmd_slots = 1;
|
|
|
|
|
2015-03-25 11:12:52 +01:00
|
|
|
state = READY;
|
|
|
|
state_change();
|
|
|
|
}
|
|
|
|
|
|
|
|
void identify_device()
|
|
|
|
{
|
|
|
|
state = IDENTIFY;
|
|
|
|
addr_t phys = (addr_t)Dataspace_client(device_info_ds).phys_addr();
|
|
|
|
|
|
|
|
Command_table table(command_table_addr(0), phys, 0x1000);
|
|
|
|
table.fis.identify_device();
|
|
|
|
execute(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************
|
|
|
|
** Block::Driver interface **
|
|
|
|
*****************************/
|
|
|
|
|
2019-02-14 22:39:08 +01:00
|
|
|
bool dma_enabled() override { return true; };
|
2015-03-25 11:12:52 +01:00
|
|
|
|
2019-04-03 16:05:10 +02:00
|
|
|
Block::Session::Info info() const override
|
2015-03-25 11:12:52 +01:00
|
|
|
{
|
2019-04-03 16:05:10 +02:00
|
|
|
return { .block_size = block_size(),
|
|
|
|
.block_count = block_count(),
|
2019-04-04 18:25:54 +02:00
|
|
|
.align_log2 = log2(block_size()),
|
2019-04-03 16:05:10 +02:00
|
|
|
.writeable = true };
|
2015-03-25 11:12:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void read_dma(Block::sector_t block_number,
|
|
|
|
size_t block_count,
|
|
|
|
addr_t phys,
|
|
|
|
Block::Packet_descriptor &packet) override
|
|
|
|
{
|
|
|
|
io(true, block_number, block_count, phys, packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_dma(Block::sector_t block_number,
|
|
|
|
size_t block_count,
|
|
|
|
addr_t phys,
|
|
|
|
Block::Packet_descriptor &packet) override
|
|
|
|
{
|
|
|
|
io(false, block_number, block_count, phys, packet);
|
|
|
|
}
|
|
|
|
|
2019-04-03 16:05:10 +02:00
|
|
|
Genode::size_t block_size() const override
|
2015-03-25 11:12:52 +01:00
|
|
|
{
|
|
|
|
Genode::size_t size = 512;
|
|
|
|
|
2019-04-03 16:05:10 +02:00
|
|
|
if (identity->read<Identity::Logical_block::Longer_512>())
|
|
|
|
size = identity->read<Identity::Logical_words>() / 2;
|
2015-03-25 11:12:52 +01:00
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2019-04-03 16:05:10 +02:00
|
|
|
Block::sector_t block_count() const override
|
2015-03-25 11:12:52 +01:00
|
|
|
{
|
2019-04-03 16:05:10 +02:00
|
|
|
return identity->read<Identity::Sector_count>();
|
2015-03-25 11:12:52 +01:00
|
|
|
}
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Ata_driver(Ata_driver const &);
|
|
|
|
Ata_driver &operator = (Ata_driver const &);
|
2015-03-25 11:12:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _ATA_DRIVER_H_ */
|