mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:12:45 +00:00 
			
		
		
		
	 aee4786d8e
			
		
	
	
		aee4786d8e
		
	
	
	
	
		
			
			This singleton simplifies many aspects that we struggled with before: 1. There's no need to make derived classes of Device expose the constructor as public anymore. The singleton is a friend of them, so he can call the constructor. This solves the issue with try_create_device helper neatly, hopefully for good. 2. Getting a reference of the NullDevice is now being done from this singleton, which means that NullDevice no longer needs to use its own singleton, and we can apply the try_create_device helper on it too :) 3. We can now defer registration completely after the Device constructor which means the Device constructor is merely assigning the major and minor numbers of the Device, and the try_create_device helper ensures it calls the after_inserting method immediately after construction. This creates a great opportunity to make registration more OOM-safe.
		
			
				
	
	
		
			62 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| //
 | |
| // A Disk Device Connected to a PATA Channel
 | |
| //
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <Kernel/Interrupts/IRQHandler.h>
 | |
| #include <Kernel/Locking/Mutex.h>
 | |
| #include <Kernel/Storage/StorageDevice.h>
 | |
| 
 | |
| namespace Kernel {
 | |
| 
 | |
| class IDEController;
 | |
| class IDEChannel;
 | |
| class PATADiskDevice final : public StorageDevice {
 | |
|     friend class IDEController;
 | |
|     friend class DeviceManagement;
 | |
|     AK_MAKE_ETERNAL
 | |
| public:
 | |
|     // Type of drive this IDEDiskDevice is on the ATA channel.
 | |
|     //
 | |
|     // Each PATA channel can contain only two devices, which (I think) are
 | |
|     // jumper selectable on the drive itself by shorting two pins.
 | |
|     enum class DriveType : u8 {
 | |
|         Master,
 | |
|         Slave
 | |
|     };
 | |
| 
 | |
|     enum class InterfaceType : u8 {
 | |
|         ATA,
 | |
|         ATAPI,
 | |
|     };
 | |
| 
 | |
| public:
 | |
|     static NonnullRefPtr<PATADiskDevice> create(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u64);
 | |
|     virtual ~PATADiskDevice() override;
 | |
| 
 | |
|     // ^BlockDevice
 | |
|     virtual void start_request(AsyncBlockDeviceRequest&) override;
 | |
|     virtual String storage_name() const override;
 | |
| 
 | |
| private:
 | |
|     PATADiskDevice(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u64);
 | |
| 
 | |
|     // ^DiskDevice
 | |
|     virtual StringView class_name() const override;
 | |
| 
 | |
|     bool is_slave() const;
 | |
| 
 | |
|     u16 m_capabilities { 0 };
 | |
|     NonnullRefPtr<IDEChannel> m_channel;
 | |
|     DriveType m_drive_type { DriveType::Master };
 | |
|     InterfaceType m_interface_type { InterfaceType::ATA };
 | |
| };
 | |
| 
 | |
| }
 |