2000-03-08 20:41:49 +01:00
|
|
|
/**************************************************************************
|
2002-03-10 00:29:33 +01:00
|
|
|
* ASPI routines
|
|
|
|
* Copyright (C) 2000 David Elliott <dfe@infinite-internet.net>
|
2005-08-10 12:52:22 +02:00
|
|
|
* Copyright (C) 2005 Vitaliy Margolen
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
2000-03-08 20:41:49 +01:00
|
|
|
|
|
|
|
/* These routines are to be called from either WNASPI32 or WINASPI */
|
|
|
|
|
|
|
|
/* FIXME:
|
|
|
|
* - No way to override automatic /proc detection, maybe provide an
|
|
|
|
* HKEY_LOCAL_MACHINE\Software\Wine\Wine\Scsi regkey
|
|
|
|
* - Somewhat debating an #ifdef linux... technically all this code will
|
|
|
|
* run on another UNIX.. it will fail nicely.
|
|
|
|
* - Please add support for mapping multiple channels on host adapters to
|
|
|
|
* aspi controllers, e-mail me if you need help.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2003-08-22 07:05:56 +02:00
|
|
|
#include <stdarg.h>
|
2000-03-08 20:41:49 +01:00
|
|
|
#include <sys/types.h>
|
2001-01-22 03:17:29 +01:00
|
|
|
#include <string.h>
|
2021-11-24 17:23:14 +01:00
|
|
|
#include <stdlib.h>
|
2000-03-08 20:41:49 +01:00
|
|
|
|
2003-08-22 07:05:56 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2000-03-08 20:41:49 +01:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winescsi.h"
|
|
|
|
|
2003-08-22 07:05:56 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(aspi);
|
2000-03-08 20:41:49 +01:00
|
|
|
|
2005-08-10 12:52:22 +02:00
|
|
|
static const WCHAR wDevicemapScsi[] = {'H','A','R','D','W','A','R','E','\\','D','E','V','I','C','E','M','A','P','\\','S','c','s','i',0};
|
|
|
|
|
2000-03-08 20:41:49 +01:00
|
|
|
/* Exported functions */
|
2007-03-10 22:00:47 +01:00
|
|
|
int ASPI_GetNumControllers(void)
|
2000-03-08 20:41:49 +01:00
|
|
|
{
|
2005-08-10 12:52:22 +02:00
|
|
|
HKEY hkeyScsi, hkeyPort;
|
|
|
|
DWORD i = 0, numPorts, num_ha = 0;
|
2008-11-05 14:50:54 +01:00
|
|
|
WCHAR wPortName[15];
|
2000-03-08 20:41:49 +01:00
|
|
|
|
2005-08-10 12:52:22 +02:00
|
|
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, wDevicemapScsi, 0,
|
|
|
|
KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hkeyScsi) != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
ERR("Could not open HKLM\\%s\n", debugstr_w(wDevicemapScsi));
|
|
|
|
return 0;
|
|
|
|
}
|
2018-08-09 20:59:38 +02:00
|
|
|
while (RegEnumKeyW(hkeyScsi, i++, wPortName, ARRAY_SIZE(wPortName)) == ERROR_SUCCESS)
|
2005-08-10 12:52:22 +02:00
|
|
|
{
|
|
|
|
if (RegOpenKeyExW(hkeyScsi, wPortName, 0, KEY_QUERY_VALUE, &hkeyPort) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (RegQueryInfoKeyW(hkeyPort, NULL, NULL, NULL, &numPorts, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
num_ha += numPorts;
|
|
|
|
}
|
|
|
|
RegCloseKey(hkeyPort);
|
|
|
|
}
|
|
|
|
}
|
2000-03-08 20:41:49 +01:00
|
|
|
|
2005-08-10 12:52:22 +02:00
|
|
|
RegCloseKey(hkeyScsi);
|
2006-10-06 23:02:14 +02:00
|
|
|
TRACE("Returning %d host adapters\n", num_ha );
|
2005-08-10 12:52:22 +02:00
|
|
|
return num_ha;
|
2000-03-08 20:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SCSI_GetHCforController
|
|
|
|
* RETURNS
|
|
|
|
* HIWORD: Host Adapter
|
|
|
|
* LOWORD: Channel
|
|
|
|
*/
|
2005-08-10 12:52:22 +02:00
|
|
|
DWORD ASPI_GetHCforController( int controller )
|
2000-03-08 20:41:49 +01:00
|
|
|
{
|
2005-08-10 12:52:22 +02:00
|
|
|
HKEY hkeyScsi, hkeyPort;
|
|
|
|
DWORD i = 0, numPorts;
|
|
|
|
int num_ha = controller + 1;
|
2007-11-01 08:09:10 +01:00
|
|
|
WCHAR wPortName[15];
|
|
|
|
WCHAR wBusName[15];
|
2000-07-08 13:44:48 +02:00
|
|
|
|
2005-08-10 12:52:22 +02:00
|
|
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, wDevicemapScsi, 0,
|
|
|
|
KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hkeyScsi) != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
ERR("Could not open HKLM\\%s\n", debugstr_w(wDevicemapScsi));
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
}
|
2018-08-09 20:59:38 +02:00
|
|
|
while (RegEnumKeyW(hkeyScsi, i++, wPortName, ARRAY_SIZE(wPortName)) == ERROR_SUCCESS)
|
2005-08-10 12:52:22 +02:00
|
|
|
{
|
|
|
|
if (RegOpenKeyExW(hkeyScsi, wPortName, 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
|
|
|
|
&hkeyPort) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (RegQueryInfoKeyW(hkeyPort, NULL, NULL, NULL, &numPorts, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
num_ha -= numPorts;
|
|
|
|
if (num_ha <= 0) break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
RegCloseKey(hkeyPort);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(hkeyScsi);
|
|
|
|
|
|
|
|
if (num_ha > 0)
|
|
|
|
{
|
|
|
|
ERR("Invalid controller(%d)\n", controller);
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
2018-08-09 20:59:38 +02:00
|
|
|
if (RegEnumKeyW(hkeyPort, -num_ha, wBusName, ARRAY_SIZE(wBusName)) != ERROR_SUCCESS)
|
2005-08-10 12:52:22 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to enumerate keys\n");
|
|
|
|
RegCloseKey(hkeyPort);
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
RegCloseKey(hkeyPort);
|
2000-07-08 13:44:48 +02:00
|
|
|
|
2021-11-24 17:23:14 +01:00
|
|
|
return (wcstol(&wPortName[9], NULL, 10) << 16) + wcstol(&wBusName[9], NULL, 10);
|
2005-12-12 11:54:19 +01:00
|
|
|
}
|