singrdk/base/Drivers/Disk/DiskDriver.sg

132 lines
4.3 KiB
Plaintext
Raw Permalink Normal View History

2008-03-05 09:52:00 -05:00
////////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: IdeController.cs
//
// Base Classes and Interfaces for interacting with ATA
//
// References used:
// "AT Attachment Interface with Extension (ATA-2)", Revision 4c, DRAFT
// 09/03/97, ISO Working Group T13, http://www.t13.org/
//
// "AT Attachment 8 - ATA/ATAPI Command Set (ATA8-ACS)", Revision 0, DRAFT
// 08/17/04, ISO Working Group T13, http://www.t13.org/
//
using System;
using System.Collections;
using System.Text;
using System.Threading;
using Microsoft.SingSharp;
2008-11-17 18:29:00 -05:00
using Microsoft.SingSharp.Reflection;
2008-03-05 09:52:00 -05:00
using Microsoft.Singularity;
using Microsoft.Singularity.Io;
using Microsoft.Singularity.Configuration;
using Microsoft.Singularity.Channels;
using Microsoft.Singularity.Drivers.IDE;
using Microsoft.Singularity.V1.Services;
using Microsoft.Singularity.Extending;
using Microsoft.Singularity.Directory;
2008-11-17 18:29:00 -05:00
using Microsoft.Singularity.Drivers;
[assembly: Transform(typeof(DriverResourceTransform))]
2008-03-05 09:52:00 -05:00
namespace Microsoft.Singularity.Drivers.IDE
{
2008-11-17 18:29:00 -05:00
// create the resource object for CTR to fill in
2008-03-05 09:52:00 -05:00
[DriverCategory]
[Signature("/ata/controller")]
[EnumeratesDevice("/ata/disk")]
[EnumeratesDevice("/ata/atapi/...")]
2008-11-17 18:29:00 -05:00
internal class DiskResources : DriverCategoryDeclaration
2008-03-05 09:52:00 -05:00
{
[IoIrqRange(0, Default = 0x0e, Shared = true)]
2008-11-17 18:29:00 -05:00
internal readonly IoIrqRange irq;
2008-03-05 09:52:00 -05:00
// [TODO] do all of these need to be shared?
[IoPortRange(1, Default = 0x01f0, Length = 0x08, Shared = true)]
2008-11-17 18:29:00 -05:00
internal readonly IoPortRange command;
2008-03-05 09:52:00 -05:00
[IoPortRange(2, Default = 0x03f4, Length = 0x04, Shared = true)]
2008-11-17 18:29:00 -05:00
internal readonly IoPortRange control;
2008-03-05 09:52:00 -05:00
[IoPortRange(3, Default = 0xffa0, Length = 0x08, Shared = true)]
2008-11-17 18:29:00 -05:00
internal readonly IoPortRange dma;
2008-03-05 09:52:00 -05:00
[ExtensionEndpoint]
2008-11-17 18:29:00 -05:00
internal TRef<ExtensionContract.Exp:Start> extension;
2008-03-05 09:52:00 -05:00
[ServiceEndpoint(typeof(DiskDeviceContract))]
2008-11-17 18:29:00 -05:00
internal TRef<ServiceProviderContract.Exp:Start> service;
2008-03-05 09:52:00 -05:00
[Endpoint]
2008-11-17 18:29:00 -05:00
internal TRef<VolumeManagerContract.Imp:Start> volman;
2008-03-05 09:52:00 -05:00
2008-11-17 18:29:00 -05:00
internal int DriverMain(string instance) {
return DiskDriverControl.DriverMain(instance, this);
2008-03-05 09:52:00 -05:00
}
}
public class DiskDriverControl
{
private static IoConfig config;
private static IdeController controller;
private static IdeDisk disk;
private static IdeDiskConfig diskConfig;
private static IdeDiskConfig slaveDiskConfig;
public static void SetMasterDiskConfig(IdeDiskConfig config)
{
diskConfig = config;
}
public static void SetSlaveDiskConfig(IdeDiskConfig config)
{
slaveDiskConfig = config;
}
2008-11-17 18:29:00 -05:00
internal static int DriverMain(string instance, DiskResources! resources)
2008-03-05 09:52:00 -05:00
{
2008-11-17 18:29:00 -05:00
DebugStub.Print("Disk: {0}: Irq={1}\n",
__arglist(instance, resources.irq.ToString()));
2008-03-05 09:52:00 -05:00
// Create the Controller
2008-11-17 18:29:00 -05:00
controller = IdeController.Create(resources, (!)instance);
2008-03-05 09:52:00 -05:00
controller.Initialize();
2008-11-17 18:29:00 -05:00
ExtensionContract.Exp! extension = resources.extension.Acquire();
ServiceProviderContract.Exp! service = resources.service.Acquire();
VolumeManagerContract.Imp! volman = resources.volman.Acquire();
2008-03-05 09:52:00 -05:00
//Create the disk
if (diskConfig == null) {
if (slaveDiskConfig != null) {
diskConfig = slaveDiskConfig;
2008-11-17 18:29:00 -05:00
DebugStub.WriteLine("Using slave disk configuration.");
2008-03-05 09:52:00 -05:00
}
}
if (diskConfig == null) {
2008-11-17 18:29:00 -05:00
DebugStub.WriteLine("Master disk configuration not found.");
2008-03-05 09:52:00 -05:00
delete service;
delete extension;
delete volman;
}
else {
disk = new IdeDisk(diskConfig, instance);
disk.Run(extension, service, volman);
}
if (disk != null) {
disk.Finalize();
}
controller.Finalize();
return 0;
}
}
}